def _add_node(self, data): LOG.info('Adding device {0} to DB'.format(data['name'])) device = Device() device.name = data['name'] device.publicIpAddr = data['addr'] # TODO: kill this field, make things use publicIpAddr instead device.floatingIpAddr = data['addr'] device.az = data['az'] device.type = data['type'] device.pingCount = 0 device.status = 'OFFLINE' device.created = None with db_session() as session: session.add(device) session.commit()
def _add_bad_node(self, data): LOG.info( 'Adding bad device {0} to DB to be deleted'.format(data['name']) ) device = Device() device.name = data['name'] device.publicIpAddr = data['addr'] # TODO: kill this field, make things use publicIpAddr instead device.floatingIpAddr = data['addr'] device.az = data['az'] device.type = data['type'] device.pingCount = 0 device.status = 'DELETED' device.created = None with db_session() as session: session.add(device) counter = session.query(Counters).\ filter(Counters.name == 'devices_bad_built').first() counter.value += 1 session.commit()
def post(self, body=None): """ Creates a new device entry in devices table. :param None Url: POST /devices JSON Request Body { "name":"device name", "publicIpAddr":"15.x.x.x", "floatingIpAddr":"15.x.x.x", "az":2, "type":"type descr" } Returns: dict { "status": "OFFLINE", "updated": "2013-06-06T10:17:19", "name": "device name", "created": "2013-06-06T10:17:19", "loadBalancers": [], "floatingIpAddr": "192.1678.98.99", "publicIpAddr": "192.1678.98.99", "az": 2, "type": "type descr", "id": 67 } """ # Get a new device object device = Device() device.name = body.name device.publicIpAddr = body.publicIpAddr device.floatingIpAddr = body.floatingIpAddr device.az = body.az device.type = body.type device.pingCount = 0 device.status = 'OFFLINE' device.created = None with db_session() as session: # write to database session.add(device) session.flush() #refresh the device record so we get the id back session.refresh(device) try: return_data = DeviceResp() return_data.id = device.id return_data.name = device.name return_data.floatingIpAddr = device.floatingIpAddr return_data.publicIpAddr = device.publicIpAddr return_data.az = device.az return_data.type = device.type return_data.created = device.created return_data.updated = device.updated return_data.status = device.status return_data.loadBalancers = [] session.commit() return return_data except: LOG.exception('Error communicating with load balancer pool') errstr = 'Error communicating with load balancer pool' session.rollback() raise ClientSideError(errstr)