Fix bugs in softlayer dynamic inventory (#28178)

* --host hostname did not work due to calling wrong function

* softlayer api returns a bunch of extra stuff in the tagReference dict that
  makes --list output crazy long, like over a terminal buffer for just one server
  this culls out the extranneous information and only inserts the actual user
  provided tags to each server.
This commit is contained in:
Paul Czarkowski 2018-09-19 17:10:15 -05:00 committed by ansibot
parent 02bfb9047c
commit caf658b420

View file

@ -49,7 +49,7 @@ class SoftLayerInventory(object):
'primaryBackendIpAddress',
'primaryIpAddress',
'datacenter',
'tagReferences.tag.name',
'tagReferences',
'userData.value',
]
@ -82,7 +82,7 @@ class SoftLayerInventory(object):
self.get_all_servers()
print(self.json_format_dict(self.inventory, True))
elif self.args.host:
self.get_virtual_servers()
self.get_all_servers()
print(self.json_format_dict(self.inventory["_meta"]["hostvars"][self.args.host], True))
def to_safe(self, word):
@ -139,6 +139,12 @@ class SoftLayerInventory(object):
dest = instance['primaryIpAddress']
instance['tags'] = list()
for tag in instance['tagReferences']:
instance['tags'].append(tag['tag']['name'])
del instance['tagReferences']
self.inventory["_meta"]["hostvars"][dest] = instance
# Inventory: group by memory
@ -168,9 +174,8 @@ class SoftLayerInventory(object):
# Inventory: group by type (hardware/virtual)
self.push(self.inventory, instance_type, dest)
# Inventory: group by tag
for tag in instance['tagReferences']:
self.push(self.inventory, tag['tag']['name'], dest)
for tag in instance['tags']:
self.push(self.inventory, tag, dest)
def get_virtual_servers(self):
'''Get all the CCI instances'''