mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
softlayer inventory include group by tags
This commit is contained in:
parent
6c2af29659
commit
44fb104da3
1 changed files with 36 additions and 2 deletions
|
@ -35,12 +35,40 @@ via the command `sl config setup`.
|
||||||
import SoftLayer
|
import SoftLayer
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
|
import itertools
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
except:
|
except:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
class SoftLayerInventory(object):
|
class SoftLayerInventory(object):
|
||||||
|
common_items = [
|
||||||
|
'id',
|
||||||
|
'globalIdentifier',
|
||||||
|
'hostname',
|
||||||
|
'domain',
|
||||||
|
'fullyQualifiedDomainName',
|
||||||
|
'primaryBackendIpAddress',
|
||||||
|
'primaryIpAddress',
|
||||||
|
'datacenter',
|
||||||
|
'tagReferences.tag.name',
|
||||||
|
]
|
||||||
|
|
||||||
|
vs_items = [
|
||||||
|
'lastKnownPowerState.name',
|
||||||
|
'powerState',
|
||||||
|
'maxCpu',
|
||||||
|
'maxMemory',
|
||||||
|
'activeTransaction.transactionStatus[friendlyName,name]',
|
||||||
|
'status',
|
||||||
|
]
|
||||||
|
|
||||||
|
hw_items = [
|
||||||
|
'hardwareStatusId',
|
||||||
|
'processorPhysicalCoreAmount',
|
||||||
|
'memoryCapacity',
|
||||||
|
]
|
||||||
|
|
||||||
def _empty_inventory(self):
|
def _empty_inventory(self):
|
||||||
return {"_meta" : {"hostvars" : {}}}
|
return {"_meta" : {"hostvars" : {}}}
|
||||||
|
|
||||||
|
@ -139,10 +167,15 @@ class SoftLayerInventory(object):
|
||||||
# Inventory: group by type (hardware/virtual)
|
# Inventory: group by type (hardware/virtual)
|
||||||
self.push(self.inventory, instance_type, dest)
|
self.push(self.inventory, instance_type, dest)
|
||||||
|
|
||||||
|
# Inventory: group by tag
|
||||||
|
for tag in instance['tagReferences']:
|
||||||
|
self.push(self.inventory, tag['tag']['name'], dest)
|
||||||
|
|
||||||
def get_virtual_servers(self):
|
def get_virtual_servers(self):
|
||||||
'''Get all the CCI instances'''
|
'''Get all the CCI instances'''
|
||||||
vs = SoftLayer.VSManager(self.client)
|
vs = SoftLayer.VSManager(self.client)
|
||||||
instances = vs.list_instances()
|
mask = "mask[%s]" % ','.join(itertools.chain(self.common_items,self.vs_items))
|
||||||
|
instances = vs.list_instances(mask=mask)
|
||||||
|
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
self.process_instance(instance)
|
self.process_instance(instance)
|
||||||
|
@ -150,7 +183,8 @@ class SoftLayerInventory(object):
|
||||||
def get_physical_servers(self):
|
def get_physical_servers(self):
|
||||||
'''Get all the hardware instances'''
|
'''Get all the hardware instances'''
|
||||||
hw = SoftLayer.HardwareManager(self.client)
|
hw = SoftLayer.HardwareManager(self.client)
|
||||||
instances = hw.list_hardware()
|
mask = "mask[%s]" % ','.join(itertools.chain(self.common_items,self.hw_items))
|
||||||
|
instances = hw.list_hardware(mask=mask)
|
||||||
|
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
self.process_instance(instance, 'hardware')
|
self.process_instance(instance, 'hardware')
|
||||||
|
|
Loading…
Reference in a new issue