diff options
| author | Hongbin Lu <hongbin.lu@huawei.com> | 2017-10-03 15:35:56 +0000 |
|---|---|---|
| committer | Hongbin Lu <hongbin034@gmail.com> | 2017-10-26 15:34:04 +0000 |
| commit | e3ad82164dc5c51b5f3cb75b826bc15a6778b8b0 (patch) | |
| tree | 0029ba87e14707d7a6dec0754bc4eaf808f22696 /openstackclient/compute | |
| parent | 8efed05e823eb76f309c0fee821fdc67a9886a3a (diff) | |
| download | python-openstackclient-e3ad82164dc5c51b5f3cb75b826bc15a6778b8b0.tar.gz | |
Added AddNetwork command to server
Currently, if users want to add another NIC to a running instance,
they need to (i) create a neutron port and (ii) add the port to the
server via teh AddPort command. It would be more convenient to have
a single command to achieve the equivalent.
Novaclient already support adding network to an instance via the
interface-attach command. This patch introduces a similar capability
in OSC.
Change-Id: Ia3e39c57ae7ecb96aae1b66adc52c289daccb6ec
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/server.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 151c6783..a4f847f5 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -300,6 +300,39 @@ class AddPort(command.Command): server.interface_attach(port_id=port_id, net_id=None, fixed_ip=None) +class AddNetwork(command.Command): + _description = _("Add network to server") + + def get_parser(self, prog_name): + parser = super(AddNetwork, self).get_parser(prog_name) + parser.add_argument( + "server", + metavar="<server>", + help=_("Server to add the network to (name or ID)"), + ) + parser.add_argument( + "network", + metavar="<network>", + help=_("Network to add to the server (name or ID)"), + ) + return parser + + def take_action(self, parsed_args): + compute_client = self.app.client_manager.compute + + server = utils.find_resource( + compute_client.servers, parsed_args.server) + + if self.app.client_manager.is_network_endpoint_enabled(): + network_client = self.app.client_manager.network + net_id = network_client.find_network( + parsed_args.network, ignore_missing=False).id + else: + net_id = parsed_args.network + + server.interface_attach(port_id=None, net_id=net_id, fixed_ip=None) + + class AddServerSecurityGroup(command.Command): _description = _("Add security group to server") |
