def test_add_dist_device(self): with sqla_session() as session: #TODO: get params from testdata.yml new_device = Device() new_device.ztp_mac = '08002708a8be' new_device.hostname = 'eosdist' new_device.platform = 'eos' new_device.management_ip = IPv4Address('10.0.1.22') new_device.state = DeviceState.MANAGED new_device.device_type = DeviceType.DIST result = session.add(new_device) pprint.pprint(result)
except Exception as e: print(str(e)) sys.exit(2) with sqla_session() as session: db_entry: Device = session.query(Device).filter( Device.ztp_mac == ztp_mac).first() if db_entry: if db_entry.state == DeviceState.DHCP_BOOT: db_entry.state = DeviceState.DISCOVERED db_entry.dhcp_ip = dhcp_ip logger.info( "New device booted via DHCP to state DISCOVERED: {}". format(ztp_mac)) else: logger.error( "New device booted via DHCP in unhandled state {}: {}". format(db_entry.state, ztp_mac)) else: # TODO: look for entries with same dhcp_ip in DB and set them to null (they are stale) new_device = Device() new_device.ztp_mac = ztp_mac new_device.dhcp_ip = dhcp_ip new_device.hostname = f'mac-{ztp_mac}' new_device.platform = platform new_device.state = DeviceState.DHCP_BOOT new_device.device_type = DeviceType.UNKNOWN session.add(new_device) logger.info( "New device booted via DHCP to state DHCP_BOOT: {}".format( ztp_mac))