def do_node_set_provision_state(cc, args): """Initiate a provisioning state change for a node.""" if args.config_drive and args.provision_state != 'active': raise exceptions.CommandError(_('--config-drive is only valid when ' 'setting provision state to "active"')) elif args.clean_steps and args.provision_state != 'clean': raise exceptions.CommandError(_('--clean-steps is only valid when ' 'setting provision state to "clean"')) elif args.provision_state == 'clean' and not args.clean_steps: raise exceptions.CommandError(_('--clean-steps must be specified when ' 'setting provision state to "clean"')) if args.wait_timeout is not None: wait_args = v1_utils.PROVISION_ACTIONS.get(args.provision_state) if wait_args is None: raise exceptions.CommandError( _("--wait is not supported for provision state '%s'") % args.provision_state) clean_steps = args.clean_steps if args.clean_steps == '-': clean_steps = utils.get_from_stdin('clean steps') if clean_steps: clean_steps = utils.handle_json_or_file_arg(clean_steps) cc.node.set_provision_state(args.node, args.provision_state, configdrive=args.config_drive, cleansteps=clean_steps) if args.wait_timeout is not None: print(_('Waiting for provision state %(state)s on node %(node)s') % {'state': wait_args['expected_state'], 'node': args.node}) cc.node.wait_for_provision_state(args.node, timeout=args.wait_timeout, **wait_args)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal # NOTE(rloo): Do this before updating the rest. Otherwise, it won't # work if parsed_args.node is the name and the name is # also being modified. if parsed_args.target_raid_config: raid_config = parsed_args.target_raid_config if raid_config == '-': raid_config = utils.get_from_stdin('target_raid_config') raid_config = utils.handle_json_or_file_arg(raid_config) baremetal_client.node.set_target_raid_config( parsed_args.node, raid_config) properties = [] if parsed_args.instance_uuid: instance_uuid = ["instance_uuid=%s" % parsed_args.instance_uuid] properties.extend(utils.args_array_to_patch('add', instance_uuid)) if parsed_args.name: name = ["name=%s" % parsed_args.name] properties.extend(utils.args_array_to_patch('add', name)) if parsed_args.chassis_uuid: chassis_uuid = ["chassis_uuid=%s" % parsed_args.chassis_uuid] properties.extend(utils.args_array_to_patch('add', chassis_uuid)) if parsed_args.driver: driver = ["driver=%s" % parsed_args.driver] properties.extend(utils.args_array_to_patch('add', driver)) if parsed_args.network_interface: network_interface = [ "network_interface=%s" % parsed_args.network_interface ] properties.extend( utils.args_array_to_patch('add', network_interface)) if parsed_args.resource_class: resource_class = ["resource_class=%s" % parsed_args.resource_class] properties.extend(utils.args_array_to_patch('add', resource_class)) if parsed_args.property: properties.extend( utils.args_array_to_patch( 'add', ['properties/' + x for x in parsed_args.property])) if parsed_args.extra: properties.extend( utils.args_array_to_patch( 'add', ['extra/' + x for x in parsed_args.extra])) if parsed_args.driver_info: properties.extend( utils.args_array_to_patch( 'add', ['driver_info/' + x for x in parsed_args.driver_info])) if parsed_args.instance_info: properties.extend( utils.args_array_to_patch( 'add', ['instance_info/' + x for x in parsed_args.instance_info])) if properties: baremetal_client.node.update(parsed_args.node, properties) else: self.log.warning(_LW("Please specify what to set."))
def do_node_set_provision_state(cc, args): """Initiate a provisioning state change for a node.""" if args.config_drive and args.provision_state != 'active': raise exceptions.CommandError(_('--config-drive is only valid when ' 'setting provision state to "active"')) elif args.clean_steps and args.provision_state != 'clean': raise exceptions.CommandError(_('--clean-steps is only valid when ' 'setting provision state to "clean"')) elif args.provision_state == 'clean' and not args.clean_steps: raise exceptions.CommandError(_('--clean-steps must be specified when ' 'setting provision state to "clean"')) if args.wait_timeout is not None: wait_args = v1_utils.PROVISION_ACTIONS.get(args.provision_state) if wait_args is None: raise exceptions.CommandError( _("--wait is not supported for provision state '%s'") % args.provision_state) clean_steps = args.clean_steps if args.clean_steps == '-': clean_steps = utils.get_from_stdin('clean steps') if clean_steps: clean_steps = utils.handle_json_or_file_arg(clean_steps) cc.node.set_provision_state(args.node, args.provision_state, configdrive=args.config_drive, cleansteps=clean_steps) if args.wait_timeout is not None: print(_('Waiting for provision state %(state)s on node %(node)s') % {'state': wait_args['expected_state'], 'node': args.node}) cc.node.wait_for_provision_state(args.node, timeout=args.wait_timeout, **wait_args)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal # NOTE(rloo): Do this before updating the rest. Otherwise, it won't # work if parsed_args.node is the name and the name is # also being modified. if parsed_args.target_raid_config: raid_config = parsed_args.target_raid_config if raid_config == '-': raid_config = utils.get_from_stdin('target_raid_config') raid_config = utils.handle_json_or_file_arg(raid_config) baremetal_client.node.set_target_raid_config(parsed_args.node, raid_config) properties = [] if parsed_args.instance_uuid: instance_uuid = ["instance_uuid=%s" % parsed_args.instance_uuid] properties.extend(utils.args_array_to_patch( 'add', instance_uuid)) if parsed_args.name: name = ["name=%s" % parsed_args.name] properties.extend(utils.args_array_to_patch( 'add', name)) if parsed_args.chassis_uuid: chassis_uuid = ["chassis_uuid=%s" % parsed_args.chassis_uuid] properties.extend(utils.args_array_to_patch( 'add', chassis_uuid)) if parsed_args.driver: driver = ["driver=%s" % parsed_args.driver] properties.extend(utils.args_array_to_patch( 'add', driver)) if parsed_args.network_interface: network_interface = [ "network_interface=%s" % parsed_args.network_interface] properties.extend(utils.args_array_to_patch( 'add', network_interface)) if parsed_args.resource_class: resource_class = [ "resource_class=%s" % parsed_args.resource_class] properties.extend(utils.args_array_to_patch( 'add', resource_class)) if parsed_args.property: properties.extend(utils.args_array_to_patch( 'add', ['properties/' + x for x in parsed_args.property])) if parsed_args.extra: properties.extend(utils.args_array_to_patch( 'add', ['extra/' + x for x in parsed_args.extra])) if parsed_args.driver_info: properties.extend(utils.args_array_to_patch( 'add', ['driver_info/' + x for x in parsed_args.driver_info])) if parsed_args.instance_info: properties.extend(utils.args_array_to_patch( 'add', ['instance_info/' + x for x in parsed_args.instance_info])) if properties: baremetal_client.node.update(parsed_args.node, properties) else: self.log.warning(_LW("Please specify what to set."))
def test_handle_json_or_file_arg_file(self): contents = '[{"step": "upgrade", "interface": "deploy"}]' with tempfile.NamedTemporaryFile(mode='w') as f: f.write(contents) f.flush() steps = utils.handle_json_or_file_arg(f.name) self.assertEqual(json.loads(contents), steps)
def test_handle_json_or_file_arg_file(self): contents = '[{"step": "upgrade", "interface": "deploy"}]' with tempfile.NamedTemporaryFile(mode='w') as f: f.write(contents) f.flush() steps = utils.handle_json_or_file_arg(f.name) self.assertEqual(json.loads(contents), steps)
def do_node_set_target_raid_config(cc, args): """Set target RAID config on a node.""" target_raid_config = args.target_raid_config if not target_raid_config: raise exc.InvalidAttribute(_("target RAID configuration not provided")) if target_raid_config == '-': target_raid_config = utils.get_from_stdin('target_raid_config') target_raid_config = utils.handle_json_or_file_arg(target_raid_config) cc.node.set_target_raid_config(args.node, target_raid_config)
def do_node_set_target_raid_config(cc, args): """Set target RAID config on a node.""" target_raid_config = args.target_raid_config if not target_raid_config: raise exc.InvalidAttribute( _("target RAID configuration not provided")) if target_raid_config == '-': target_raid_config = utils.get_from_stdin('target_raid_config') target_raid_config = utils.handle_json_or_file_arg(target_raid_config) cc.node.set_target_raid_config(args.node, target_raid_config)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal clean_steps = parsed_args.clean_steps if parsed_args.clean_steps == '-': clean_steps = utils.get_from_stdin('clean steps') if clean_steps: clean_steps = utils.handle_json_or_file_arg(clean_steps) baremetal_client.node.set_provision_state(parsed_args.node, parsed_args.provision_state, cleansteps=clean_steps)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) baremetal_client = self.app.client_manager.baremetal clean_steps = parsed_args.clean_steps if parsed_args.clean_steps == '-': clean_steps = utils.get_from_stdin('clean steps') if clean_steps: clean_steps = utils.handle_json_or_file_arg(clean_steps) baremetal_client.node.set_provision_state( parsed_args.node, parsed_args.provision_state, cleansteps=clean_steps)
def do_node_set_provision_state(cc, args): """Initiate a provisioning state change for a node.""" if args.config_drive and args.provision_state != 'active': raise exceptions.CommandError(_('--config-drive is only valid when ' 'setting provision state to "active"')) elif args.clean_steps and args.provision_state != 'clean': raise exceptions.CommandError(_('--clean-steps is only valid when ' 'setting provision state to "clean"')) elif args.provision_state == 'clean' and not args.clean_steps: raise exceptions.CommandError(_('--clean-steps must be specified when ' 'setting provision state to "clean"')) clean_steps = args.clean_steps if args.clean_steps == '-': clean_steps = utils.get_from_stdin('clean steps') if clean_steps: clean_steps = utils.handle_json_or_file_arg(clean_steps) cc.node.set_provision_state(args.node, args.provision_state, configdrive=args.config_drive, cleansteps=clean_steps)
def test_handle_json_or_file_arg(self): cleansteps = '[{"step": "upgrade", "interface": "deploy"}]' steps = utils.handle_json_or_file_arg(cleansteps) self.assertEqual(json.loads(cleansteps), steps)
def test_handle_json_or_file_arg(self): cleansteps = '[{"step": "upgrade", "interface": "deploy"}]' steps = utils.handle_json_or_file_arg(cleansteps) self.assertEqual(json.loads(cleansteps), steps)