Merge pull request #826 from DazWorrall/feature/cs_instance_iptonetwork

Add iptonetwork parameter to cs_instance
reviewable/pr18780/r1
Brian Coca 9 years ago
commit c310d3a8cd

@ -97,6 +97,13 @@ options:
- IPv6 address for default instance's network.
required: false
default: null
ip_to_networks:
description:
- List of mappings in the form {'network': NetworkName, 'ip': 1.2.3.4}
- Mutually exclusive with C(networks) option.
required: false
default: null
aliases: [ 'ip_to_network' ]
disk_offering:
description:
- Name of the disk offering to be used.
@ -214,6 +221,16 @@ EXAMPLES = '''
- { key: admin, value: john }
- { key: foo, value: bar }
# Create an instance with multiple interfaces specifying the IP addresses
- local_action:
module: cs_instance
name: web-vm-1
template: Linux Debian 7 64-bit
service_offering: Tiny
ip_to_networks:
- {'network': NetworkA, 'ip': '10.1.1.1'}
- {'network': NetworkB, 'ip': '192.168.1.1'}
# Ensure a instance has stopped
- local_action: cs_instance name=web-vm-1 state=stopped
@ -453,9 +470,25 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
break
return self.instance
def get_iptonetwork_mappings(self):
network_mappings = self.module.params.get('ip_to_networks')
if network_mappings is None:
return
if network_mappings and self.module.params.get('networks'):
self.module.fail_json(msg="networks and ip_to_networks are mutually exclusive.")
network_names = [n['network'] for n in network_mappings]
ids = self.get_network_ids(network_names)
res = []
for i, data in enumerate(network_mappings):
res.append({'networkid': ids[i], 'ip': data['ip']})
return res
def get_network_ids(self, network_names=None):
if network_names is None:
network_names = self.module.params.get('networks')
def get_network_ids(self):
network_names = self.module.params.get('networks')
if not network_names:
return None
@ -481,7 +514,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
if len(network_ids) != len(network_names):
self.module.fail_json(msg="Could not find all networks, networks list found: %s" % network_displaytexts)
return ','.join(network_ids)
return network_ids
def present_instance(self):
@ -507,6 +540,9 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
def deploy_instance(self):
self.result['changed'] = True
networkids = self.get_network_ids()
if networkids is not None:
networkids = ','.join(networkids)
args = {}
args['templateid'] = self.get_template_or_iso(key='id')
@ -516,7 +552,8 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
args['domainid'] = self.get_domain(key='id')
args['projectid'] = self.get_project(key='id')
args['diskofferingid'] = self.get_disk_offering_id()
args['networkids'] = self.get_network_ids()
args['networkids'] = networkids
args['iptonetworklist'] = self.get_iptonetwork_mappings()
args['userdata'] = self.get_user_data()
args['keyboard'] = self.module.params.get('keyboard')
args['ipaddress'] = self.module.params.get('ip_address')
@ -791,6 +828,7 @@ def main():
template = dict(default=None),
iso = dict(default=None),
networks = dict(type='list', aliases=[ 'network' ], default=None),
ip_to_networks = dict(type='list', aliases=['ip_to_network'], default=None),
ip_address = dict(defaul=None),
ip6_address = dict(defaul=None),
disk_offering = dict(default=None),

Loading…
Cancel
Save