def addHost(host, env): '''Imports the host and environment ''' try: h = Host.objects.get(fqdn=host) if h.pk: msg("Host " + host + " already exists") return h except: pass msg("importing new host " + host) # Hardware Model try: tenv, tmodel = puppetProbe(host) try: hwm = HardwareModel.objects.get(name=tmodel) except: hwm = HardwareModel(name=tmodel, power_usage=300, size=1) hwm.save() except: hwm = unknown # Machine itself t = classifier.guess(host) try: print "AI says " + t[0][0] dc = DataCenter.objects.get(name=t[0][0]) except: try: dc = DataCenter(name=t[0][0]) dc.save() except: print "AI Error" hw = Hardware(name="FIXME " + host, hardware_model=hwm) hw.save() h = Host(fqdn=host, environment=Environment.objects.get(name=env.name), owner=amo, hardware=hw) h.save() return h
def addHost(host, env): '''Imports the host and environment ''' try: h = Host.objects.get(fqdn = host) if h.pk: msg("Host " + host+ " already exists") return h except: pass msg("importing new host " + host) # Hardware Model try: tenv, tmodel = puppetProbe(host) try: hwm = HardwareModel.objects.get(name = tmodel) except: hwm = HardwareModel(name = tmodel, power_usage=300, size=1) hwm.save() except: hwm = unknown # Machine itself t = classifier.guess(host) try: print "AI says " + t[0][0] dc = DataCenter.objects.get(name = t[0][0]) except: try: dc = DataCenter(name=t[0][0]) dc.save() except: print "AI Error" hw = Hardware(name = "FIXME " + host, hardware_model = hwm) hw.save() h = Host(fqdn=host, environment=Environment.objects.get(name=env.name), owner=amo, hardware=hw ) h.save() return h
msg("Starting Import") for line in reader: msg(" importing " + line[0]) name = line[0] location = line[1] fqdn = line[2] rack = line[3] ilo = line[4] model = line[5] serial = line[6] # Test / Create Hardware Object try: hw = HardwareModel.objects.get(name = model) except: hw = HardwareModel(name = model, power_usage="300", size="1") hw.save() # Test / Create Datacenter Object try: dc = DataCenter.objects.get(name = location) except: dc = DataCenter(name=location) dc.save() # Test / Create Rack Object try: rack = Rack.objects.get(name = rack) except: rack = Rack(name = rack, datacenter = dc, size=42) rack.save()
# URL xmlurl = 'http://someurl/foo.xml' # Test if essential link models exist try: dc = DataCenter.objects.get(name = 'JFA') amo = Owner.objects.get(name = 'AMO Infrastructure') except: print("init failed, check DC 'JFA' and owner 'AMO Infrastructure' exists!") sys.exit(1) # Test / Create a unknown hardware type model which is used for unidentified equipment try: unknown = HardwareModel.objects.get(name = 'Unknown') except: unknown = HardwareModel(name = "Unknown", power_usage="300", size="1") unknown.save() # this is the important function for converting XML to list python object def xml2obj(src): """ A simple function to converts XML data into native Python object. """ non_id_char = re.compile('[^_0-9a-zA-Z]') def _name_mangle(name): return non_id_char.sub('_', name) class DataNode(object): def __init__(self): self._attrs = {} # XML attributes and child elements self.data = None # child text data
msg("Starting Import") for line in reader: msg(" importing " + line[0]) name = line[0] location = line[1] fqdn = line[2] rack = line[3] ilo = line[4] model = line[5] serial = line[6] # Test / Create Hardware Object try: hw = HardwareModel.objects.get(name=model) except: hw = HardwareModel(name=model, power_usage="300", size="1") hw.save() # Test / Create Datacenter Object try: dc = DataCenter.objects.get(name=location) except: dc = DataCenter(name=location) dc.save() # Test / Create Rack Object try: rack = Rack.objects.get(name=rack) except: rack = Rack(name=rack, datacenter=dc, size=42) rack.save()
# URL xmlurl = 'http://someurl/foo.xml' # Test if essential link models exist try: dc = DataCenter.objects.get(name='JFA') amo = Owner.objects.get(name='AMO Infrastructure') except: print("init failed, check DC 'JFA' and owner 'AMO Infrastructure' exists!") sys.exit(1) # Test / Create a unknown hardware type model which is used for unidentified equipment try: unknown = HardwareModel.objects.get(name='Unknown') except: unknown = HardwareModel(name="Unknown", power_usage="300", size="1") unknown.save() # this is the important function for converting XML to list python object def xml2obj(src): """ A simple function to converts XML data into native Python object. """ non_id_char = re.compile('[^_0-9a-zA-Z]') def _name_mangle(name): return non_id_char.sub('_', name) class DataNode(object): def __init__(self):