2016-02-02 09:35:38 +05:30
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
"""IP Floating action implementations"""
|
|
|
|
|
2016-05-13 16:14:09 -05:00
|
|
|
from osc_lib import utils
|
2019-06-03 14:37:41 -07:00
|
|
|
from osc_lib.utils import tags as _tag
|
2016-05-13 16:14:09 -05:00
|
|
|
|
2024-05-16 12:01:44 +01:00
|
|
|
from openstackclient.api import compute_v2
|
2016-04-16 10:59:37 +08:00
|
|
|
from openstackclient.i18n import _
|
2016-08-16 16:00:32 +07:00
|
|
|
from openstackclient.identity import common as identity_common
|
2016-02-02 09:35:38 +05:30
|
|
|
from openstackclient.network import common
|
2016-11-02 10:11:54 -05:00
|
|
|
|
2018-01-15 22:21:19 +00:00
|
|
|
_formatters = {
|
|
|
|
'port_details': utils.format_dict,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 10:11:54 -05:00
|
|
|
def _get_network_columns(item):
|
2022-01-14 18:51:56 +01:00
|
|
|
column_map = {}
|
2022-06-27 09:17:31 +02:00
|
|
|
hidden_columns = ['location', 'tenant_id']
|
2021-12-16 16:38:41 +01:00
|
|
|
return utils.get_osc_show_columns_for_sdk_resource(
|
2023-05-08 11:03:05 +01:00
|
|
|
item, column_map, hidden_columns
|
2021-12-16 16:38:41 +01:00
|
|
|
)
|
2016-02-02 09:35:38 +05:30
|
|
|
|
|
|
|
|
2016-02-24 17:26:13 +08:00
|
|
|
def _get_columns(item):
|
2016-03-12 10:58:28 +08:00
|
|
|
columns = list(item.keys())
|
2016-02-24 17:26:13 +08:00
|
|
|
return tuple(sorted(columns))
|
|
|
|
|
|
|
|
|
2016-03-03 17:17:40 +08:00
|
|
|
def _get_attrs(client_manager, parsed_args):
|
|
|
|
attrs = {}
|
|
|
|
network_client = client_manager.network
|
|
|
|
|
2016-06-17 15:06:40 +08:00
|
|
|
# Name of a network could be empty string.
|
2016-03-03 17:17:40 +08:00
|
|
|
if parsed_args.network is not None:
|
2023-05-08 11:03:05 +01:00
|
|
|
network = network_client.find_network(
|
|
|
|
parsed_args.network, ignore_missing=False
|
|
|
|
)
|
2016-03-03 17:17:40 +08:00
|
|
|
attrs['floating_network_id'] = network.id
|
|
|
|
|
2016-06-17 15:06:40 +08:00
|
|
|
if parsed_args.subnet:
|
2023-05-08 11:03:05 +01:00
|
|
|
subnet = network_client.find_subnet(
|
|
|
|
parsed_args.subnet, ignore_missing=False
|
|
|
|
)
|
2016-03-03 17:17:40 +08:00
|
|
|
attrs['subnet_id'] = subnet.id
|
|
|
|
|
2016-06-17 15:06:40 +08:00
|
|
|
if parsed_args.port:
|
2023-05-08 11:03:05 +01:00
|
|
|
port = network_client.find_port(parsed_args.port, ignore_missing=False)
|
2016-03-03 17:17:40 +08:00
|
|
|
attrs['port_id'] = port.id
|
|
|
|
|
2016-06-17 15:06:40 +08:00
|
|
|
if parsed_args.floating_ip_address:
|
2016-03-03 17:17:40 +08:00
|
|
|
attrs['floating_ip_address'] = parsed_args.floating_ip_address
|
|
|
|
|
2016-06-17 15:06:40 +08:00
|
|
|
if parsed_args.fixed_ip_address:
|
2016-03-03 17:17:40 +08:00
|
|
|
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
|
|
|
|
|
2017-11-05 12:05:09 +08:00
|
|
|
if parsed_args.qos_policy:
|
|
|
|
attrs['qos_policy_id'] = network_client.find_qos_policy(
|
2023-05-08 11:03:05 +01:00
|
|
|
parsed_args.qos_policy, ignore_missing=False
|
|
|
|
).id
|
2017-11-05 12:05:09 +08:00
|
|
|
|
2016-09-20 12:29:08 -05:00
|
|
|
if parsed_args.description is not None:
|
|
|
|
attrs['description'] = parsed_args.description
|
|
|
|
|
2016-08-16 16:00:32 +07:00
|
|
|
if parsed_args.project:
|
|
|
|
identity_client = client_manager.identity
|
|
|
|
project_id = identity_common.find_project(
|
|
|
|
identity_client,
|
|
|
|
parsed_args.project,
|
|
|
|
parsed_args.project_domain,
|
|
|
|
).id
|
2022-01-14 18:51:56 +01:00
|
|
|
attrs['project_id'] = project_id
|
2016-08-16 16:00:32 +07:00
|
|
|
|
2018-04-04 13:44:24 +00:00
|
|
|
if parsed_args.dns_domain:
|
|
|
|
attrs['dns_domain'] = parsed_args.dns_domain
|
|
|
|
|
|
|
|
if parsed_args.dns_name:
|
|
|
|
attrs['dns_name'] = parsed_args.dns_name
|
|
|
|
|
2016-03-03 17:17:40 +08:00
|
|
|
return attrs
|
|
|
|
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
class CreateFloatingIP(
|
|
|
|
common.NetworkAndComputeShowOne, common.NeutronCommandWithExtraArgs
|
|
|
|
):
|
2016-11-13 09:42:09 -05:00
|
|
|
_description = _("Create floating IP")
|
2016-03-03 17:17:40 +08:00
|
|
|
|
|
|
|
def update_parser_common(self, parser):
|
|
|
|
# In Compute v2 network, floating IPs could be allocated from floating
|
|
|
|
# IP pools, which are actually external networks. So deprecate the
|
|
|
|
# parameter "pool", and use "network" instead.
|
|
|
|
parser.add_argument(
|
|
|
|
'network',
|
|
|
|
metavar='<network>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Network to allocate floating IP from (name or ID)"),
|
2016-03-03 17:17:40 +08:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def update_parser_network(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
'--subnet',
|
|
|
|
metavar='<subnet>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"Subnet on which you want to create the floating IP "
|
|
|
|
"(name or ID)"
|
|
|
|
)
|
|
|
|
),
|
2016-03-03 17:17:40 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--port',
|
|
|
|
metavar='<port>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("Port to be associated with the floating IP " "(name or ID)")
|
|
|
|
),
|
2016-03-03 17:17:40 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--floating-ip-address',
|
2017-04-03 16:15:14 -05:00
|
|
|
metavar='<ip-address>',
|
2016-03-03 17:17:40 +08:00
|
|
|
dest='floating_ip_address',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=self.enhance_help_neutron(_("Floating IP address")),
|
2016-03-03 17:17:40 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--fixed-ip-address',
|
2017-04-03 16:15:14 -05:00
|
|
|
metavar='<ip-address>',
|
2016-03-03 17:17:40 +08:00
|
|
|
dest='fixed_ip_address',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("Fixed IP address mapped to the floating IP")
|
|
|
|
),
|
2016-03-03 17:17:40 +08:00
|
|
|
)
|
2017-11-05 12:05:09 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'--qos-policy',
|
|
|
|
metavar='<qos-policy>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("Attach QoS policy to the floating IP (name or ID)")
|
|
|
|
),
|
2017-11-05 12:05:09 +08:00
|
|
|
)
|
2016-09-20 12:29:08 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
|
|
|
metavar='<description>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=self.enhance_help_neutron(_('Set floating IP description')),
|
2016-09-20 12:29:08 -05:00
|
|
|
)
|
2016-08-16 16:00:32 +07:00
|
|
|
parser.add_argument(
|
|
|
|
'--project',
|
|
|
|
metavar='<project>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=self.enhance_help_neutron(_("Owner's project (name or ID)")),
|
2016-08-16 16:00:32 +07:00
|
|
|
)
|
2018-04-04 13:44:24 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--dns-domain',
|
|
|
|
metavar='<dns-domain>',
|
|
|
|
dest='dns_domain',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("Set DNS domain for this floating IP")
|
|
|
|
),
|
2018-04-04 13:44:24 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--dns-name',
|
|
|
|
metavar='<dns-name>',
|
|
|
|
dest='dns_name',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("Set DNS name for this floating IP")
|
|
|
|
),
|
2018-04-04 13:44:24 +00:00
|
|
|
)
|
|
|
|
|
2019-10-28 17:27:38 -05:00
|
|
|
identity_common.add_project_domain_option_to_parser(
|
2023-05-08 11:03:05 +01:00
|
|
|
parser, enhance_help=self.enhance_help_neutron
|
|
|
|
)
|
2019-10-28 17:27:38 -05:00
|
|
|
_tag.add_tag_option_to_parser_for_create(
|
2023-05-08 11:03:05 +01:00
|
|
|
parser, _('floating IP'), enhance_help=self.enhance_help_neutron
|
|
|
|
)
|
2016-03-03 17:17:40 +08:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action_network(self, client, parsed_args):
|
|
|
|
attrs = _get_attrs(self.app.client_manager, parsed_args)
|
2020-12-22 15:31:44 +01:00
|
|
|
attrs.update(
|
2023-05-08 11:03:05 +01:00
|
|
|
self._parse_extra_properties(parsed_args.extra_properties)
|
|
|
|
)
|
2018-04-04 13:44:24 +00:00
|
|
|
with common.check_missing_extension_if_error(
|
2023-05-08 11:03:05 +01:00
|
|
|
self.app.client_manager.network, attrs
|
|
|
|
):
|
2018-04-04 13:44:24 +00:00
|
|
|
obj = client.create_ip(**attrs)
|
|
|
|
|
2018-02-23 08:03:12 +00:00
|
|
|
# tags cannot be set when created, so tags need to be set later.
|
|
|
|
_tag.update_tags_for_set(client, obj, parsed_args)
|
2018-04-04 13:44:24 +00:00
|
|
|
|
2016-11-02 10:11:54 -05:00
|
|
|
display_columns, columns = _get_network_columns(obj)
|
2016-03-03 17:17:40 +08:00
|
|
|
data = utils.get_item_properties(obj, columns)
|
2016-11-02 10:11:54 -05:00
|
|
|
return (display_columns, data)
|
2016-03-03 17:17:40 +08:00
|
|
|
|
|
|
|
def take_action_compute(self, client, parsed_args):
|
2024-05-16 12:01:44 +01:00
|
|
|
obj = compute_v2.create_floating_ip(client, parsed_args.network)
|
2017-04-08 11:17:30 -05:00
|
|
|
columns = _get_columns(obj)
|
|
|
|
data = utils.get_dict_properties(obj, columns)
|
2016-03-03 17:17:40 +08:00
|
|
|
return (columns, data)
|
|
|
|
|
|
|
|
|
2016-06-12 12:50:30 +08:00
|
|
|
class DeleteFloatingIP(common.NetworkAndComputeDelete):
|
2016-11-13 09:42:09 -05:00
|
|
|
_description = _("Delete floating IP(s)")
|
2016-06-12 12:50:30 +08:00
|
|
|
|
|
|
|
# Used by base class to find resources in parsed_args.
|
|
|
|
resource = 'floating_ip'
|
|
|
|
r = None
|
2016-02-02 09:35:38 +05:30
|
|
|
|
|
|
|
def update_parser_common(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
'floating_ip',
|
|
|
|
metavar="<floating-ip>",
|
2016-06-12 12:50:30 +08:00
|
|
|
nargs="+",
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Floating IP(s) to delete (IP address or ID)"),
|
2016-02-02 09:35:38 +05:30
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action_network(self, client, parsed_args):
|
2018-01-29 09:59:08 -06:00
|
|
|
obj = client.find_ip(
|
2017-01-13 14:05:04 -06:00
|
|
|
self.r,
|
|
|
|
ignore_missing=False,
|
|
|
|
)
|
2016-02-02 09:35:38 +05:30
|
|
|
client.delete_ip(obj)
|
|
|
|
|
|
|
|
def take_action_compute(self, client, parsed_args):
|
2024-05-16 12:01:44 +01:00
|
|
|
compute_v2.delete_floating_ip(client, self.r)
|
2017-01-13 14:05:04 -06:00
|
|
|
|
2016-02-09 14:23:28 +08:00
|
|
|
|
|
|
|
class ListFloatingIP(common.NetworkAndComputeLister):
|
2016-12-09 14:23:26 +08:00
|
|
|
# TODO(songminglong): Use SDK resource mapped attribute names once
|
|
|
|
# the OSC minimum requirements include SDK 1.0
|
2019-10-28 17:27:38 -05:00
|
|
|
|
2016-11-13 09:42:09 -05:00
|
|
|
_description = _("List floating IP(s)")
|
2016-02-09 14:23:28 +08:00
|
|
|
|
2016-11-13 10:11:03 +08:00
|
|
|
def update_parser_network(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
'--network',
|
|
|
|
metavar='<network>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"List floating IP(s) according to "
|
|
|
|
"given network (name or ID)"
|
|
|
|
)
|
|
|
|
),
|
2016-11-13 10:11:03 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--port',
|
|
|
|
metavar='<port>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("List floating IP(s) according to given port (name or ID)")
|
|
|
|
),
|
2016-11-13 10:11:03 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--fixed-ip-address',
|
2017-04-03 16:15:14 -05:00
|
|
|
metavar='<ip-address>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("List floating IP(s) according to given fixed IP address")
|
|
|
|
),
|
2016-11-13 10:11:03 +08:00
|
|
|
)
|
2019-01-07 13:02:57 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'--floating-ip-address',
|
|
|
|
metavar='<ip-address>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"List floating IP(s) according to given floating IP "
|
|
|
|
"address"
|
|
|
|
)
|
|
|
|
),
|
2019-01-07 13:02:57 +01:00
|
|
|
)
|
2016-12-09 14:23:26 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'--long',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_("List additional fields in output")
|
|
|
|
),
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--status',
|
|
|
|
metavar='<status>',
|
|
|
|
choices=['ACTIVE', 'DOWN'],
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"List floating IP(s) according to given status ('ACTIVE', "
|
|
|
|
"'DOWN')"
|
|
|
|
)
|
|
|
|
),
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--project',
|
|
|
|
metavar='<project>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"List floating IP(s) according to given project (name or "
|
|
|
|
"ID)"
|
|
|
|
)
|
|
|
|
),
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
|
|
|
identity_common.add_project_domain_option_to_parser(parser)
|
|
|
|
parser.add_argument(
|
|
|
|
'--router',
|
|
|
|
metavar='<router>',
|
2019-10-28 17:27:38 -05:00
|
|
|
help=self.enhance_help_neutron(
|
2023-05-08 11:03:05 +01:00
|
|
|
_(
|
|
|
|
"List floating IP(s) according to given router (name or "
|
|
|
|
"ID)"
|
|
|
|
)
|
|
|
|
),
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
2019-10-28 17:27:38 -05:00
|
|
|
_tag.add_tag_filtering_option_to_parser(
|
2023-05-08 11:03:05 +01:00
|
|
|
parser, _('floating IP'), enhance_help=self.enhance_help_neutron
|
|
|
|
)
|
2016-11-13 10:11:03 +08:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
2016-02-09 14:23:28 +08:00
|
|
|
def take_action_network(self, client, parsed_args):
|
2016-11-13 10:11:03 +08:00
|
|
|
network_client = self.app.client_manager.network
|
2016-12-09 14:23:26 +08:00
|
|
|
identity_client = self.app.client_manager.identity
|
2016-11-13 10:11:03 +08:00
|
|
|
|
2016-02-16 14:33:31 +08:00
|
|
|
columns = (
|
|
|
|
'id',
|
|
|
|
'floating_ip_address',
|
|
|
|
'fixed_ip_address',
|
|
|
|
'port_id',
|
2016-10-04 16:25:07 +05:30
|
|
|
'floating_network_id',
|
|
|
|
'project_id',
|
2016-02-16 14:33:31 +08:00
|
|
|
)
|
|
|
|
headers = (
|
|
|
|
'ID',
|
|
|
|
'Floating IP Address',
|
|
|
|
'Fixed IP Address',
|
|
|
|
'Port',
|
2016-10-04 16:25:07 +05:30
|
|
|
'Floating Network',
|
|
|
|
'Project',
|
2016-02-16 14:33:31 +08:00
|
|
|
)
|
2016-12-09 14:23:26 +08:00
|
|
|
if parsed_args.long:
|
|
|
|
columns = columns + (
|
|
|
|
'router_id',
|
|
|
|
'status',
|
|
|
|
'description',
|
2018-02-23 08:03:12 +00:00
|
|
|
'tags',
|
2018-04-04 13:44:24 +00:00
|
|
|
'dns_name',
|
|
|
|
'dns_domain',
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
|
|
|
headers = headers + (
|
|
|
|
'Router',
|
|
|
|
'Status',
|
|
|
|
'Description',
|
2018-02-23 08:03:12 +00:00
|
|
|
'Tags',
|
2018-04-04 13:44:24 +00:00
|
|
|
'DNS Name',
|
|
|
|
'DNS Domain',
|
2016-12-09 14:23:26 +08:00
|
|
|
)
|
2016-02-16 14:33:31 +08:00
|
|
|
|
2016-02-09 14:23:28 +08:00
|
|
|
query = {}
|
2016-11-13 10:11:03 +08:00
|
|
|
|
|
|
|
if parsed_args.network is not None:
|
2023-05-08 11:03:05 +01:00
|
|
|
network = network_client.find_network(
|
|
|
|
parsed_args.network, ignore_missing=False
|
|
|
|
)
|
2016-11-13 10:11:03 +08:00
|
|
|
query['floating_network_id'] = network.id
|
|
|
|
if parsed_args.port is not None:
|
2023-05-08 11:03:05 +01:00
|
|
|
port = network_client.find_port(
|
|
|
|
parsed_args.port, ignore_missing=False
|
|
|
|
)
|
2016-11-13 10:11:03 +08:00
|
|
|
query['port_id'] = port.id
|
|
|
|
if parsed_args.fixed_ip_address is not None:
|
|
|
|
query['fixed_ip_address'] = parsed_args.fixed_ip_address
|
2019-01-07 13:02:57 +01:00
|
|
|
if parsed_args.floating_ip_address is not None:
|
|
|
|
query['floating_ip_address'] = parsed_args.floating_ip_address
|
2016-12-09 14:23:26 +08:00
|
|
|
if parsed_args.status:
|
|
|
|
query['status'] = parsed_args.status
|
|
|
|
if parsed_args.project is not None:
|
|
|
|
project = identity_common.find_project(
|
|
|
|
identity_client,
|
|
|
|
parsed_args.project,
|
|
|
|
parsed_args.project_domain,
|
|
|
|
)
|
|
|
|
query['project_id'] = project.id
|
|
|
|
if parsed_args.router is not None:
|
2023-05-08 11:03:05 +01:00
|
|
|
router = network_client.find_router(
|
|
|
|
parsed_args.router, ignore_missing=False
|
|
|
|
)
|
2016-12-09 14:23:26 +08:00
|
|
|
query['router_id'] = router.id
|
2016-11-13 10:11:03 +08:00
|
|
|
|
2018-02-23 08:03:12 +00:00
|
|
|
_tag.get_tag_filtering_args(parsed_args, query)
|
|
|
|
|
2016-02-09 14:23:28 +08:00
|
|
|
data = client.ips(**query)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
return (
|
|
|
|
headers,
|
|
|
|
(
|
|
|
|
utils.get_item_properties(
|
|
|
|
s,
|
|
|
|
columns,
|
2016-02-09 14:23:28 +08:00
|
|
|
formatters={},
|
2023-05-08 11:03:05 +01:00
|
|
|
)
|
|
|
|
for s in data
|
|
|
|
),
|
|
|
|
)
|
2016-02-09 14:23:28 +08:00
|
|
|
|
|
|
|
def take_action_compute(self, client, parsed_args):
|
2016-02-16 14:33:31 +08:00
|
|
|
columns = (
|
|
|
|
'ID',
|
|
|
|
'IP',
|
|
|
|
'Fixed IP',
|
|
|
|
'Instance ID',
|
|
|
|
'Pool',
|
|
|
|
)
|
|
|
|
headers = (
|
|
|
|
'ID',
|
|
|
|
'Floating IP Address',
|
|
|
|
'Fixed IP Address',
|
|
|
|
'Server',
|
|
|
|
'Pool',
|
|
|
|
)
|
|
|
|
|
2024-05-16 12:01:44 +01:00
|
|
|
objs = compute_v2.list_floating_ips(client)
|
2023-05-08 11:03:05 +01:00
|
|
|
return (
|
|
|
|
headers,
|
|
|
|
(
|
|
|
|
utils.get_dict_properties(
|
|
|
|
s,
|
|
|
|
columns,
|
2016-02-09 14:23:28 +08:00
|
|
|
formatters={},
|
2023-05-08 11:03:05 +01:00
|
|
|
)
|
2024-05-16 12:01:44 +01:00
|
|
|
for s in objs
|
2023-05-08 11:03:05 +01:00
|
|
|
),
|
|
|
|
)
|
2016-02-24 17:26:13 +08:00
|
|
|
|
|
|
|
|
2020-12-22 15:31:44 +01:00
|
|
|
class SetFloatingIP(common.NeutronCommandWithExtraArgs):
|
2016-10-06 10:01:59 -05:00
|
|
|
_description = _("Set floating IP Properties")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super().get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'floating_ip',
|
|
|
|
metavar='<floating-ip>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Floating IP to modify (IP address or ID)"),
|
|
|
|
)
|
2016-10-06 10:01:59 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--port',
|
|
|
|
metavar='<port>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Associate the floating IP with port (name or ID)"),
|
|
|
|
),
|
2016-10-06 10:01:59 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--fixed-ip-address',
|
|
|
|
metavar='<ip-address>',
|
|
|
|
dest='fixed_ip_address',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_(
|
|
|
|
"Fixed IP of the port "
|
|
|
|
"(required only if port has multiple IPs)"
|
|
|
|
),
|
2016-10-06 10:01:59 -05:00
|
|
|
)
|
2020-03-18 15:51:55 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--description',
|
|
|
|
metavar='<description>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_('Set floating IP description'),
|
2020-03-18 15:51:55 +00:00
|
|
|
)
|
2017-11-05 12:05:09 +08:00
|
|
|
qos_policy_group = parser.add_mutually_exclusive_group()
|
|
|
|
qos_policy_group.add_argument(
|
|
|
|
'--qos-policy',
|
|
|
|
metavar='<qos-policy>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Attach QoS policy to the floating IP (name or ID)"),
|
2017-11-05 12:05:09 +08:00
|
|
|
)
|
|
|
|
qos_policy_group.add_argument(
|
|
|
|
'--no-qos-policy',
|
|
|
|
action='store_true',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Remove the QoS policy attached to the floating IP"),
|
2017-11-05 12:05:09 +08:00
|
|
|
)
|
2018-02-23 08:03:12 +00:00
|
|
|
|
|
|
|
_tag.add_tag_option_to_parser_for_set(parser, _('floating IP'))
|
|
|
|
|
2016-10-06 10:01:59 -05:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
client = self.app.client_manager.network
|
|
|
|
attrs = {}
|
2018-01-29 09:59:08 -06:00
|
|
|
obj = client.find_ip(
|
2016-10-06 10:01:59 -05:00
|
|
|
parsed_args.floating_ip,
|
|
|
|
ignore_missing=False,
|
|
|
|
)
|
2018-06-13 05:21:53 -04:00
|
|
|
if parsed_args.port:
|
2023-05-08 11:03:05 +01:00
|
|
|
port = client.find_port(parsed_args.port, ignore_missing=False)
|
2018-06-13 05:21:53 -04:00
|
|
|
attrs['port_id'] = port.id
|
|
|
|
|
2016-10-06 10:01:59 -05:00
|
|
|
if parsed_args.fixed_ip_address:
|
|
|
|
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
|
|
|
|
|
2020-03-18 15:51:55 +00:00
|
|
|
if parsed_args.description:
|
|
|
|
attrs['description'] = parsed_args.description
|
|
|
|
|
2017-11-05 12:05:09 +08:00
|
|
|
if parsed_args.qos_policy:
|
|
|
|
attrs['qos_policy_id'] = client.find_qos_policy(
|
2023-05-08 11:03:05 +01:00
|
|
|
parsed_args.qos_policy, ignore_missing=False
|
|
|
|
).id
|
2017-11-05 12:05:09 +08:00
|
|
|
|
|
|
|
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
|
|
|
|
attrs['qos_policy_id'] = None
|
|
|
|
|
2020-12-22 15:31:44 +01:00
|
|
|
attrs.update(
|
2023-05-08 11:03:05 +01:00
|
|
|
self._parse_extra_properties(parsed_args.extra_properties)
|
|
|
|
)
|
2020-12-22 15:31:44 +01:00
|
|
|
|
2018-02-23 08:03:12 +00:00
|
|
|
if attrs:
|
|
|
|
client.update_ip(obj, **attrs)
|
|
|
|
|
|
|
|
# tags is a subresource and it needs to be updated separately.
|
|
|
|
_tag.update_tags_for_set(client, obj, parsed_args)
|
2016-10-06 10:01:59 -05:00
|
|
|
|
|
|
|
|
2016-02-24 17:26:13 +08:00
|
|
|
class ShowFloatingIP(common.NetworkAndComputeShowOne):
|
2016-11-13 09:42:09 -05:00
|
|
|
_description = _("Display floating IP details")
|
2016-02-24 17:26:13 +08:00
|
|
|
|
|
|
|
def update_parser_common(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
'floating_ip',
|
|
|
|
metavar="<floating-ip>",
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Floating IP to display (IP address or ID)"),
|
2016-02-24 17:26:13 +08:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action_network(self, client, parsed_args):
|
2018-01-29 09:59:08 -06:00
|
|
|
obj = client.find_ip(
|
2017-01-13 14:05:04 -06:00
|
|
|
parsed_args.floating_ip,
|
|
|
|
ignore_missing=False,
|
|
|
|
)
|
2016-11-02 10:11:54 -05:00
|
|
|
display_columns, columns = _get_network_columns(obj)
|
2018-01-15 22:21:19 +00:00
|
|
|
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
2016-11-02 10:11:54 -05:00
|
|
|
return (display_columns, data)
|
2016-02-24 17:26:13 +08:00
|
|
|
|
|
|
|
def take_action_compute(self, client, parsed_args):
|
2024-05-16 12:01:44 +01:00
|
|
|
obj = compute_v2.get_floating_ip(client, parsed_args.floating_ip)
|
2017-04-08 11:17:30 -05:00
|
|
|
columns = _get_columns(obj)
|
|
|
|
data = utils.get_dict_properties(obj, columns)
|
2016-02-24 17:26:13 +08:00
|
|
|
return (columns, data)
|
2016-06-17 15:06:40 +08:00
|
|
|
|
|
|
|
|
2020-12-22 15:31:44 +01:00
|
|
|
class UnsetFloatingIP(common.NeutronCommandWithExtraArgs):
|
2016-10-06 10:01:59 -05:00
|
|
|
_description = _("Unset floating IP Properties")
|
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super().get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'floating_ip',
|
|
|
|
metavar='<floating-ip>',
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Floating IP to disassociate (IP address or ID)"),
|
|
|
|
)
|
2016-10-06 10:01:59 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--port',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Disassociate any port associated with the floating IP"),
|
2016-10-06 10:01:59 -05:00
|
|
|
)
|
2017-11-05 12:05:09 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'--qos-policy',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2023-05-08 11:03:05 +01:00
|
|
|
help=_("Remove the QoS policy attached to the floating IP"),
|
2017-11-05 12:05:09 +08:00
|
|
|
)
|
2018-02-23 08:03:12 +00:00
|
|
|
_tag.add_tag_option_to_parser_for_unset(parser, _('floating IP'))
|
|
|
|
|
2016-10-06 10:01:59 -05:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def take_action(self, parsed_args):
|
|
|
|
client = self.app.client_manager.network
|
2018-01-29 09:59:08 -06:00
|
|
|
obj = client.find_ip(
|
2016-10-06 10:01:59 -05:00
|
|
|
parsed_args.floating_ip,
|
|
|
|
ignore_missing=False,
|
|
|
|
)
|
2017-11-05 12:05:09 +08:00
|
|
|
attrs = {}
|
2016-10-06 10:01:59 -05:00
|
|
|
if parsed_args.port:
|
2017-11-05 12:05:09 +08:00
|
|
|
attrs['port_id'] = None
|
|
|
|
if parsed_args.qos_policy:
|
|
|
|
attrs['qos_policy_id'] = None
|
2020-12-22 15:31:44 +01:00
|
|
|
attrs.update(
|
2023-05-08 11:03:05 +01:00
|
|
|
self._parse_extra_properties(parsed_args.extra_properties)
|
|
|
|
)
|
2017-11-05 12:05:09 +08:00
|
|
|
|
|
|
|
if attrs:
|
2016-10-06 10:01:59 -05:00
|
|
|
client.update_ip(obj, **attrs)
|
2018-02-23 08:03:12 +00:00
|
|
|
|
|
|
|
# tags is a subresource and it needs to be updated separately.
|
|
|
|
_tag.update_tags_for_unset(client, obj, parsed_args)
|