summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@spootnik.org>2018-12-01 02:00:41 +0100
committerRené Moser <mail@renemoser.net>2018-12-01 02:00:41 +0100
commitbd1050dfc7ce378a43a6f283f83d2deeb3451581 (patch)
tree98c523f6a225ab3f485a400b48460d75ad9bbe6b /contrib
parent238786c0d397edc8a7cafd8e332a720cb765a245 (diff)
downloadansible-bd1050dfc7ce378a43a6f283f83d2deeb3451581.tar.gz
cloudstack: inventory: consider more keys optional (#49364)
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/cloudstack.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/contrib/inventory/cloudstack.py b/contrib/inventory/cloudstack.py
index 36ad84c520..bbebcacd92 100755
--- a/contrib/inventory/cloudstack.py
+++ b/contrib/inventory/cloudstack.py
@@ -157,24 +157,35 @@ class CloudStackInventory(object):
data['affinity_group'] = host['affinitygroup']
data['security_group'] = host['securitygroup']
data['cpu_number'] = host['cpunumber']
- data['cpu_speed'] = host['cpuspeed']
+ if 'cpu_speed' in host:
+ data['cpu_speed'] = host['cpuspeed']
if 'cpuused' in host:
data['cpu_used'] = host['cpuused']
data['memory'] = host['memory']
data['tags'] = host['tags']
- data['hypervisor'] = host['hypervisor']
+ if 'hypervisor' in host:
+ data['hypervisor'] = host['hypervisor']
data['created'] = host['created']
data['nic'] = []
for nic in host['nic']:
- data['nic'].append({
+ nicdata = {
'ip': nic['ipaddress'],
'mac': nic['macaddress'],
'netmask': nic['netmask'],
'gateway': nic['gateway'],
'type': nic['type'],
- })
+ }
+ if 'ip6address' in nic:
+ nicdata['ip6'] = nic['ip6address']
+ if 'gateway' in nic:
+ nicdata['gateway'] = nic['gateway']
+ if 'netmask' in nic:
+ nicdata['netmask'] = nic['netmask']
+ data['nic'].append(nicdata)
if nic['isdefault']:
data['default_ip'] = nic['ipaddress']
+ if 'ip6address' in nic:
+ data['default_ip6'] = nic['ip6address']
break
return data
@@ -221,25 +232,36 @@ class CloudStackInventory(object):
data['_meta']['hostvars'][host_name]['affinity_group'] = host['affinitygroup']
data['_meta']['hostvars'][host_name]['security_group'] = host['securitygroup']
data['_meta']['hostvars'][host_name]['cpu_number'] = host['cpunumber']
- data['_meta']['hostvars'][host_name]['cpu_speed'] = host['cpuspeed']
+ if 'cpuspeed' in host:
+ data['_meta']['hostvars'][host_name]['cpu_speed'] = host['cpuspeed']
if 'cpuused' in host:
data['_meta']['hostvars'][host_name]['cpu_used'] = host['cpuused']
data['_meta']['hostvars'][host_name]['created'] = host['created']
data['_meta']['hostvars'][host_name]['memory'] = host['memory']
data['_meta']['hostvars'][host_name]['tags'] = host['tags']
- data['_meta']['hostvars'][host_name]['hypervisor'] = host['hypervisor']
+ if 'hypervisor' in host:
+ data['_meta']['hostvars'][host_name]['hypervisor'] = host['hypervisor']
data['_meta']['hostvars'][host_name]['created'] = host['created']
data['_meta']['hostvars'][host_name]['nic'] = []
for nic in host['nic']:
- data['_meta']['hostvars'][host_name]['nic'].append({
+ nicdata = {
'ip': nic['ipaddress'],
'mac': nic['macaddress'],
'netmask': nic['netmask'],
'gateway': nic['gateway'],
'type': nic['type'],
- })
+ }
+ if 'ip6address' in nic:
+ nicdata['ip6'] = nic['ip6address']
+ if 'gateway' in nic:
+ nicdata['gateway'] = nic['gateway']
+ if 'netmask' in nic:
+ nicdata['netmask'] = nic['netmask']
+ data['_meta']['hostvars'][host_name]['nic'].append(nicdata)
if nic['isdefault']:
data['_meta']['hostvars'][host_name]['default_ip'] = nic['ipaddress']
+ if 'ip6address' in nic:
+ data['_meta']['hostvars'][host_name]['default_ip6'] = nic['ip6address']
group_name = ''
if 'group' in host: