summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/server.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2018-03-05 14:18:41 -0600
committerMatt Riedemann <mriedem.os@gmail.com>2018-04-20 10:08:06 -0400
commit6c8967dc8eeea1d64b8b7a17bee1f8d1aa647bed (patch)
treef6f4ba8bcd588c8d7d47565cd2ed4a8f231691f1 /openstackclient/compute/v2/server.py
parentcc3dd2abe23b5363a963206e89371be493d43ad7 (diff)
downloadpython-openstackclient-3.14.2.tar.gz
Re-implement novaclient bits removed in 10.03.14.2
a) /os-floating-ips was removed in Compute API 2.36 and from novaclient's Python API in 10.0 Add to api.computev2: floating_ip_add() floating_ip_remove() Convert add floating IP command to nova-net/neutron split: "server add floating ip" "server remove floating ip" b) /os-hosts was removed in Compute API 2.43 and from novaclient's Python API in 10.0. Add to api.computev2: host_list() host_set() host_show() Convert host commands to use intenal api: "host list" "host set" "host show" c) The introduction of the Network-style commands into the server group broke cliff's autoprogram directive as it executes the get_parser() methods without fully initializing the Command object. NOTE: This is really three reviews squashed to get through the gate in one pass. Closes-Bug: #1745795 Change-Id: I5116086f9a9e4b2b31a744bf8f4558c79f0bfe59 (cherry picked from commit 53e7aab7ed4d6c981ca067c1db8bce290a5f0055)
Diffstat (limited to 'openstackclient/compute/v2/server.py')
-rw-r--r--openstackclient/compute/v2/server.py59
1 files changed, 42 insertions, 17 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index c08f5cae..85c20aee 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -32,6 +32,7 @@ import six
from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
+from openstackclient.network import common as network_common
LOG = logging.getLogger(__name__)
@@ -234,11 +235,10 @@ class AddFixedIP(command.Command):
)
-class AddFloatingIP(command.Command):
+class AddFloatingIP(network_common.NetworkAndComputeCommand):
_description = _("Add floating IP address to server")
- def get_parser(self, prog_name):
- parser = super(AddFloatingIP, self).get_parser(prog_name)
+ def update_parser_common(self, parser):
parser.add_argument(
"server",
metavar="<server>",
@@ -252,19 +252,37 @@ class AddFloatingIP(command.Command):
parser.add_argument(
"--fixed-ip-address",
metavar="<ip-address>",
- help=_("Fixed IP address to associate with this floating IP "
- "address"),
+ help=_(
+ "Fixed IP address to associate with this floating IP address"
+ ),
)
return parser
- def take_action(self, parsed_args):
+ def take_action_network(self, client, parsed_args):
compute_client = self.app.client_manager.compute
+ attrs = {}
+ obj = client.find_ip(
+ parsed_args.ip_address,
+ ignore_missing=False,
+ )
server = utils.find_resource(
- compute_client.servers, parsed_args.server)
+ compute_client.servers,
+ parsed_args.server,
+ )
+ port = list(client.ports(device_id=server.id))[0]
+ attrs['port_id'] = port.id
+ if parsed_args.fixed_ip_address:
+ attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
+
+ client.update_ip(obj, **attrs)
- server.add_floating_ip(parsed_args.ip_address,
- parsed_args.fixed_ip_address)
+ def take_action_compute(self, client, parsed_args):
+ client.api.floating_ip_add(
+ parsed_args.server,
+ parsed_args.ip_address,
+ fixed_address=parsed_args.fixed_ip_address,
+ )
class AddPort(command.Command):
@@ -1482,11 +1500,10 @@ class RemoveFixedIP(command.Command):
server.remove_fixed_ip(parsed_args.ip_address)
-class RemoveFloatingIP(command.Command):
+class RemoveFloatingIP(network_common.NetworkAndComputeCommand):
_description = _("Remove floating IP address from server")
- def get_parser(self, prog_name):
- parser = super(RemoveFloatingIP, self).get_parser(prog_name)
+ def update_parser_common(self, parser):
parser.add_argument(
"server",
metavar="<server>",
@@ -1501,13 +1518,21 @@ class RemoveFloatingIP(command.Command):
)
return parser
- def take_action(self, parsed_args):
- compute_client = self.app.client_manager.compute
+ def take_action_network(self, client, parsed_args):
+ attrs = {}
+ obj = client.find_ip(
+ parsed_args.ip_address,
+ ignore_missing=False,
+ )
+ attrs['port_id'] = None
- server = utils.find_resource(
- compute_client.servers, parsed_args.server)
+ client.update_ip(obj, **attrs)
- server.remove_floating_ip(parsed_args.ip_address)
+ def take_action_compute(self, client, parsed_args):
+ client.api.floating_ip_remove(
+ parsed_args.server,
+ parsed_args.ip_address,
+ )
class RemovePort(command.Command):