def GET(self, id): try: dev_cfg = data.device_config(id) web.header('Content-Type', 'application/json; charset=utf-8') return dev_cfg['boot_config'] except KeyError: raise web.notfound()
def GET(self, id): try: dev_cfg = data.device_config(id) web.header('Content-Type', 'application/json; charset=utf-8') return dev_cfg['boot_config'] except KeyError: raise web.notfound()
def setup_pxe(self): # set the pxe config based on what's in the DB cfg = data.device_config(self.machine.device_name) try: pxe_config = data.get_pxe_config_for_device(self.machine.device_name) except data.NotFound: self.logger.warning('no appropriate PXE config found') self.machine.goto_state(failed_pxe_booting) return bmm_api.set_pxe(self.machine.device_name, pxe_config, cfg['boot_config'])
def contact_lifeguard(self, request_config): # If the requested image is reusable and we got a device with that # image and the requested bootconfig, just power cycle it. # Otherwise, image it. Note that there will be a failure if the # image is not installed and the device is not imageable. event = '' device_request_data = {} assigned_device_name = request_config['assigned_device'] if data.image_is_reusable(request_config['image']): device_config = data.device_config(request_config['assigned_device']) if (device_config['image'] == request_config['image'] and data.from_json(device_config['boot_config']) == data.from_json(request_config['boot_config'])): event = 'please_power_cycle' if not event: # Use the device's hardware type and requested image to find the # pxe config, if any. event = 'please_image' device_request_data['boot_config'] = request_config['boot_config'] device_request_data['image'] = request_config['image'] device_url = 'http://%s/api/device/%s/event/%s/' % ( data.get_server_for_device(assigned_device_name), assigned_device_name, event) # FIXME: make this asynchronous so slow/missing servers don't halt # the state machine. try: urllib.urlopen(device_url, json.dumps(device_request_data)) except IOError: self.logger.warn('Could not contact lifeguard server at %s' % device_url) return False return True
def testDeviceConfigPxe(self): add_pxe_config('img1', contents='IMG1 ip=%IPADDRESS%', id=23) add_device("withpxe", config='', server="server1", last_pxe_config_id=23) self.assertEqual(data.device_config('withpxe'), {'boot_config': '', 'pxe_config': 'img1'})
def testDeviceConfigNoPxe(self): add_device("withconfig", server="server1", config='abcd') self.assertEqual(data.device_config('withconfig'), {'boot_config': 'abcd', 'pxe_config': None})
def testDeviceConfigEmpty(self): self.assertEqual(data.device_config('foo'), {})
def setup_pxe(self): # set the pxe config based on what's in the DB cfg = data.device_config(self.machine.device_name) bmm_api.set_pxe(self.machine.device_name, cfg['pxe_config'], cfg['boot_config'])
def testDeviceConfigImage(self): add_image('img1', id=23) add_device("withimg", config='', server="server1", last_image_id=23) self.assertEqual(data.device_config('withimg'), {'boot_config': '', 'image': 'img1'})
def setup_pxe(self): # set the pxe config based on what's in the DB cfg = data.device_config(self.machine.device_name) bmm_api.set_pxe(self.machine.device_name, cfg['pxe_config'], cfg['boot_config'])