def _add_dev_blade(ip, pairs, parent, raw, counts, dev_id): if '[' in dev_id: pos = int(dev_id[dev_id.find('[') + 1:dev_id.find(']')]) else: pos = None dev = _dev(DeviceType.blade_server, pairs, parent, raw) dev.chassis_position = pos if pos: dev.position = '%02d' % pos else: dev.position = '' counts.blade += 1 dev.save(update_last_seen=True, priority=SAVE_PRIORITY) for i in range(1, 9): name = 'MAC Address %d' % i mac = pairs.get(name) if mac == 'Not Available' or mac is None: continue eth, created = Ethernet.concurrent_get_or_create( mac=MACAddressField.normalize(mac), defaults=dict(device=dev), ) eth.label = name eth.save(priority=SAVE_PRIORITY) return dev
def _add_dev_switch(ip, pairs, parent, raw, counts, dev_id): dev_type = DeviceType.switch if pairs["Mach type/model"].startswith("Fibre Channel SM"): dev_type = DeviceType.fibre_channel_switch dev = _dev(dev_type, pairs, parent, raw) mac = pairs.get("MAC Address") if mac: eth, created = Ethernet.concurrent_get_or_create(mac=MACAddressField.normalize(mac), defaults=dict(device=dev)) eth.label = "Ethernet" eth.save(priority=SAVE_PRIORITY) return dev
def run_ssh_asa(ip): ssh = _connect_ssh(ip) try: lines = ssh.asa_command( "show version | grep (^Hardware|Boot microcode|^Serial|address is)" ) raw_inventory = '\n'.join(ssh.asa_command("show inventory")) finally: ssh.close() pairs = parse.pairs(lines=[line.strip() for line in lines]) sn = pairs.get('Serial Number', None) model, ram, cpu = pairs['Hardware'].split(',') boot_firmware = pairs['Boot microcode'] ethernets = [] for i in xrange(99): try: junk, label, mac = pairs['%d' % i].split(':') except KeyError: break mac = mac.split(',', 1)[0] mac = mac.replace('address is', '') mac = mac.replace('.', '').upper().strip() label = label.strip() ethernets.append(Eth(label, mac, speed=None)) dev = Device.create(ethernets=ethernets, sn=sn, model_name=model, model_type=DeviceType.firewall, boot_firmware=boot_firmware) dev.save(update_last_seen=True) inventory = list(cisco_inventory(raw_inventory)) for inv in inventory: cisco_component(dev, inv) ipaddr, created = IPAddress.concurrent_get_or_create(address=ip) ipaddr.device = dev ipaddr.is_management = True ipaddr.save() for label, mac, speed in ethernets: eth, created = Ethernet.concurrent_get_or_create( mac=mac, defaults={'device': dev}, ) eth.label = label eth.device = dev eth.save() return model
def _add_dev_switch(pairs, parent, raw, counts, dev_id): dev_type = DeviceType.switch if pairs['Mach type/model'].startswith('Fibre Channel SM'): dev_type = DeviceType.fibre_channel_switch dev = _dev(dev_type, pairs, parent, raw) mac = pairs.get('MAC Address') if mac: eth, created = Ethernet.concurrent_get_or_create(device=dev, mac=MACAddressField.normalize(mac)) eth.label = 'Ethernet' eth.save(priority=SAVE_PRIORITY) return dev
def _add_dev_switch(pairs, parent, raw, counts, dev_id): dev_type = DeviceType.switch if pairs['Mach type/model'].startswith('Fibre Channel SM'): dev_type = DeviceType.fibre_channel_switch dev = _dev(dev_type, pairs, parent, raw) mac = pairs.get('MAC Address') if mac: eth, created = Ethernet.concurrent_get_or_create( device=dev, mac=MACAddressField.normalize(mac)) eth.label = 'Ethernet' eth.save(priority=SAVE_PRIORITY) return dev
def _add_dev_blade(pairs, parent, raw, counts, dev_id): if "[" in dev_id: pos = int(dev_id[dev_id.find("[") + 1 : dev_id.find("]")]) else: pos = None dev = _dev(DeviceType.blade_server, pairs, parent, raw) dev.chassis_position = pos dev.position = "%02d" % pos counts.blade += 1 dev.save(update_last_seen=True, priority=SAVE_PRIORITY) for i in range(1, 9): name = "MAC Address %d" % i mac = pairs.get(name) if mac == "Not Available" or mac is None: continue eth, created = Ethernet.concurrent_get_or_create(device=dev, mac=MACAddressField.normalize(mac)) eth.label = name eth.save(priority=SAVE_PRIORITY) return dev
def _add_ipmi_lan(device, mac): eth, created = Ethernet.concurrent_get_or_create(device=device, mac=MACAddressField.normalize(mac)) eth.label = 'IPMI MC' eth.save(priority=SAVE_PRIORITY)
def test_mac_addresses(self): for i in xrange(5): mac = 'deadbeefcaf%d' % i Ethernet(mac=mac, device=self.device).save()
def _add_ipmi_lan(device, mac): eth, created = Ethernet.concurrent_get_or_create( device=device, mac=MACAddressField.normalize(mac)) eth.label = 'IPMI MC' eth.save(priority=SAVE_PRIORITY)