diff --git a/ironicclient/osc/v1/baremetal_node.py b/ironicclient/osc/v1/baremetal_node.py index a57ed40d9..e4fd32ef9 100644 --- a/ironicclient/osc/v1/baremetal_node.py +++ b/ironicclient/osc/v1/baremetal_node.py @@ -110,6 +110,73 @@ class CleanBaremetalNode(ProvisionStateBaremetalNode): cleansteps=clean_steps) +class ConsoleDisableBaremetalNode(command.Command): + """Disable console access for a node""" + + log = logging.getLogger(__name__ + ".ConsoleDisableBaremetalNode") + + def get_parser(self, prog_name): + parser = super(ConsoleDisableBaremetalNode, self).get_parser(prog_name) + + parser.add_argument( + 'node', + metavar='', + help="Name or UUID of the node" + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + + baremetal_client = self.app.client_manager.baremetal + baremetal_client.node.set_console_mode(parsed_args.node, False) + + +class ConsoleEnableBaremetalNode(command.Command): + """Enable console access for a node""" + + log = logging.getLogger(__name__ + ".ConsoleEnableBaremetalNode") + + def get_parser(self, prog_name): + parser = super(ConsoleEnableBaremetalNode, self).get_parser(prog_name) + + parser.add_argument( + 'node', + metavar='', + help="Name or UUID of the node" + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + + baremetal_client = self.app.client_manager.baremetal + baremetal_client.node.set_console_mode(parsed_args.node, True) + + +class ConsoleShowBaremetalNode(command.ShowOne): + """Show console information for a node""" + + log = logging.getLogger(__name__ + ".ConsoleShowBaremetalNode") + + def get_parser(self, prog_name): + parser = super(ConsoleShowBaremetalNode, self).get_parser(prog_name) + + parser.add_argument( + 'node', + metavar='', + help="Name or UUID of the node" + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + + baremetal_client = self.app.client_manager.baremetal + info = baremetal_client.node.get_console(parsed_args.node) + return zip(*sorted(info.items())) + + class CreateBaremetalNode(command.ShowOne): """Register a new node with the baremetal service""" diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py index d9032ea2d..b25ff9310 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py @@ -56,6 +56,66 @@ class TestAdopt(TestBaremetal): 'node_uuid', 'adopt') +class TestConsoleDisable(TestBaremetal): + def setUp(self): + super(TestConsoleDisable, self).setUp() + + # Get the command object to test + self.cmd = baremetal_node.ConsoleDisableBaremetalNode(self.app, None) + + def test_console_disable(self): + arglist = ['node_uuid'] + verifylist = [('node', 'node_uuid')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_console_mode.assert_called_once_with( + 'node_uuid', False) + + +class TestConsoleEnable(TestBaremetal): + def setUp(self): + super(TestConsoleEnable, self).setUp() + + # Get the command object to test + self.cmd = baremetal_node.ConsoleEnableBaremetalNode(self.app, None) + + def test_console_enable(self): + arglist = ['node_uuid'] + verifylist = [('node', 'node_uuid')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_console_mode.assert_called_once_with( + 'node_uuid', True) + + +class TestConsoleShow(TestBaremetal): + def setUp(self): + super(TestConsoleShow, self).setUp() + + # Get the command object to test + self.cmd = baremetal_node.ConsoleShowBaremetalNode(self.app, None) + + self.baremetal_mock.node.get_console.return_value = { + "console_enabled": False, "console_info": None} + + def test_console_show(self): + arglist = ['node_uuid'] + verifylist = [('node', 'node_uuid')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.get_console.assert_called_once_with( + 'node_uuid') + + class TestBaremetalCreate(TestBaremetal): def setUp(self): super(TestBaremetalCreate, self).setUp() diff --git a/releasenotes/notes/osc-plugin-node-console-610bce4e0418a3cc.yaml b/releasenotes/notes/osc-plugin-node-console-610bce4e0418a3cc.yaml new file mode 100644 index 000000000..b47a3d694 --- /dev/null +++ b/releasenotes/notes/osc-plugin-node-console-610bce4e0418a3cc.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + Extends the OpenStackClient plug-in with new commands: + + * openstack baremetal node console disable + * openstack baremetal node console enable + * openstack baremetal node console show diff --git a/setup.cfg b/setup.cfg index be3acce09..54e91f72d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,9 @@ openstack.baremetal.v1 = baremetal_node_abort = ironicclient.osc.v1.baremetal_node:AbortBaremetalNode baremetal_node_adopt = ironicclient.osc.v1.baremetal_node:AdoptBaremetalNode baremetal_node_clean = ironicclient.osc.v1.baremetal_node:CleanBaremetalNode + baremetal_node_console_disable = ironicclient.osc.v1.baremetal_node:ConsoleDisableBaremetalNode + baremetal_node_console_enable = ironicclient.osc.v1.baremetal_node:ConsoleEnableBaremetalNode + baremetal_node_console_show = ironicclient.osc.v1.baremetal_node:ConsoleShowBaremetalNode baremetal_node_create = ironicclient.osc.v1.baremetal_node:CreateBaremetalNode baremetal_node_delete = ironicclient.osc.v1.baremetal_node:DeleteBaremetalNode baremetal_node_deploy = ironicclient.osc.v1.baremetal_node:DeployBaremetalNode