os_server: Adding support to accept 'n' nic args as a string containing list

pull/18777/head
Abitha Palaniappan 9 years ago committed by Matt Clay
parent dd76088019
commit 5047561036

@ -84,7 +84,10 @@ options:
nics: nics:
description: description:
- A list of networks to which the instance's interface should - A list of networks to which the instance's interface should
be attached. Networks may be referenced by net-id or net-name. be attached. Networks may be referenced by net-id/net-name/port-id
or port-name.
Also this accepts a string containing a list of net-id/port-id.
Eg: nics: "net-id=uuid-1,net-id=uuid-2"
required: false required: false
default: None default: None
public_ip: public_ip:
@ -241,6 +244,25 @@ EXAMPLES = '''
image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM) image: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
flavor_ram: 4096 flavor_ram: 4096
flavor_include: Performance flavor_include: Performance
# Creates a new instance and attaches to multiple network
- name: launch a compute instance
hosts: localhost
tasks:
- name: launch an instance with a string
os_server:
name: vm1
auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
username: admin
password: admin
project_name: admin
name: vm1
image: 4f905f38-e52a-43d2-b6ec-754a13ffb529
key_name: ansible_key
timeout: 200
flavor: 4
nics: "net-id=4cb08b20-62fe-11e5-9d70-feff819cdc9f,net-id=542f0430-62fe-11e5-9d70-feff819cdc9f..."
''' '''
@ -252,25 +274,33 @@ def _exit_hostvars(module, cloud, server, changed=True):
def _network_args(module, cloud): def _network_args(module, cloud):
args = [] args = []
for net in module.params['nics']: nics = module.params['nics']
if net.get('net-id'): if type(nics) == str :
args.append(net) for kv_str in nics.split(","):
elif net.get('net-name'): nic = {}
by_name = cloud.get_network(net['net-name']) k, v = kv_str.split("=")
if not by_name: nic[k] = v
module.fail_json( args.append(nic)
msg='Could not find network by net-name: %s' % else:
net['net-name']) for net in module.params['nics']:
args.append({'net-id': by_name['id']}) if net.get('net-id'):
elif net.get('port-id'): args.append(net)
args.append(net) elif net.get('net-name'):
elif net.get('port-name'): by_name = cloud.get_network(net['net-name'])
by_name = cloud.get_port(net['port-name']) if not by_name:
if not by_name: module.fail_json(
module.fail_json( msg='Could not find network by net-name: %s' %
msg='Could not find port by port-name: %s' % net['net-name'])
net['port-name']) args.append({'net-id': by_name['id']})
args.append({'port-id': by_name['id']}) elif net.get('port-id'):
args.append(net)
elif net.get('port-name'):
by_name = cloud.get_port(net['port-name'])
if not by_name:
module.fail_json(
msg='Could not find port by port-name: %s' %
net['port-name'])
args.append({'port-id': by_name['id']})
return args return args

Loading…
Cancel
Save