adds missing serialize_instance function

This commit is contained in:
Peter Sprygada 2015-09-08 10:50:13 -04:00 committed by Matt Clay
parent bb9109ebca
commit 9a8be8ae06

View file

@ -61,7 +61,7 @@ options:
- The type of service we are authenticating against - The type of service we are authenticating against
required: false required: false
default: vca default: vca
choices: [ "vca", "vchs", "vcd" ] choices: [ "vca", "vchs", "vcd" ]
state: state:
description: description:
- if the object should be added or removed - if the object should be added or removed
@ -108,7 +108,7 @@ EXAMPLES = '''
instance_id: 'b15ff1e5-1024-4f55-889f-ea0209726282' instance_id: 'b15ff1e5-1024-4f55-889f-ea0209726282'
vdc_name: 'benz_ansible' vdc_name: 'benz_ansible'
state: 'present' state: 'present'
nat_rules: nat_rules:
- rule_type: SNAT - rule_type: SNAT
original_ip: 192.168.2.10 original_ip: 192.168.2.10
translated_ip: 107.189.95.208 translated_ip: 107.189.95.208
@ -121,7 +121,7 @@ EXAMPLES = '''
instance_id: 'b15ff1e5-1024-4f55-889f-ea0209726282' instance_id: 'b15ff1e5-1024-4f55-889f-ea0209726282'
vdc_name: 'benz_ansible' vdc_name: 'benz_ansible'
state: 'present' state: 'present'
nat_rules: nat_rules:
- rule_type: DNAT - rule_type: DNAT
original_ip: 107.189.95.208 original_ip: 107.189.95.208
original_port: 22 original_port: 22
@ -145,6 +145,12 @@ LOGIN_HOST['vca'] = 'vca.vmware.com'
LOGIN_HOST['vchs'] = 'vchs.vmware.com' LOGIN_HOST['vchs'] = 'vchs.vmware.com'
VALID_RULE_KEYS = ['rule_type', 'original_ip', 'original_port', 'translated_ip', 'translated_port', 'protocol'] VALID_RULE_KEYS = ['rule_type', 'original_ip', 'original_port', 'translated_ip', 'translated_port', 'protocol']
def serialize_instances(instance_list):
instances = []
for i in instance_list:
instances.append(dict(apiUrl=i['apiUrl'], instance_id=i['id']))
return instances
def vca_login(module=None): def vca_login(module=None):
service_type = module.params.get('service_type') service_type = module.params.get('service_type')
username = module.params.get('username') username = module.params.get('username')
@ -216,7 +222,7 @@ def vca_login(module=None):
if not vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url): if not vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url):
module.fail_json(msg = "Failed to login to org", error=vca.response.content) module.fail_json(msg = "Failed to login to org", error=vca.response.content)
return vca return vca
def validate_nat_rules(module=None, nat_rules=None): def validate_nat_rules(module=None, nat_rules=None):
for rule in nat_rules: for rule in nat_rules:
if not isinstance(rule, dict): if not isinstance(rule, dict):
@ -301,7 +307,7 @@ def main():
if service_type == 'vcd': if service_type == 'vcd':
if not host: if not host:
module.fail_json(msg="When service type is vcd host parameter is mandatory") module.fail_json(msg="When service type is vcd host parameter is mandatory")
vca = vca_login(module) vca = vca_login(module)
vdc = vca.get_vdc(vdc_name) vdc = vca.get_vdc(vdc_name)
if not vdc: if not vdc:
@ -368,7 +374,7 @@ def main():
module.exit_json(changed=True, rules_added=mod_rules) module.exit_json(changed=True, rules_added=mod_rules)
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':