Skip to content

Commit

Permalink
softlayer inventory include group by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Craft authored and mattclay committed Jan 3, 2017
1 parent 6c2af29 commit 44fb104
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions contrib/inventory/softlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,40 @@
import SoftLayer
import re
import argparse
import itertools
try:
import json
except:
import simplejson as json

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):
return {"_meta" : {"hostvars" : {}}}

Expand Down Expand Up @@ -139,18 +167,24 @@ def process_instance(self, instance, instance_type="virtual"):
# 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)

def get_virtual_servers(self):
'''Get all the CCI instances'''
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:
self.process_instance(instance)

def get_physical_servers(self):
'''Get all the hardware instances'''
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:
self.process_instance(instance, 'hardware')
Expand Down

0 comments on commit 44fb104

Please sign in to comment.