Blacken openstackclient.network

Black used with the '-l 79 -S' flags.

A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.

Change-Id: I8048746dbc2ef0cb582f68934734db4c1153d779
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane
2023-05-08 11:03:05 +01:00
parent 35ba1d8f13
commit 6475dc58e8
100 changed files with 10499 additions and 7628 deletions

View File

@@ -50,7 +50,9 @@ def build_option_parser(parser):
'--os-network-api-version',
metavar='<network-api-version>',
default=utils.env('OS_NETWORK_API_VERSION'),
help=_("Network API version, default=%s "
"(Env: OS_NETWORK_API_VERSION)") % DEFAULT_API_VERSION
help=_(
"Network API version, default=%s " "(Env: OS_NETWORK_API_VERSION)"
)
% DEFAULT_API_VERSION,
)
return parser

View File

@@ -64,6 +64,7 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
But the command classes are used for docs builds as well, and docs must
present the options for both network types, often qualified accordingly.
"""
@property
def _network_type(self):
"""Discover whether the running cloud is using neutron or nova-network.
@@ -85,7 +86,9 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
except AttributeError:
LOG.warning(
"%s: Could not detect a network type. Assuming we are "
"building docs.", self.__class__.__name__)
"building docs.",
self.__class__.__name__,
)
net_type = None
self._net_type = net_type
return self._net_type
@@ -118,11 +121,14 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
def split_help(network_help, compute_help):
return (
"*%(network_qualifier)s:*\n %(network_help)s\n\n"
"*%(compute_qualifier)s:*\n %(compute_help)s" % dict(
"*%(compute_qualifier)s:*\n %(compute_help)s"
% dict(
network_qualifier=_("Network version 2"),
network_help=network_help,
compute_qualifier=_("Compute version 2"),
compute_help=compute_help))
compute_help=compute_help,
)
)
def get_parser(self, prog_name):
LOG.debug('get_parser(%s)', prog_name)
@@ -150,11 +156,13 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
def take_action(self, parsed_args):
if self.is_neutron:
return self.take_action_network(self.app.client_manager.network,
parsed_args)
return self.take_action_network(
self.app.client_manager.network, parsed_args
)
elif self.is_nova_network:
return self.take_action_compute(self.app.client_manager.compute,
parsed_args)
return self.take_action_compute(
self.app.client_manager.compute, parsed_args
)
def take_action_network(self, client, parsed_args):
"""Override to do something useful."""
@@ -165,8 +173,9 @@ class NetDetectionMixin(metaclass=abc.ABCMeta):
pass
class NetworkAndComputeCommand(NetDetectionMixin, command.Command,
metaclass=abc.ABCMeta):
class NetworkAndComputeCommand(
NetDetectionMixin, command.Command, metaclass=abc.ABCMeta
):
"""Network and Compute Command
Command class for commands that support implementation via
@@ -174,11 +183,11 @@ class NetworkAndComputeCommand(NetDetectionMixin, command.Command,
implementations for take_action() and may even have different
arguments.
"""
pass
class NetworkAndComputeDelete(NetworkAndComputeCommand,
metaclass=abc.ABCMeta):
class NetworkAndComputeDelete(NetworkAndComputeCommand, metaclass=abc.ABCMeta):
"""Network and Compute Delete
Delete class for commands that support implementation via
@@ -196,17 +205,21 @@ class NetworkAndComputeDelete(NetworkAndComputeCommand,
self.r = r
try:
if self.app.client_manager.is_network_endpoint_enabled():
self.take_action_network(self.app.client_manager.network,
parsed_args)
self.take_action_network(
self.app.client_manager.network, parsed_args
)
else:
self.take_action_compute(self.app.client_manager.compute,
parsed_args)
self.take_action_compute(
self.app.client_manager.compute, parsed_args
)
except Exception as e:
msg = _("Failed to delete %(resource)s with name or ID "
"'%(name_or_id)s': %(e)s") % {
"resource": self.resource,
"name_or_id": r,
"e": e,
msg = _(
"Failed to delete %(resource)s with name or ID "
"'%(name_or_id)s': %(e)s"
) % {
"resource": self.resource,
"name_or_id": r,
"e": e,
}
LOG.error(msg)
ret += 1
@@ -221,8 +234,9 @@ class NetworkAndComputeDelete(NetworkAndComputeCommand,
raise exceptions.CommandError(msg)
class NetworkAndComputeLister(NetDetectionMixin, command.Lister,
metaclass=abc.ABCMeta):
class NetworkAndComputeLister(
NetDetectionMixin, command.Lister, metaclass=abc.ABCMeta
):
"""Network and Compute Lister
Lister class for commands that support implementation via
@@ -230,11 +244,13 @@ class NetworkAndComputeLister(NetDetectionMixin, command.Lister,
implementations for take_action() and may even have different
arguments.
"""
pass
class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne,
metaclass=abc.ABCMeta):
class NetworkAndComputeShowOne(
NetDetectionMixin, command.ShowOne, metaclass=abc.ABCMeta
):
"""Network and Compute ShowOne
ShowOne class for commands that support implementation via
@@ -247,10 +263,12 @@ class NetworkAndComputeShowOne(NetDetectionMixin, command.ShowOne,
try:
if self.app.client_manager.is_network_endpoint_enabled():
return self.take_action_network(
self.app.client_manager.network, parsed_args)
self.app.client_manager.network, parsed_args
)
else:
return self.take_action_compute(
self.app.client_manager.compute, parsed_args)
self.app.client_manager.compute, parsed_args
)
except openstack.exceptions.HttpException as exc:
msg = _("Error while executing command: %s") % exc.message
if exc.details:
@@ -282,10 +300,13 @@ class NeutronCommandWithExtraArgs(command.Command):
if not converter:
raise exceptions.CommandError(
_("Type {property_type} of property {name} "
"is not supported").format(
property_type=_property['type'],
name=_property['name']))
_(
"Type {property_type} of property {name} "
"is not supported"
).format(
property_type=_property['type'], name=_property['name']
)
)
return converter
def _parse_extra_properties(self, extra_properties):
@@ -301,25 +322,26 @@ class NeutronCommandWithExtraArgs(command.Command):
parser.add_argument(
'--extra-property',
metavar='type=<property_type>,name=<property_name>,'
'value=<property_value>',
'value=<property_value>',
dest='extra_properties',
action=parseractions.MultiKeyValueAction,
required_keys=['name', 'value'],
optional_keys=['type'],
help=_("Additional parameters can be passed using this property. "
"Default type of the extra property is string ('str'), but "
"other types can be used as well. Available types are: "
"'dict', 'list', 'str', 'bool', 'int'. "
"In case of 'list' type, 'value' can be "
"semicolon-separated list of values. "
"For 'dict' value is semicolon-separated list of the "
"key:value pairs.")
help=_(
"Additional parameters can be passed using this property. "
"Default type of the extra property is string ('str'), but "
"other types can be used as well. Available types are: "
"'dict', 'list', 'str', 'bool', 'int'. "
"In case of 'list' type, 'value' can be "
"semicolon-separated list of values. "
"For 'dict' value is semicolon-separated list of the "
"key:value pairs."
),
)
return parser
class NeutronUnsetCommandWithExtraArgs(NeutronCommandWithExtraArgs):
def _parse_extra_properties(self, extra_properties):
result = {}
if extra_properties:

View File

@@ -31,9 +31,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -65,27 +63,27 @@ class CreateAddressGroup(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateAddressGroup, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar="<name>",
help=_("New address group name")
'name', metavar="<name>", help=_("New address group name")
)
parser.add_argument(
'--description',
metavar="<description>",
help=_("New address group description")
help=_("New address group description"),
)
parser.add_argument(
"--address",
metavar="<ip-address>",
action='append',
default=[],
help=_("IP address or CIDR "
"(repeat option to set multiple addresses)"),
help=_(
"IP address or CIDR "
"(repeat option to set multiple addresses)"
),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -96,7 +94,8 @@ class CreateAddressGroup(command.ShowOne, common.NeutronCommandWithExtraArgs):
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_address_group(**attrs)
display_columns, columns = _get_columns(obj)
@@ -114,7 +113,7 @@ class DeleteAddressGroup(command.Command):
'address_group',
metavar="<address-group>",
nargs='+',
help=_("Address group(s) to delete (name or ID)")
help=_("Address group(s) to delete (name or ID)"),
)
return parser
@@ -129,14 +128,19 @@ class DeleteAddressGroup(command.Command):
client.delete_address_group(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete address group with "
"name or ID '%(group)s': %(e)s"),
{'group': group, 'e': e})
LOG.error(
_(
"Failed to delete address group with "
"name or ID '%(group)s': %(e)s"
),
{'group': group, 'e': e},
)
if result > 0:
total = len(parsed_args.address_group)
msg = (_("%(result)s of %(total)s address groups failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s address groups failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -149,13 +153,15 @@ class ListAddressGroup(command.Lister):
parser.add_argument(
'--name',
metavar='<name>',
help=_("List only address groups of given name in output")
help=_("List only address groups of given name in output"),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("List address groups according to their project "
"(name or ID)")
help=_(
"List address groups according to their project "
"(name or ID)"
),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -190,10 +196,17 @@ class ListAddressGroup(command.Lister):
attrs['project_id'] = project_id
data = client.address_groups(**attrs)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters={},
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
class SetAddressGroup(common.NeutronCommandWithExtraArgs):
@@ -204,46 +217,48 @@ class SetAddressGroup(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'address_group',
metavar="<address-group>",
help=_("Address group to modify (name or ID)")
help=_("Address group to modify (name or ID)"),
)
parser.add_argument(
'--name',
metavar="<name>",
help=_('Set address group name')
'--name', metavar="<name>", help=_('Set address group name')
)
parser.add_argument(
'--description',
metavar="<description>",
help=_('Set address group description')
help=_('Set address group description'),
)
parser.add_argument(
"--address",
metavar="<ip-address>",
action='append',
default=[],
help=_("IP address or CIDR "
"(repeat option to set multiple addresses)"),
help=_(
"IP address or CIDR "
"(repeat option to set multiple addresses)"
),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_address_group(
parsed_args.address_group,
ignore_missing=False)
parsed_args.address_group, ignore_missing=False
)
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
if attrs:
client.update_address_group(obj, **attrs)
if parsed_args.address:
client.add_addresses_to_address_group(
obj, _format_addresses(parsed_args.address))
obj, _format_addresses(parsed_args.address)
)
class ShowAddressGroup(command.ShowOne):
@@ -254,7 +269,7 @@ class ShowAddressGroup(command.ShowOne):
parser.add_argument(
'address_group',
metavar="<address-group>",
help=_("Address group to display (name or ID)")
help=_("Address group to display (name or ID)"),
)
return parser
@@ -262,8 +277,8 @@ class ShowAddressGroup(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_address_group(
parsed_args.address_group,
ignore_missing=False)
parsed_args.address_group, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -278,23 +293,26 @@ class UnsetAddressGroup(command.Command):
parser.add_argument(
'address_group',
metavar="<address-group>",
help=_("Address group to modify (name or ID)")
help=_("Address group to modify (name or ID)"),
)
parser.add_argument(
"--address",
metavar="<ip-address>",
action='append',
default=[],
help=_("IP address or CIDR "
"(repeat option to unset multiple addresses)"),
help=_(
"IP address or CIDR "
"(repeat option to unset multiple addresses)"
),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_address_group(
parsed_args.address_group,
ignore_missing=False)
parsed_args.address_group, ignore_missing=False
)
if parsed_args.address:
client.remove_addresses_from_address_group(
obj, _format_addresses(parsed_args.address))
obj, _format_addresses(parsed_args.address)
)

View File

@@ -32,9 +32,7 @@ def _get_columns(item):
}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -66,21 +64,19 @@ class CreateAddressScope(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateAddressScope, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar="<name>",
help=_("New address scope name")
'name', metavar="<name>", help=_("New address scope name")
)
parser.add_argument(
'--ip-version',
type=int,
default=4,
choices=[4, 6],
help=_("IP version (default is 4)")
help=_("IP version (default is 4)"),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -88,12 +84,14 @@ class CreateAddressScope(command.ShowOne, common.NeutronCommandWithExtraArgs):
share_group.add_argument(
'--share',
action='store_true',
help=_('Share the address scope between projects')
help=_('Share the address scope between projects'),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_('Do not share the address scope between projects (default)')
help=_(
'Do not share the address scope between projects (default)'
),
)
return parser
@@ -102,7 +100,8 @@ class CreateAddressScope(command.ShowOne, common.NeutronCommandWithExtraArgs):
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_address_scope(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -119,7 +118,7 @@ class DeleteAddressScope(command.Command):
'address_scope',
metavar="<address-scope>",
nargs='+',
help=_("Address scope(s) to delete (name or ID)")
help=_("Address scope(s) to delete (name or ID)"),
)
return parser
@@ -134,14 +133,19 @@ class DeleteAddressScope(command.Command):
client.delete_address_scope(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete address scope with "
"name or ID '%(scope)s': %(e)s"),
{'scope': scope, 'e': e})
LOG.error(
_(
"Failed to delete address scope with "
"name or ID '%(scope)s': %(e)s"
),
{'scope': scope, 'e': e},
)
if result > 0:
total = len(parsed_args.address_scope)
msg = (_("%(result)s of %(total)s address scopes failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s address scopes failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -156,7 +160,7 @@ class ListAddressScope(command.Lister):
parser.add_argument(
'--name',
metavar='<name>',
help=_("List only address scopes of given name in output")
help=_("List only address scopes of given name in output"),
)
parser.add_argument(
'--ip-version',
@@ -164,13 +168,17 @@ class ListAddressScope(command.Lister):
choices=[4, 6],
metavar='<ip-version>',
dest='ip_version',
help=_("List address scopes of given IP version networks (4 or 6)")
help=_(
"List address scopes of given IP version networks (4 or 6)"
),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("List address scopes according to their project "
"(name or ID)")
help=_(
"List address scopes according to their project "
"(name or ID)"
),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -178,12 +186,12 @@ class ListAddressScope(command.Lister):
shared_group.add_argument(
'--share',
action='store_true',
help=_("List address scopes shared between projects")
help=_("List address scopes shared between projects"),
)
shared_group.add_argument(
'--no-share',
action='store_true',
help=_("List address scopes not shared between projects")
help=_("List address scopes not shared between projects"),
)
return parser
@@ -222,10 +230,17 @@ class ListAddressScope(command.Lister):
attrs['project_id'] = project_id
data = client.address_scopes(**attrs)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters={},
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
# TODO(rtheis): Use the SDK resource mapped attribute names once the
@@ -238,23 +253,21 @@ class SetAddressScope(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'address_scope',
metavar="<address-scope>",
help=_("Address scope to modify (name or ID)")
help=_("Address scope to modify (name or ID)"),
)
parser.add_argument(
'--name',
metavar="<name>",
help=_('Set address scope name')
'--name', metavar="<name>", help=_('Set address scope name')
)
share_group = parser.add_mutually_exclusive_group()
share_group.add_argument(
'--share',
action='store_true',
help=_('Share the address scope between projects')
help=_('Share the address scope between projects'),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_('Do not share the address scope between projects')
help=_('Do not share the address scope between projects'),
)
return parser
@@ -262,8 +275,8 @@ class SetAddressScope(common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_address_scope(
parsed_args.address_scope,
ignore_missing=False)
parsed_args.address_scope, ignore_missing=False
)
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
@@ -272,7 +285,8 @@ class SetAddressScope(common.NeutronCommandWithExtraArgs):
if parsed_args.no_share:
attrs['shared'] = False
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_address_scope(obj, **attrs)
@@ -284,7 +298,7 @@ class ShowAddressScope(command.ShowOne):
parser.add_argument(
'address_scope',
metavar="<address-scope>",
help=_("Address scope to display (name or ID)")
help=_("Address scope to display (name or ID)"),
)
return parser
@@ -292,8 +306,8 @@ class ShowAddressScope(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_address_scope(
parsed_args.address_scope,
ignore_missing=False)
parsed_args.address_scope, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})

View File

@@ -30,9 +30,7 @@ def _get_network_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -47,18 +45,19 @@ def _get_attrs(client_manager, parsed_args):
# Name of a network could be empty string.
if parsed_args.network is not None:
network = network_client.find_network(parsed_args.network,
ignore_missing=False)
network = network_client.find_network(
parsed_args.network, ignore_missing=False
)
attrs['floating_network_id'] = network.id
if parsed_args.subnet:
subnet = network_client.find_subnet(parsed_args.subnet,
ignore_missing=False)
subnet = network_client.find_subnet(
parsed_args.subnet, ignore_missing=False
)
attrs['subnet_id'] = subnet.id
if parsed_args.port:
port = network_client.find_port(parsed_args.port,
ignore_missing=False)
port = network_client.find_port(parsed_args.port, ignore_missing=False)
attrs['port_id'] = port.id
if parsed_args.floating_ip_address:
@@ -69,7 +68,8 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.qos_policy:
attrs['qos_policy_id'] = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False).id
parsed_args.qos_policy, ignore_missing=False
).id
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
@@ -92,8 +92,9 @@ def _get_attrs(client_manager, parsed_args):
return attrs
class CreateFloatingIP(common.NetworkAndComputeShowOne,
common.NeutronCommandWithExtraArgs):
class CreateFloatingIP(
common.NetworkAndComputeShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create floating IP")
def update_parser_common(self, parser):
@@ -103,7 +104,7 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne,
parser.add_argument(
'network',
metavar='<network>',
help=_("Network to allocate floating IP from (name or ID)")
help=_("Network to allocate floating IP from (name or ID)"),
)
return parser
@@ -112,72 +113,83 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne,
'--subnet',
metavar='<subnet>',
help=self.enhance_help_neutron(
_("Subnet on which you want to create the floating IP "
"(name or ID)"))
_(
"Subnet on which you want to create the floating IP "
"(name or ID)"
)
),
)
parser.add_argument(
'--port',
metavar='<port>',
help=self.enhance_help_neutron(
_("Port to be associated with the floating IP "
"(name or ID)"))
_("Port to be associated with the floating IP " "(name or ID)")
),
)
parser.add_argument(
'--floating-ip-address',
metavar='<ip-address>',
dest='floating_ip_address',
help=self.enhance_help_neutron(_("Floating IP address"))
help=self.enhance_help_neutron(_("Floating IP address")),
)
parser.add_argument(
'--fixed-ip-address',
metavar='<ip-address>',
dest='fixed_ip_address',
help=self.enhance_help_neutron(
_("Fixed IP address mapped to the floating IP"))
_("Fixed IP address mapped to the floating IP")
),
)
parser.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=self.enhance_help_neutron(
_("Attach QoS policy to the floating IP (name or ID)"))
_("Attach QoS policy to the floating IP (name or ID)")
),
)
parser.add_argument(
'--description',
metavar='<description>',
help=self.enhance_help_neutron(_('Set floating IP description'))
help=self.enhance_help_neutron(_('Set floating IP description')),
)
parser.add_argument(
'--project',
metavar='<project>',
help=self.enhance_help_neutron(_("Owner's project (name or ID)"))
help=self.enhance_help_neutron(_("Owner's project (name or ID)")),
)
parser.add_argument(
'--dns-domain',
metavar='<dns-domain>',
dest='dns_domain',
help=self.enhance_help_neutron(
_("Set DNS domain for this floating IP"))
_("Set DNS domain for this floating IP")
),
)
parser.add_argument(
'--dns-name',
metavar='<dns-name>',
dest='dns_name',
help=self.enhance_help_neutron(
_("Set DNS name for this floating IP"))
_("Set DNS name for this floating IP")
),
)
identity_common.add_project_domain_option_to_parser(
parser, enhance_help=self.enhance_help_neutron)
parser, enhance_help=self.enhance_help_neutron
)
_tag.add_tag_option_to_parser_for_create(
parser, _('floating IP'), enhance_help=self.enhance_help_neutron)
parser, _('floating IP'), enhance_help=self.enhance_help_neutron
)
return parser
def take_action_network(self, client, parsed_args):
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
with common.check_missing_extension_if_error(
self.app.client_manager.network, attrs):
self.app.client_manager.network, attrs
):
obj = client.create_ip(**attrs)
# tags cannot be set when created, so tags need to be set later.
@@ -206,7 +218,7 @@ class DeleteFloatingIP(common.NetworkAndComputeDelete):
'floating_ip',
metavar="<floating-ip>",
nargs="+",
help=_("Floating IP(s) to delete (IP address or ID)")
help=_("Floating IP(s) to delete (IP address or ID)"),
)
return parser
@@ -232,60 +244,79 @@ class ListFloatingIP(common.NetworkAndComputeLister):
'--network',
metavar='<network>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to "
"given network (name or ID)"))
_(
"List floating IP(s) according to "
"given network (name or ID)"
)
),
)
parser.add_argument(
'--port',
metavar='<port>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to given port (name or ID)"))
_("List floating IP(s) according to given port (name or ID)")
),
)
parser.add_argument(
'--fixed-ip-address',
metavar='<ip-address>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to given fixed IP address"))
_("List floating IP(s) according to given fixed IP address")
),
)
parser.add_argument(
'--floating-ip-address',
metavar='<ip-address>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to given floating IP "
"address"))
_(
"List floating IP(s) according to given floating IP "
"address"
)
),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=self.enhance_help_neutron(
_("List additional fields in output"))
_("List additional fields in output")
),
)
parser.add_argument(
'--status',
metavar='<status>',
choices=['ACTIVE', 'DOWN'],
help=self.enhance_help_neutron(
_("List floating IP(s) according to given status ('ACTIVE', "
"'DOWN')"))
_(
"List floating IP(s) according to given status ('ACTIVE', "
"'DOWN')"
)
),
)
parser.add_argument(
'--project',
metavar='<project>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to given project (name or "
"ID)"))
_(
"List floating IP(s) according to given project (name or "
"ID)"
)
),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--router',
metavar='<router>',
help=self.enhance_help_neutron(
_("List floating IP(s) according to given router (name or "
"ID)"))
_(
"List floating IP(s) according to given router (name or "
"ID)"
)
),
)
_tag.add_tag_filtering_option_to_parser(
parser, _('floating IP'), enhance_help=self.enhance_help_neutron)
parser, _('floating IP'), enhance_help=self.enhance_help_neutron
)
return parser
@@ -330,12 +361,14 @@ class ListFloatingIP(common.NetworkAndComputeLister):
query = {}
if parsed_args.network is not None:
network = network_client.find_network(parsed_args.network,
ignore_missing=False)
network = network_client.find_network(
parsed_args.network, ignore_missing=False
)
query['floating_network_id'] = network.id
if parsed_args.port is not None:
port = network_client.find_port(parsed_args.port,
ignore_missing=False)
port = network_client.find_port(
parsed_args.port, ignore_missing=False
)
query['port_id'] = port.id
if parsed_args.fixed_ip_address is not None:
query['fixed_ip_address'] = parsed_args.fixed_ip_address
@@ -351,19 +384,26 @@ class ListFloatingIP(common.NetworkAndComputeLister):
)
query['project_id'] = project.id
if parsed_args.router is not None:
router = network_client.find_router(parsed_args.router,
ignore_missing=False)
router = network_client.find_router(
parsed_args.router, ignore_missing=False
)
query['router_id'] = router.id
_tag.get_tag_filtering_args(parsed_args, query)
data = client.ips(**query)
return (headers,
(utils.get_item_properties(
s, columns,
return (
headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
) for s in data))
)
for s in data
),
)
def take_action_compute(self, client, parsed_args):
columns = (
@@ -383,11 +423,17 @@ class ListFloatingIP(common.NetworkAndComputeLister):
data = client.api.floating_ip_list()
return (headers,
(utils.get_dict_properties(
s, columns,
return (
headers,
(
utils.get_dict_properties(
s,
columns,
formatters={},
) for s in data))
)
for s in data
),
)
class SetFloatingIP(common.NeutronCommandWithExtraArgs):
@@ -398,33 +444,37 @@ class SetFloatingIP(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP to modify (IP address or ID)"))
help=_("Floating IP to modify (IP address or ID)"),
)
parser.add_argument(
'--port',
metavar='<port>',
help=_("Associate the floating IP with port (name or ID)")),
help=_("Associate the floating IP with port (name or ID)"),
),
parser.add_argument(
'--fixed-ip-address',
metavar='<ip-address>',
dest='fixed_ip_address',
help=_("Fixed IP of the port "
"(required only if port has multiple IPs)")
help=_(
"Fixed IP of the port "
"(required only if port has multiple IPs)"
),
)
parser.add_argument(
'--description',
metavar='<description>',
help=_('Set floating IP description')
help=_('Set floating IP description'),
)
qos_policy_group = parser.add_mutually_exclusive_group()
qos_policy_group.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=_("Attach QoS policy to the floating IP (name or ID)")
help=_("Attach QoS policy to the floating IP (name or ID)"),
)
qos_policy_group.add_argument(
'--no-qos-policy',
action='store_true',
help=_("Remove the QoS policy attached to the floating IP")
help=_("Remove the QoS policy attached to the floating IP"),
)
_tag.add_tag_option_to_parser_for_set(parser, _('floating IP'))
@@ -439,8 +489,7 @@ class SetFloatingIP(common.NeutronCommandWithExtraArgs):
ignore_missing=False,
)
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
attrs['port_id'] = port.id
if parsed_args.fixed_ip_address:
@@ -451,13 +500,15 @@ class SetFloatingIP(common.NeutronCommandWithExtraArgs):
if parsed_args.qos_policy:
attrs['qos_policy_id'] = client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False).id
parsed_args.qos_policy, ignore_missing=False
).id
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
attrs['qos_policy_id'] = None
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
if attrs:
client.update_ip(obj, **attrs)
@@ -473,7 +524,7 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne):
parser.add_argument(
'floating_ip',
metavar="<floating-ip>",
help=_("Floating IP to display (IP address or ID)")
help=_("Floating IP to display (IP address or ID)"),
)
return parser
@@ -501,18 +552,19 @@ class UnsetFloatingIP(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP to disassociate (IP address or ID)"))
help=_("Floating IP to disassociate (IP address or ID)"),
)
parser.add_argument(
'--port',
action='store_true',
default=False,
help=_("Disassociate any port associated with the floating IP")
help=_("Disassociate any port associated with the floating IP"),
)
parser.add_argument(
'--qos-policy',
action='store_true',
default=False,
help=_("Remove the QoS policy attached to the floating IP")
help=_("Remove the QoS policy attached to the floating IP"),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('floating IP'))
@@ -530,7 +582,8 @@ class UnsetFloatingIP(common.NeutronCommandWithExtraArgs):
if parsed_args.qos_policy:
attrs['qos_policy_id'] = None
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
if attrs:
client.update_ip(obj, **attrs)

View File

@@ -25,17 +25,23 @@ class ListFloatingIPPool(common.NetworkAndComputeLister):
_description = _("List pools of floating IP addresses")
def take_action_network(self, client, parsed_args):
msg = _("Floating ip pool operations are only available for "
"Compute v2 network.")
msg = _(
"Floating ip pool operations are only available for "
"Compute v2 network."
)
raise exceptions.CommandError(msg)
def take_action_compute(self, client, parsed_args):
columns = (
'Name',
)
columns = ('Name',)
data = client.api.floating_ip_pool_list()
return (columns,
(utils.get_dict_properties(
s, columns,
) for s in data))
return (
columns,
(
utils.get_dict_properties(
s,
columns,
)
for s in data
),
)

View File

@@ -31,8 +31,10 @@ def validate_ports_diff(ports):
ports_diff = ports[-1] - ports[0]
if ports_diff < 0:
msg = _("The last number in port range must be"
" greater or equal to the first")
msg = _(
"The last number in port range must be"
" greater or equal to the first"
)
raise exceptions.CommandError(msg)
return ports_diff
@@ -42,8 +44,10 @@ def validate_ports_match(internal_ports, external_ports):
external_ports_diff = validate_ports_diff(external_ports)
if internal_ports_diff != 0 and internal_ports_diff != external_ports_diff:
msg = _("The relation between internal and external ports does not "
"match the pattern 1:N and N:N")
msg = _(
"The relation between internal and external ports does not "
"match the pattern 1:N and N:N"
)
raise exceptions.CommandError(msg)
@@ -84,66 +88,80 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
class CreateFloatingIPPortForwarding(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateFloatingIPPortForwarding(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create floating IP port forwarding")
def get_parser(self, prog_name):
parser = super(CreateFloatingIPPortForwarding,
self).get_parser(prog_name)
parser = super(CreateFloatingIPPortForwarding, self).get_parser(
prog_name
)
parser.add_argument(
'--internal-ip-address',
required=True,
metavar='<internal-ip-address>',
help=_("The fixed IPv4 address of the network "
"port associated to the floating IP port forwarding")
help=_(
"The fixed IPv4 address of the network "
"port associated to the floating IP port forwarding"
),
)
parser.add_argument(
'--port',
metavar='<port>',
required=True,
help=_("The name or ID of the network port associated "
"to the floating IP port forwarding")
help=_(
"The name or ID of the network port associated "
"to the floating IP port forwarding"
),
)
parser.add_argument(
'--internal-protocol-port',
metavar='<port-number>',
required=True,
help=_("The protocol port number "
"of the network port fixed IPv4 address "
"associated to the floating IP port forwarding")
help=_(
"The protocol port number "
"of the network port fixed IPv4 address "
"associated to the floating IP port forwarding"
),
)
parser.add_argument(
'--external-protocol-port',
metavar='<port-number>',
required=True,
help=_("The protocol port number of "
"the port forwarding's floating IP address")
help=_(
"The protocol port number of "
"the port forwarding's floating IP address"
),
)
parser.add_argument(
'--protocol',
metavar='<protocol>',
required=True,
help=_("The protocol used in the floating IP "
"port forwarding, for instance: TCP, UDP")
help=_(
"The protocol used in the floating IP "
"port forwarding, for instance: TCP, UDP"
),
),
parser.add_argument(
'--description',
metavar='<description>',
help=_("A text to describe/contextualize the use of the "
"port forwarding configuration")
help=_(
"A text to describe/contextualize the use of the "
"port forwarding configuration"
),
)
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP that the port forwarding belongs to "
"(IP address or ID)")
help=_(
"Floating IP that the port forwarding belongs to "
"(IP address or ID)"
),
)
return parser
@@ -159,8 +177,7 @@ class CreateFloatingIPPortForwarding(command.ShowOne,
validate_and_assign_port_ranges(parsed_args, attrs)
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
attrs['internal_port_id'] = port.id
attrs['internal_ip_address'] = parsed_args.internal_ip_address
attrs['protocol'] = parsed_args.protocol
@@ -169,11 +186,11 @@ class CreateFloatingIPPortForwarding(command.ShowOne,
attrs['description'] = parsed_args.description
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_floating_ip_port_forwarding(
floating_ip.id,
**attrs
floating_ip.id, **attrs
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
@@ -184,19 +201,22 @@ class DeleteFloatingIPPortForwarding(command.Command):
_description = _("Delete floating IP port forwarding")
def get_parser(self, prog_name):
parser = super(DeleteFloatingIPPortForwarding,
self).get_parser(prog_name)
parser = super(DeleteFloatingIPPortForwarding, self).get_parser(
prog_name
)
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP that the port forwarding belongs to "
"(IP address or ID)")
help=_(
"Floating IP that the port forwarding belongs to "
"(IP address or ID)"
),
)
parser.add_argument(
'port_forwarding_id',
nargs="+",
metavar="<port-forwarding-id>",
help=_("The ID of the floating IP port forwarding(s) to delete")
help=_("The ID of the floating IP port forwarding(s) to delete"),
)
return parser
@@ -217,13 +237,18 @@ class DeleteFloatingIPPortForwarding(command.Command):
)
except Exception as e:
result += 1
LOG.error(_("Failed to delete floating IP port forwarding "
"'%(port_forwarding_id)s': %(e)s"),
{'port_forwarding_id': port_forwarding_id, 'e': e})
LOG.error(
_(
"Failed to delete floating IP port forwarding "
"'%(port_forwarding_id)s': %(e)s"
),
{'port_forwarding_id': port_forwarding_id, 'e': e},
)
if result > 0:
total = len(parsed_args.port_forwarding_id)
msg = (_("%(result)s of %(total)s Port forwarding failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s Port forwarding failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -231,31 +256,38 @@ class ListFloatingIPPortForwarding(command.Lister):
_description = _("List floating IP port forwarding")
def get_parser(self, prog_name):
parser = super(ListFloatingIPPortForwarding,
self).get_parser(prog_name)
parser = super(ListFloatingIPPortForwarding, self).get_parser(
prog_name
)
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP that the port forwarding belongs to "
"(IP address or ID)")
help=_(
"Floating IP that the port forwarding belongs to "
"(IP address or ID)"
),
)
parser.add_argument(
'--port',
metavar='<port>',
help=_("Filter the list result by the ID or name of "
"the internal network port")
help=_(
"Filter the list result by the ID or name of "
"the internal network port"
),
)
parser.add_argument(
'--external-protocol-port',
metavar='<port-number>',
dest='external_protocol_port',
help=_("Filter the list result by the "
"protocol port number of the floating IP")
help=_(
"Filter the list result by the "
"protocol port number of the floating IP"
),
)
parser.add_argument(
'--protocol',
metavar='protocol',
help=_("Filter the list result by the port protocol")
help=_("Filter the list result by the port protocol"),
)
return parser
@@ -289,8 +321,7 @@ class ListFloatingIPPortForwarding(command.Lister):
query = {}
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
query['internal_port_id'] = port.id
external_port = parsed_args.external_protocol_port
if external_port:
@@ -298,7 +329,8 @@ class ListFloatingIPPortForwarding(command.Lister):
query['external_port_range'] = external_port
else:
query['external_port'] = int(
parsed_args.external_protocol_port)
parsed_args.external_protocol_port
)
if parsed_args.protocol is not None:
query['protocol'] = parsed_args.protocol
@@ -309,66 +341,83 @@ class ListFloatingIPPortForwarding(command.Lister):
data = client.floating_ip_port_forwardings(obj, **query)
return (headers,
(utils.get_item_properties(
s, columns,
return (
headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
) for s in data))
)
for s in data
),
)
class SetFloatingIPPortForwarding(common.NeutronCommandWithExtraArgs):
_description = _("Set floating IP Port Forwarding Properties")
def get_parser(self, prog_name):
parser = super(SetFloatingIPPortForwarding,
self).get_parser(prog_name)
parser = super(SetFloatingIPPortForwarding, self).get_parser(prog_name)
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP that the port forwarding belongs to "
"(IP address or ID)")
help=_(
"Floating IP that the port forwarding belongs to "
"(IP address or ID)"
),
)
parser.add_argument(
'port_forwarding_id',
metavar='<port-forwarding-id>',
help=_("The ID of the floating IP port forwarding")
help=_("The ID of the floating IP port forwarding"),
)
parser.add_argument(
'--port',
metavar='<port>',
help=_("The ID of the network port associated to "
"the floating IP port forwarding")
help=_(
"The ID of the network port associated to "
"the floating IP port forwarding"
),
)
parser.add_argument(
'--internal-ip-address',
metavar='<internal-ip-address>',
help=_("The fixed IPv4 address of the network port "
"associated to the floating IP port forwarding")
help=_(
"The fixed IPv4 address of the network port "
"associated to the floating IP port forwarding"
),
)
parser.add_argument(
'--internal-protocol-port',
metavar='<port-number>',
help=_("The TCP/UDP/other protocol port number of the "
"network port fixed IPv4 address associated to "
"the floating IP port forwarding")
help=_(
"The TCP/UDP/other protocol port number of the "
"network port fixed IPv4 address associated to "
"the floating IP port forwarding"
),
)
parser.add_argument(
'--external-protocol-port',
metavar='<port-number>',
help=_("The TCP/UDP/other protocol port number of the "
"port forwarding's floating IP address")
help=_(
"The TCP/UDP/other protocol port number of the "
"port forwarding's floating IP address"
),
)
parser.add_argument(
'--protocol',
metavar='<protocol>',
choices=['tcp', 'udp'],
help=_("The IP protocol used in the floating IP port forwarding")
help=_("The IP protocol used in the floating IP port forwarding"),
),
parser.add_argument(
'--description',
metavar='<description>',
help=_("A text to describe/contextualize the use of "
"the port forwarding configuration")
help=_(
"A text to describe/contextualize the use of "
"the port forwarding configuration"
),
)
return parser
@@ -382,8 +431,7 @@ class SetFloatingIPPortForwarding(common.NeutronCommandWithExtraArgs):
attrs = {}
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
attrs['internal_port_id'] = port.id
if parsed_args.internal_ip_address:
@@ -398,28 +446,33 @@ class SetFloatingIPPortForwarding(common.NeutronCommandWithExtraArgs):
attrs['description'] = parsed_args.description
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_floating_ip_port_forwarding(
floating_ip.id, parsed_args.port_forwarding_id, **attrs)
floating_ip.id, parsed_args.port_forwarding_id, **attrs
)
class ShowFloatingIPPortForwarding(command.ShowOne):
_description = _("Display floating IP Port Forwarding details")
def get_parser(self, prog_name):
parser = super(ShowFloatingIPPortForwarding,
self).get_parser(prog_name)
parser = super(ShowFloatingIPPortForwarding, self).get_parser(
prog_name
)
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
help=_("Floating IP that the port forwarding belongs to "
"(IP address or ID)")
help=_(
"Floating IP that the port forwarding belongs to "
"(IP address or ID)"
),
)
parser.add_argument(
'port_forwarding_id',
metavar="<port-forwarding-id>",
help=_("The ID of the floating IP port forwarding")
help=_("The ID of the floating IP port forwarding"),
)
return parser

View File

@@ -29,9 +29,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['id', 'name', 'location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -49,8 +47,10 @@ class ListIPAvailability(command.Lister):
choices=[4, 6],
metavar='<ip-version>',
dest='ip_version',
help=_("List IP availability of given IP version "
"networks (default is 4)"),
help=_(
"List IP availability of given IP version "
"networks (default is 4)"
),
)
parser.add_argument(
'--project',
@@ -89,10 +89,16 @@ class ListIPAvailability(command.Lister):
).id
filters['project_id'] = project_id
data = client.network_ip_availabilities(**filters)
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
class ShowIPAvailability(command.ShowOne):
@@ -109,10 +115,12 @@ class ShowIPAvailability(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
network_id = client.find_network(parsed_args.network,
ignore_missing=False).id
obj = client.find_network_ip_availability(network_id,
ignore_missing=False)
network_id = client.find_network(
parsed_args.network, ignore_missing=False
).id
obj = client.find_network_ip_availability(
network_id, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (display_columns, data)

View File

@@ -28,9 +28,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -55,27 +53,29 @@ class CreateConntrackHelper(command.ShowOne):
parser.add_argument(
'router',
metavar='<router>',
help=_('Router for which conntrack helper will be created')
help=_('Router for which conntrack helper will be created'),
)
parser.add_argument(
'--helper',
required=True,
metavar='<helper>',
help=_('The netfilter conntrack helper module')
help=_('The netfilter conntrack helper module'),
)
parser.add_argument(
'--protocol',
required=True,
metavar='<protocol>',
help=_('The network protocol for the netfilter conntrack target '
'rule')
help=_(
'The network protocol for the netfilter conntrack target '
'rule'
),
)
parser.add_argument(
'--port',
required=True,
metavar='<port>',
type=int,
help=_('The network port for the netfilter conntrack target rule')
help=_('The network port for the netfilter conntrack target rule'),
)
return parser
@@ -99,13 +99,13 @@ class DeleteConntrackHelper(command.Command):
parser.add_argument(
'router',
metavar='<router>',
help=_('Router that the conntrack helper belong to')
help=_('Router that the conntrack helper belong to'),
)
parser.add_argument(
'conntrack_helper_id',
metavar='<conntrack-helper-id>',
nargs='+',
help=_('The ID of the conntrack helper(s) to delete')
help=_('The ID of the conntrack helper(s) to delete'),
)
return parser
@@ -118,17 +118,24 @@ class DeleteConntrackHelper(command.Command):
for ct_helper in parsed_args.conntrack_helper_id:
try:
client.delete_conntrack_helper(
ct_helper, router.id, ignore_missing=False)
ct_helper, router.id, ignore_missing=False
)
except Exception as e:
result += 1
LOG.error(_("Failed to delete L3 conntrack helper with "
"ID '%(ct_helper)s': %(e)s"),
{'ct_helper': ct_helper, 'e': e})
LOG.error(
_(
"Failed to delete L3 conntrack helper with "
"ID '%(ct_helper)s': %(e)s"
),
{'ct_helper': ct_helper, 'e': e},
)
if result > 0:
total = len(parsed_args.conntrack_helper_id)
msg = (_("%(result)s of %(total)s L3 conntrack helpers failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s L3 conntrack helpers failed "
"to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -140,23 +147,25 @@ class ListConntrackHelper(command.Lister):
parser.add_argument(
'router',
metavar='<router>',
help=_('Router that the conntrack helper belong to')
help=_('Router that the conntrack helper belong to'),
)
parser.add_argument(
'--helper',
metavar='<helper>',
help=_('The netfilter conntrack helper module')
help=_('The netfilter conntrack helper module'),
)
parser.add_argument(
'--protocol',
metavar='<protocol>',
help=_('The network protocol for the netfilter conntrack target '
'rule')
help=_(
'The network protocol for the netfilter conntrack target '
'rule'
),
)
parser.add_argument(
'--port',
metavar='<port>',
help=_('The network port for the netfilter conntrack target rule')
help=_('The network port for the netfilter conntrack target rule'),
)
return parser
@@ -180,10 +189,17 @@ class ListConntrackHelper(command.Lister):
attrs = _get_attrs(client, parsed_args)
data = client.conntrack_helpers(attrs.pop('router_id'), **attrs)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters={},
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
class SetConntrackHelper(command.Command):
@@ -194,29 +210,31 @@ class SetConntrackHelper(command.Command):
parser.add_argument(
'router',
metavar='<router>',
help=_('Router that the conntrack helper belong to')
help=_('Router that the conntrack helper belong to'),
)
parser.add_argument(
'conntrack_helper_id',
metavar='<conntrack-helper-id>',
help=_('The ID of the conntrack helper(s)')
help=_('The ID of the conntrack helper(s)'),
)
parser.add_argument(
'--helper',
metavar='<helper>',
help=_('The netfilter conntrack helper module')
help=_('The netfilter conntrack helper module'),
)
parser.add_argument(
'--protocol',
metavar='<protocol>',
help=_('The network protocol for the netfilter conntrack target '
'rule')
help=_(
'The network protocol for the netfilter conntrack target '
'rule'
),
)
parser.add_argument(
'--port',
metavar='<port>',
type=int,
help=_('The network port for the netfilter conntrack target rule')
help=_('The network port for the netfilter conntrack target rule'),
)
return parser
@@ -225,8 +243,10 @@ class SetConntrackHelper(command.Command):
attrs = _get_attrs(client, parsed_args)
if attrs:
client.update_conntrack_helper(
parsed_args.conntrack_helper_id, attrs.pop('router_id'),
**attrs)
parsed_args.conntrack_helper_id,
attrs.pop('router_id'),
**attrs
)
class ShowConntrackHelper(command.ShowOne):
@@ -237,12 +257,12 @@ class ShowConntrackHelper(command.ShowOne):
parser.add_argument(
'router',
metavar='<router>',
help=_('Router that the conntrack helper belong to')
help=_('Router that the conntrack helper belong to'),
)
parser.add_argument(
'conntrack_helper_id',
metavar='<conntrack-helper-id>',
help=_('The ID of the conntrack helper')
help=_('The ID of the conntrack helper'),
)
return parser
@@ -251,7 +271,8 @@ class ShowConntrackHelper(command.ShowOne):
client = self.app.client_manager.network
router = client.find_router(parsed_args.router, ignore_missing=False)
obj = client.get_conntrack_helper(
parsed_args.conntrack_helper_id, router.id)
parsed_args.conntrack_helper_id, router.id
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})

View File

@@ -31,7 +31,8 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden_columns)
item, column_map, hidden_columns
)
def _get_attrs(client_manager, parsed_args):
@@ -51,14 +52,16 @@ def _get_attrs(client_manager, parsed_args):
).id
attrs['project_id'] = project_id
if parsed_args.network:
network = network_client.find_network(parsed_args.network,
ignore_missing=False)
network = network_client.find_network(
parsed_args.network, ignore_missing=False
)
attrs['network_id'] = network.id
if parsed_args.local_ip_address:
attrs['local_ip_address'] = parsed_args.local_ip_address
if parsed_args.local_port:
port = network_client.find_port(parsed_args.local_port,
ignore_missing=False)
port = network_client.find_port(
parsed_args.local_port, ignore_missing=False
)
attrs['local_port_id'] = port.id
if parsed_args.ip_mode:
attrs['ip_mode'] = parsed_args.ip_mode
@@ -71,24 +74,22 @@ class CreateLocalIP(command.ShowOne):
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
'--name',
metavar="<name>",
help=_("New local IP name")
'--name', metavar="<name>", help=_("New local IP name")
)
parser.add_argument(
'--description',
metavar="<description>",
help=_("New local IP description")
help=_("New local IP description"),
)
parser.add_argument(
'--network',
metavar='<network>',
help=_("Network to allocate Local IP (name or ID)")
help=_("Network to allocate Local IP (name or ID)"),
)
parser.add_argument(
'--local-port',
metavar='<local-port>',
help=_("Port to allocate Local IP (name or ID)")
help=_("Port to allocate Local IP (name or ID)"),
)
parser.add_argument(
"--local-ip-address",
@@ -96,9 +97,7 @@ class CreateLocalIP(command.ShowOne):
help=_("IP address or CIDR "),
)
parser.add_argument(
'--ip-mode',
metavar='<ip-mode>',
help=_("local IP ip mode")
'--ip-mode', metavar='<ip-mode>', help=_("local IP ip mode")
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -125,7 +124,7 @@ class DeleteLocalIP(command.Command):
'local_ip',
metavar="<local-ip>",
nargs='+',
help=_("Local IP(s) to delete (name or ID)")
help=_("Local IP(s) to delete (name or ID)"),
)
return parser
@@ -140,14 +139,19 @@ class DeleteLocalIP(command.Command):
client.delete_local_ip(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete Local IP with "
"name or ID '%(lip)s': %(e)s"),
{'lip': lip, 'e': e})
LOG.error(
_(
"Failed to delete Local IP with "
"name or ID '%(lip)s': %(e)s"
),
{'lip': lip, 'e': e},
)
if result > 0:
total = len(parsed_args.local_ip)
msg = (_("%(result)s of %(total)s local IPs failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s local IPs failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -159,25 +163,21 @@ class SetLocalIP(command.Command):
parser.add_argument(
'local_ip',
metavar="<local-ip>",
help=_("Local IP to modify (name or ID)")
help=_("Local IP to modify (name or ID)"),
)
parser.add_argument(
'--name',
metavar="<name>",
help=_('Set local IP name')
'--name', metavar="<name>", help=_('Set local IP name')
)
parser.add_argument(
'--description',
metavar="<description>",
help=_('Set local IP description')
help=_('Set local IP description'),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_local_ip(
parsed_args.local_ip,
ignore_missing=False)
obj = client.find_local_ip(parsed_args.local_ip, ignore_missing=False)
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
@@ -196,37 +196,36 @@ class ListLocalIP(command.Lister):
parser.add_argument(
'--name',
metavar='<name>',
help=_("List only local IPs of given name in output")
help=_("List only local IPs of given name in output"),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("List Local IPs according to their project "
"(name or ID)")
help=_(
"List Local IPs according to their project " "(name or ID)"
),
)
parser.add_argument(
'--network',
metavar='<network>',
help=_("List Local IP(s) according to "
"given network (name or ID)")
help=_(
"List Local IP(s) according to " "given network (name or ID)"
),
)
parser.add_argument(
'--local-port',
metavar='<local-port>',
help=_("List Local IP(s) according to "
"given port (name or ID)")
help=_("List Local IP(s) according to " "given port (name or ID)"),
)
parser.add_argument(
'--local-ip-address',
metavar='<local-ip-address>',
help=_("List Local IP(s) according to "
"given Local IP Address")
help=_("List Local IP(s) according to " "given Local IP Address"),
)
parser.add_argument(
'--ip-mode',
metavar='<ip_mode>',
help=_("List Local IP(s) according to "
"given IP mode")
help=_("List Local IP(s) according to " "given IP mode"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -267,12 +266,14 @@ class ListLocalIP(command.Lister):
).id
attrs['project_id'] = project_id
if parsed_args.network is not None:
network = client.find_network(parsed_args.network,
ignore_missing=False)
network = client.find_network(
parsed_args.network, ignore_missing=False
)
attrs['network_id'] = network.id
if parsed_args.local_port:
port = client.find_port(parsed_args.local_port,
ignore_missing=False)
port = client.find_port(
parsed_args.local_port, ignore_missing=False
)
attrs['local_port_id'] = port.id
if parsed_args.local_ip_address:
attrs['local_ip_address'] = parsed_args.local_ip_address
@@ -280,10 +281,17 @@ class ListLocalIP(command.Lister):
attrs['ip_mode'] = parsed_args.ip_mode
data = client.local_ips(**attrs)
return (column_headers,
(utils.get_item_properties(s,
columns,
formatters={},) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
class ShowLocalIP(command.ShowOne):
@@ -294,16 +302,14 @@ class ShowLocalIP(command.ShowOne):
parser.add_argument(
'local_ip',
metavar="<local-ip>",
help=_("Local IP to display (name or ID)")
help=_("Local IP to display (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_local_ip(
parsed_args.local_ip,
ignore_missing=False)
obj = client.find_local_ip(parsed_args.local_ip, ignore_missing=False)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})

View File

@@ -31,7 +31,8 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'name', 'id', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden_columns)
item, column_map, hidden_columns
)
class CreateLocalIPAssociation(command.ShowOne):
@@ -42,18 +43,19 @@ class CreateLocalIPAssociation(command.ShowOne):
parser.add_argument(
'local_ip',
metavar='<local-ip>',
help=_("Local IP that the port association belongs to "
"(Name or ID)")
help=_(
"Local IP that the port association belongs to " "(Name or ID)"
),
)
parser.add_argument(
'fixed_port',
metavar='<fixed-port>',
help=_("The ID or Name of Port to allocate Local IP Association")
help=_("The ID or Name of Port to allocate Local IP Association"),
)
parser.add_argument(
'--fixed-ip',
metavar='<fixed-ip>',
help=_("Fixed IP for Local IP Association")
help=_("Fixed IP for Local IP Association"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -64,8 +66,7 @@ class CreateLocalIPAssociation(command.ShowOne):
client = self.app.client_manager.network
attrs = {}
port = client.find_port(parsed_args.fixed_port,
ignore_missing=False)
port = client.find_port(parsed_args.fixed_port, ignore_missing=False)
attrs['fixed_port_id'] = port.id
if parsed_args.fixed_ip:
attrs['fixed_ip'] = parsed_args.fixed_ip
@@ -88,14 +89,15 @@ class DeleteLocalIPAssociation(command.Command):
parser.add_argument(
'local_ip',
metavar="<local-ip>",
help=_("Local IP that the port association belongs to "
"(Name or ID)")
help=_(
"Local IP that the port association belongs to " "(Name or ID)"
),
)
parser.add_argument(
'fixed_port_id',
nargs="+",
metavar="<fixed-port-id>",
help=_("The fixed port ID of Local IP Association")
help=_("The fixed port ID of Local IP Association"),
)
return parser
@@ -116,15 +118,21 @@ class DeleteLocalIPAssociation(command.Command):
)
except Exception as e:
result += 1
LOG.error(_("Failed to delete Local IP Association with "
"fixed port "
"name or ID '%(fixed_port_id)s': %(e)s"),
{'fixed port ID': fixed_port_id, 'e': e})
LOG.error(
_(
"Failed to delete Local IP Association with "
"fixed port "
"name or ID '%(fixed_port_id)s': %(e)s"
),
{'fixed port ID': fixed_port_id, 'e': e},
)
if result > 0:
total = len(parsed_args.fixed_port_id)
msg = (_("%(result)s of %(total)s Local IP Associations failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s Local IP Associations failed "
"to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -137,23 +145,24 @@ class ListLocalIPAssociation(command.Lister):
parser.add_argument(
'local_ip',
metavar='<local-ip>',
help=_("Local IP that port associations belongs to")
help=_("Local IP that port associations belongs to"),
)
parser.add_argument(
'--fixed-port',
metavar='<fixed-port>',
help=_("Filter the list result by the ID or name of "
"the fixed port")
help=_(
"Filter the list result by the ID or name of " "the fixed port"
),
)
parser.add_argument(
'--fixed-ip',
metavar='<fixed-ip>',
help=_("Filter the list result by fixed ip")
help=_("Filter the list result by fixed ip"),
)
parser.add_argument(
'--host',
metavar='<host>',
help=_("Filter the list result by given host")
help=_("Filter the list result by given host"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -173,7 +182,7 @@ class ListLocalIPAssociation(command.Lister):
'Local IP Address',
'Fixed port ID',
'Fixed IP',
'Host'
'Host',
)
attrs = {}
obj = client.find_local_ip(
@@ -181,8 +190,9 @@ class ListLocalIPAssociation(command.Lister):
ignore_missing=False,
)
if parsed_args.fixed_port:
port = client.find_port(parsed_args.fixed_port,
ignore_missing=False)
port = client.find_port(
parsed_args.fixed_port, ignore_missing=False
)
attrs['fixed_port_id'] = port.id
if parsed_args.fixed_ip:
attrs['fixed_ip'] = parsed_args.fixed_ip
@@ -191,7 +201,10 @@ class ListLocalIPAssociation(command.Lister):
data = client.local_ip_associations(obj, **attrs)
return (column_headers,
(utils.get_item_properties(s,
columns,
formatters={}) for s in data))
return (
column_headers,
(
utils.get_item_properties(s, columns, formatters={})
for s in data
),
)

View File

@@ -31,7 +31,8 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location']
return utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden_columns)
item, column_map, hidden_columns
)
class CreateNDPProxy(command.ShowOne):
@@ -40,31 +41,36 @@ class CreateNDPProxy(command.ShowOne):
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument(
'router',
metavar='<router>',
help=_("The name or ID of a router"))
'router', metavar='<router>', help=_("The name or ID of a router")
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("New NDP proxy name")
'--name', metavar='<name>', help=_("New NDP proxy name")
)
parser.add_argument(
'--port',
metavar='<port>',
required=True,
help=_("The name or ID of the network port associated "
"to the NDP proxy"))
help=_(
"The name or ID of the network port associated "
"to the NDP proxy"
),
)
parser.add_argument(
'--ip-address',
metavar='<ip-address>',
help=_("The IPv6 address that is to be proxied. In case the port "
"has multiple addresses assigned, use this option to "
"select which address is to be used."))
help=_(
"The IPv6 address that is to be proxied. In case the port "
"has multiple addresses assigned, use this option to "
"select which address is to be used."
),
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("A text to describe/contextualize the use of the "
"NDP proxy configuration")
help=_(
"A text to describe/contextualize the use of the "
"NDP proxy configuration"
),
)
return parser
@@ -81,8 +87,7 @@ class CreateNDPProxy(command.ShowOne):
if parsed_args.ip_address:
attrs['ip_address'] = parsed_args.ip_address
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
attrs['port_id'] = port.id
if parsed_args.description is not None:
@@ -103,7 +108,7 @@ class DeleteNDPProxy(command.Command):
'ndp_proxy',
nargs="+",
metavar="<ndp-proxy>",
help=_("NDP proxy(s) to delete (name or ID)")
help=_("NDP proxy(s) to delete (name or ID)"),
)
return parser
@@ -117,13 +122,15 @@ class DeleteNDPProxy(command.Command):
client.delete_ndp_proxy(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete NDP proxy "
"'%(ndp_proxy)s': %(e)s"),
{'ndp_proxy': ndp_proxy, 'e': e})
LOG.error(
_("Failed to delete NDP proxy " "'%(ndp_proxy)s': %(e)s"),
{'ndp_proxy': ndp_proxy, 'e': e},
)
if result > 0:
total = len(parsed_args.ndp_proxy)
msg = (_("%(result)s of %(total)s NDP Proxy failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s NDP Proxy failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -135,27 +142,27 @@ class ListNDPProxy(command.Lister):
parser.add_argument(
'--router',
metavar='<router>',
help=_("List only NDP proxies belong to this router (name or ID)")
help=_("List only NDP proxies belong to this router (name or ID)"),
)
parser.add_argument(
'--port',
metavar='<port>',
help=_("List only NDP proxies assocate to this port (name or ID)")
help=_("List only NDP proxies assocate to this port (name or ID)"),
)
parser.add_argument(
'--ip-address',
metavar='ip-address',
help=_("List only NDP proxies according to their IPv6 address")
help=_("List only NDP proxies according to their IPv6 address"),
)
parser.add_argument(
'--project',
metavar='<project>',
help=_("List NDP proxies according to their project (name or ID)")
help=_("List NDP proxies according to their project (name or ID)"),
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("List NDP proxies according to their name")
help=_("List NDP proxies according to their name"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -184,12 +191,12 @@ class ListNDPProxy(command.Lister):
query = {}
if parsed_args.router:
router = client.find_router(parsed_args.router,
ignore_missing=False)
router = client.find_router(
parsed_args.router, ignore_missing=False
)
query['router_id'] = router.id
if parsed_args.port:
port = client.find_port(parsed_args.port,
ignore_missing=False)
port = client.find_port(parsed_args.port, ignore_missing=False)
query['port_id'] = port.id
if parsed_args.ip_address is not None:
query['ip_address'] = parsed_args.ip_address
@@ -205,11 +212,17 @@ class ListNDPProxy(command.Lister):
data = client.ndp_proxies(**query)
return (headers,
(utils.get_item_properties(
s, columns,
return (
headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
) for s in data))
)
for s in data
),
)
class SetNDPProxy(command.Command):
@@ -220,18 +233,18 @@ class SetNDPProxy(command.Command):
parser.add_argument(
'ndp_proxy',
metavar='<ndp-proxy>',
help=_("The ID or name of the NDP proxy to update")
help=_("The ID or name of the NDP proxy to update"),
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("Set NDP proxy name")
'--name', metavar='<name>', help=_("Set NDP proxy name")
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("A text to describe/contextualize the use of "
"the NDP proxy configuration")
help=_(
"A text to describe/contextualize the use of "
"the NDP proxy configuration"
),
)
return parser
@@ -244,7 +257,8 @@ class SetNDPProxy(command.Command):
attrs['name'] = parsed_args.name
obj = client.find_ndp_proxy(
parsed_args.ndp_proxy, ignore_missing=False)
parsed_args.ndp_proxy, ignore_missing=False
)
client.update_ndp_proxy(obj, **attrs)
@@ -256,14 +270,15 @@ class ShowNDPProxy(command.ShowOne):
parser.add_argument(
'ndp_proxy',
metavar="<ndp-proxy>",
help=_("The ID or name of the NDP proxy")
help=_("The ID or name of the NDP proxy"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_ndp_proxy(parsed_args.ndp_proxy,
ignore_missing=False)
obj = client.find_ndp_proxy(
parsed_args.ndp_proxy, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return (display_columns, data)

View File

@@ -63,9 +63,7 @@ def _get_columns_network(item):
hidden_columns = ['location', 'tenant_id']
hidden_columns = ['location']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -102,8 +100,10 @@ def _get_attrs_network(client_manager, parsed_args):
attrs['project_id'] = project_id
# "network set" command doesn't support setting availability zone hints.
if 'availability_zone_hints' in parsed_args and \
parsed_args.availability_zone_hints is not None:
if (
'availability_zone_hints' in parsed_args
and parsed_args.availability_zone_hints is not None
):
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
# set description
@@ -132,8 +132,9 @@ def _get_attrs_network(client_manager, parsed_args):
attrs['provider:segmentation_id'] = parsed_args.segmentation_id
if parsed_args.qos_policy is not None:
network_client = client_manager.network
_qos_policy = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
_qos_policy = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
attrs['qos_policy_id'] = _qos_policy.id
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
attrs['qos_policy_id'] = None
@@ -162,53 +163,63 @@ def _add_additional_network_options(parser):
parser.add_argument(
'--provider-network-type',
metavar='<provider-network-type>',
help=_("The physical mechanism by which the virtual network "
"is implemented. For example: "
"flat, geneve, gre, local, vlan, vxlan."))
help=_(
"The physical mechanism by which the virtual network "
"is implemented. For example: "
"flat, geneve, gre, local, vlan, vxlan."
),
)
parser.add_argument(
'--provider-physical-network',
metavar='<provider-physical-network>',
dest='physical_network',
help=_("Name of the physical network over which the virtual "
"network is implemented"))
help=_(
"Name of the physical network over which the virtual "
"network is implemented"
),
)
parser.add_argument(
'--provider-segment',
metavar='<provider-segment>',
dest='segmentation_id',
help=_("VLAN ID for VLAN networks or Tunnel ID for "
"GENEVE/GRE/VXLAN networks"))
help=_(
"VLAN ID for VLAN networks or Tunnel ID for "
"GENEVE/GRE/VXLAN networks"
),
)
parser.add_argument(
'--dns-domain',
metavar='<dns-domain>',
dest='dns_domain',
help=_("Set DNS domain for this network "
"(requires DNS integration extension)")
help=_(
"Set DNS domain for this network "
"(requires DNS integration extension)"
),
)
# TODO(sindhu): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class CreateNetwork(common.NetworkAndComputeShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetwork(
common.NetworkAndComputeShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create new network")
def update_parser_common(self, parser):
parser.add_argument(
'name',
metavar='<name>',
help=_("New network name")
'name', metavar='<name>', help=_("New network name")
)
share_group = parser.add_mutually_exclusive_group()
share_group.add_argument(
'--share',
action='store_true',
default=None,
help=_("Share the network between projects")
help=_("Share the network between projects"),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_("Do not share the network between projects")
help=_("Do not share the network between projects"),
)
return parser
@@ -218,27 +229,27 @@ class CreateNetwork(common.NetworkAndComputeShowOne,
'--enable',
action='store_true',
default=True,
help=self.enhance_help_neutron(_("Enable network (default)"))
help=self.enhance_help_neutron(_("Enable network (default)")),
)
admin_group.add_argument(
'--disable',
action='store_true',
help=self.enhance_help_neutron(_("Disable network"))
help=self.enhance_help_neutron(_("Disable network")),
)
parser.add_argument(
'--project',
metavar='<project>',
help=self.enhance_help_neutron(_("Owner's project (name or ID)"))
help=self.enhance_help_neutron(_("Owner's project (name or ID)")),
)
parser.add_argument(
'--description',
metavar='<description>',
help=self.enhance_help_neutron(_("Set network description"))
help=self.enhance_help_neutron(_("Set network description")),
)
parser.add_argument(
'--mtu',
metavar='<mtu>',
help=self.enhance_help_neutron(_("Set network mtu"))
help=self.enhance_help_neutron(_("Set network mtu")),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
@@ -247,77 +258,102 @@ class CreateNetwork(common.NetworkAndComputeShowOne,
dest='availability_zone_hints',
metavar='<availability-zone>',
help=self.enhance_help_neutron(
_("Availability Zone in which to create this network "
"(Network Availability Zone extension required, "
"repeat option to set multiple availability zones)"))
_(
"Availability Zone in which to create this network "
"(Network Availability Zone extension required, "
"repeat option to set multiple availability zones)"
)
),
)
port_security_group = parser.add_mutually_exclusive_group()
port_security_group.add_argument(
'--enable-port-security',
action='store_true',
help=self.enhance_help_neutron(
_("Enable port security by default for ports created on "
"this network (default)"))
_(
"Enable port security by default for ports created on "
"this network (default)"
)
),
)
port_security_group.add_argument(
'--disable-port-security',
action='store_true',
help=self.enhance_help_neutron(
_("Disable port security by default for ports created on "
"this network"))
_(
"Disable port security by default for ports created on "
"this network"
)
),
)
external_router_grp = parser.add_mutually_exclusive_group()
external_router_grp.add_argument(
'--external',
action='store_true',
help=self.enhance_help_neutron(
_("The network has an external routing facility that's not "
"managed by Neutron and can be used as in: "
"openstack router set --external-gateway NETWORK "
"(external-net extension required)"))
_(
"The network has an external routing facility that's not "
"managed by Neutron and can be used as in: "
"openstack router set --external-gateway NETWORK "
"(external-net extension required)"
)
),
)
external_router_grp.add_argument(
'--internal',
action='store_true',
help=self.enhance_help_neutron(
_("Opposite of '--external' (default)"))
_("Opposite of '--external' (default)")
),
)
default_router_grp = parser.add_mutually_exclusive_group()
default_router_grp.add_argument(
'--default',
action='store_true',
help=self.enhance_help_neutron(
_("Specify if this network should be used as the default "
"external network"))
_(
"Specify if this network should be used as the default "
"external network"
)
),
)
default_router_grp.add_argument(
'--no-default',
action='store_true',
help=self.enhance_help_neutron(
_("Do not use the network as the default external network "
"(default)"))
_(
"Do not use the network as the default external network "
"(default)"
)
),
)
parser.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=self.enhance_help_neutron(
_("QoS policy to attach to this network (name or ID)"))
_("QoS policy to attach to this network (name or ID)")
),
)
vlan_transparent_grp = parser.add_mutually_exclusive_group()
vlan_transparent_grp.add_argument(
'--transparent-vlan',
action='store_true',
help=self.enhance_help_neutron(
_("Make the network VLAN transparent")))
_("Make the network VLAN transparent")
),
)
vlan_transparent_grp.add_argument(
'--no-transparent-vlan',
action='store_true',
help=self.enhance_help_neutron(
_("Do not make the network VLAN transparent")))
_("Do not make the network VLAN transparent")
),
)
_add_additional_network_options(parser)
_tag.add_tag_option_to_parser_for_create(
parser, _('network'), enhance_help=self.enhance_help_neutron)
parser, _('network'), enhance_help=self.enhance_help_neutron
)
return parser
def update_parser_compute(self, parser):
@@ -326,7 +362,8 @@ class CreateNetwork(common.NetworkAndComputeShowOne,
metavar='<subnet>',
required=True,
help=self.enhance_help_nova_network(
_("IPv4 subnet for fixed IPs (in CIDR notation)"))
_("IPv4 subnet for fixed IPs (in CIDR notation)")
),
)
return parser
@@ -337,9 +374,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne,
if parsed_args.no_transparent_vlan:
attrs['vlan_transparent'] = False
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
with common.check_missing_extension_if_error(
self.app.client_manager.network, attrs):
self.app.client_manager.network, attrs
):
obj = client.create_network(**attrs)
# tags cannot be set when created, so tags need to be set later.
@@ -368,7 +407,7 @@ class DeleteNetwork(common.NetworkAndComputeDelete):
'network',
metavar="<network>",
nargs="+",
help=_("Network(s) to delete (name or ID)")
help=_("Network(s) to delete (name or ID)"),
)
return parser
@@ -391,98 +430,114 @@ class ListNetwork(common.NetworkAndComputeLister):
router_ext_group.add_argument(
'--external',
action='store_true',
help=self.enhance_help_neutron(_("List external networks"))
help=self.enhance_help_neutron(_("List external networks")),
)
router_ext_group.add_argument(
'--internal',
action='store_true',
help=self.enhance_help_neutron(_("List internal networks"))
help=self.enhance_help_neutron(_("List internal networks")),
)
parser.add_argument(
'--long',
action='store_true',
help=self.enhance_help_neutron(
_("List additional fields in output"))
_("List additional fields in output")
),
)
parser.add_argument(
'--name',
metavar='<name>',
help=self.enhance_help_neutron(
_("List networks according to their name"))
_("List networks according to their name")
),
)
admin_state_group = parser.add_mutually_exclusive_group()
admin_state_group.add_argument(
'--enable',
action='store_true',
help=self.enhance_help_neutron(_("List enabled networks"))
help=self.enhance_help_neutron(_("List enabled networks")),
)
admin_state_group.add_argument(
'--disable',
action='store_true',
help=self.enhance_help_neutron(_("List disabled networks"))
help=self.enhance_help_neutron(_("List disabled networks")),
)
parser.add_argument(
'--project',
metavar='<project>',
help=_("List networks according to their project (name or ID)")
help=_("List networks according to their project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(
parser, enhance_help=self.enhance_help_neutron)
parser, enhance_help=self.enhance_help_neutron
)
shared_group = parser.add_mutually_exclusive_group()
shared_group.add_argument(
'--share',
action='store_true',
help=self.enhance_help_neutron(
_("List networks shared between projects"))
_("List networks shared between projects")
),
)
shared_group.add_argument(
'--no-share',
action='store_true',
help=self.enhance_help_neutron(
_("List networks not shared between projects"))
_("List networks not shared between projects")
),
)
parser.add_argument(
'--status',
metavar='<status>',
choices=['ACTIVE', 'BUILD', 'DOWN', 'ERROR'],
help=self.enhance_help_neutron(
_("List networks according to their status "
"('ACTIVE', 'BUILD', 'DOWN', 'ERROR')"))
_(
"List networks according to their status "
"('ACTIVE', 'BUILD', 'DOWN', 'ERROR')"
)
),
)
parser.add_argument(
'--provider-network-type',
metavar='<provider-network-type>',
choices=['flat', 'geneve', 'gre', 'local',
'vlan', 'vxlan'],
choices=['flat', 'geneve', 'gre', 'local', 'vlan', 'vxlan'],
help=self.enhance_help_neutron(
_("List networks according to their physical mechanisms. The "
"supported options are: flat, geneve, gre, local, vlan, "
"vxlan."))
_(
"List networks according to their physical mechanisms. "
"The supported options are: flat, geneve, gre, local, "
"vlan, vxlan."
)
),
)
parser.add_argument(
'--provider-physical-network',
metavar='<provider-physical-network>',
dest='physical_network',
help=self.enhance_help_neutron(
_("List networks according to name of the physical network"))
_("List networks according to name of the physical network")
),
)
parser.add_argument(
'--provider-segment',
metavar='<provider-segment>',
dest='segmentation_id',
help=self.enhance_help_neutron(
_("List networks according to VLAN ID for VLAN networks or "
"Tunnel ID for GENEVE/GRE/VXLAN networks"))
_(
"List networks according to VLAN ID for VLAN networks or "
"Tunnel ID for GENEVE/GRE/VXLAN networks"
)
),
)
parser.add_argument(
'--agent',
metavar='<agent-id>',
dest='agent_id',
help=self.enhance_help_neutron(
_('List networks hosted by agent (ID only)'))
_('List networks hosted by agent (ID only)')
),
)
_tag.add_tag_filtering_option_to_parser(
parser, _('networks'), enhance_help=self.enhance_help_neutron)
parser, _('networks'), enhance_help=self.enhance_help_neutron
)
return parser
def take_action_network(self, client, parsed_args):
@@ -515,11 +570,7 @@ class ListNetwork(common.NetworkAndComputeLister):
'Tags',
)
elif parsed_args.agent_id:
columns = (
'id',
'name',
'subnet_ids'
)
columns = ('id', 'name', 'subnet_ids')
column_headers = (
'ID',
'Name',
@@ -529,17 +580,19 @@ class ListNetwork(common.NetworkAndComputeLister):
dhcp_agent = client.get_agent(parsed_args.agent_id)
data = client.dhcp_agent_hosting_networks(dhcp_agent)
return (column_headers,
(utils.get_item_properties(
s, columns,
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters=_formatters,
) for s in data))
else:
columns = (
'id',
'name',
'subnet_ids'
)
for s in data
),
)
else:
columns = ('id', 'name', 'subnet_ids')
column_headers = (
'ID',
'Name',
@@ -597,11 +650,17 @@ class ListNetwork(common.NetworkAndComputeLister):
data = client.networks(**args)
return (column_headers,
(utils.get_item_properties(
s, columns,
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters=_formatters,
) for s in data))
)
for s in data
),
)
def take_action_compute(self, client, parsed_args):
columns = (
@@ -617,11 +676,17 @@ class ListNetwork(common.NetworkAndComputeLister):
data = client.api.network_list()
return (column_headers,
(utils.get_dict_properties(
s, columns,
return (
column_headers,
(
utils.get_dict_properties(
s,
columns,
formatters=_formatters,
) for s in data))
)
for s in data
),
)
# TODO(sindhu): Use the SDK resource mapped attribute names once the
@@ -634,95 +699,95 @@ class SetNetwork(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'network',
metavar="<network>",
help=_("Network to modify (name or ID)")
help=_("Network to modify (name or ID)"),
)
parser.add_argument(
'--name',
metavar='<name>',
help=_("Set network name")
'--name', metavar='<name>', help=_("Set network name")
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
default=None,
help=_("Enable network")
help=_("Enable network"),
)
admin_group.add_argument(
'--disable',
action='store_true',
help=_("Disable network")
'--disable', action='store_true', help=_("Disable network")
)
share_group = parser.add_mutually_exclusive_group()
share_group.add_argument(
'--share',
action='store_true',
default=None,
help=_("Share the network between projects")
help=_("Share the network between projects"),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_("Do not share the network between projects")
help=_("Do not share the network between projects"),
)
parser.add_argument(
'--description',
metavar="<description>",
help=_("Set network description")
help=_("Set network description"),
)
parser.add_argument(
'--mtu',
metavar="<mtu>",
help=_("Set network mtu")
'--mtu', metavar="<mtu>", help=_("Set network mtu")
)
port_security_group = parser.add_mutually_exclusive_group()
port_security_group.add_argument(
'--enable-port-security',
action='store_true',
help=_("Enable port security by default for ports created on "
"this network")
help=_(
"Enable port security by default for ports created on "
"this network"
),
)
port_security_group.add_argument(
'--disable-port-security',
action='store_true',
help=_("Disable port security by default for ports created on "
"this network")
help=_(
"Disable port security by default for ports created on "
"this network"
),
)
external_router_grp = parser.add_mutually_exclusive_group()
external_router_grp.add_argument(
'--external',
action='store_true',
help=_("The network has an external routing facility that's not "
"managed by Neutron and can be used as in: "
"openstack router set --external-gateway NETWORK "
"(external-net extension required)")
help=_(
"The network has an external routing facility that's not "
"managed by Neutron and can be used as in: "
"openstack router set --external-gateway NETWORK "
"(external-net extension required)"
),
)
external_router_grp.add_argument(
'--internal',
action='store_true',
help=_("Opposite of '--external'")
help=_("Opposite of '--external'"),
)
default_router_grp = parser.add_mutually_exclusive_group()
default_router_grp.add_argument(
'--default',
action='store_true',
help=_("Set the network as the default external network")
help=_("Set the network as the default external network"),
)
default_router_grp.add_argument(
'--no-default',
action='store_true',
help=_("Do not use the network as the default external network")
help=_("Do not use the network as the default external network"),
)
qos_group = parser.add_mutually_exclusive_group()
qos_group.add_argument(
'--qos-policy',
metavar='<qos-policy>',
help=_("QoS policy to attach to this network (name or ID)")
help=_("QoS policy to attach to this network (name or ID)"),
)
qos_group.add_argument(
'--no-qos-policy',
action='store_true',
help=_("Remove the QoS policy attached to this network")
help=_("Remove the QoS policy attached to this network"),
)
_tag.add_tag_option_to_parser_for_set(parser, _('network'))
_add_additional_network_options(parser)
@@ -734,10 +799,12 @@ class SetNetwork(common.NeutronCommandWithExtraArgs):
attrs = _get_attrs_network(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
if attrs:
with common.check_missing_extension_if_error(
self.app.client_manager.network, attrs):
self.app.client_manager.network, attrs
):
client.update_network(obj, **attrs)
# tags is a subresource and it needs to be updated separately.
@@ -751,7 +818,7 @@ class ShowNetwork(common.NetworkAndComputeShowOne):
parser.add_argument(
'network',
metavar="<network>",
help=_("Network to display (name or ID)")
help=_("Network to display (name or ID)"),
)
return parser
@@ -776,7 +843,7 @@ class UnsetNetwork(common.NeutronUnsetCommandWithExtraArgs):
parser.add_argument(
'network',
metavar="<network>",
help=_("Network to modify (name or ID)")
help=_("Network to modify (name or ID)"),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('network'))
return parser

View File

@@ -52,9 +52,7 @@ def _get_network_columns(item):
}
hidden_columns = ['location', 'name', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -66,15 +64,18 @@ class AddNetworkToAgent(command.Command):
parser.add_argument(
'--dhcp',
action='store_true',
help=_('Add network to a DHCP agent'))
help=_('Add network to a DHCP agent'),
)
parser.add_argument(
'agent_id',
metavar='<agent-id>',
help=_('Agent to which a network is added (ID only)'))
help=_('Agent to which a network is added (ID only)'),
)
parser.add_argument(
'network',
metavar='<network>',
help=_('Network to be added to an agent (name or ID)'))
help=_('Network to be added to an agent (name or ID)'),
)
return parser
@@ -82,13 +83,15 @@ class AddNetworkToAgent(command.Command):
client = self.app.client_manager.network
agent = client.get_agent(parsed_args.agent_id)
network = client.find_network(
parsed_args.network, ignore_missing=False)
parsed_args.network, ignore_missing=False
)
if parsed_args.dhcp:
try:
client.add_dhcp_agent_to_network(agent, network)
except Exception:
msg = 'Failed to add {} to {}'.format(
network.name, agent.agent_type)
network.name, agent.agent_type
)
exceptions.CommandError(msg)
@@ -98,19 +101,17 @@ class AddRouterToAgent(command.Command):
def get_parser(self, prog_name):
parser = super(AddRouterToAgent, self).get_parser(prog_name)
parser.add_argument(
'--l3',
action='store_true',
help=_('Add router to an L3 agent')
'--l3', action='store_true', help=_('Add router to an L3 agent')
)
parser.add_argument(
'agent_id',
metavar='<agent-id>',
help=_("Agent to which a router is added (ID only)")
help=_("Agent to which a router is added (ID only)"),
)
parser.add_argument(
'router',
metavar='<router>',
help=_("Router to be added to an agent (name or ID)")
help=_("Router to be added to an agent (name or ID)"),
)
return parser
@@ -132,7 +133,7 @@ class DeleteNetworkAgent(command.Command):
'network_agent',
metavar="<network-agent>",
nargs='+',
help=(_("Network agent(s) to delete (ID only)"))
help=(_("Network agent(s) to delete (ID only)")),
)
return parser
@@ -145,14 +146,19 @@ class DeleteNetworkAgent(command.Command):
client.delete_agent(agent, ignore_missing=False)
except Exception as e:
result += 1
LOG.error(_("Failed to delete network agent with "
"ID '%(agent)s': %(e)s"),
{'agent': agent, 'e': e})
LOG.error(
_(
"Failed to delete network agent with "
"ID '%(agent)s': %(e)s"
),
{'agent': agent, 'e': e},
)
if result > 0:
total = len(parsed_args.network_agent)
msg = (_("%(result)s of %(total)s network agents failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s network agents failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -166,35 +172,48 @@ class ListNetworkAgent(command.Lister):
parser.add_argument(
'--agent-type',
metavar='<agent-type>',
choices=["bgp", "dhcp", "open-vswitch", "linux-bridge", "ofa",
"l3", "loadbalancer", "metering", "metadata", "macvtap",
"nic", "baremetal"],
help=_("List only agents with the specified agent type. "
"The supported agent types are: bgp, dhcp, open-vswitch, "
"linux-bridge, ofa, l3, loadbalancer, metering, "
"metadata, macvtap, nic, baremetal.")
choices=[
"bgp",
"dhcp",
"open-vswitch",
"linux-bridge",
"ofa",
"l3",
"loadbalancer",
"metering",
"metadata",
"macvtap",
"nic",
"baremetal",
],
help=_(
"List only agents with the specified agent type. "
"The supported agent types are: bgp, dhcp, open-vswitch, "
"linux-bridge, ofa, l3, loadbalancer, metering, "
"metadata, macvtap, nic, baremetal."
),
)
parser.add_argument(
'--host',
metavar='<host>',
help=_("List only agents running on the specified host")
help=_("List only agents running on the specified host"),
)
agent_type_group = parser.add_mutually_exclusive_group()
agent_type_group.add_argument(
'--network',
metavar='<network>',
help=_('List agents hosting a network (name or ID)')
help=_('List agents hosting a network (name or ID)'),
)
agent_type_group.add_argument(
'--router',
metavar='<router>',
help=_('List agents hosting this router (name or ID)')
help=_('List agents hosting this router (name or ID)'),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=_("List additional fields in output")
help=_("List additional fields in output"),
)
return parser
@@ -208,7 +227,7 @@ class ListNetworkAgent(command.Lister):
'availability_zone',
'is_alive',
'is_admin_state_up',
'binary'
'binary',
)
column_headers = (
'ID',
@@ -217,7 +236,7 @@ class ListNetworkAgent(command.Lister):
'Availability Zone',
'Alive',
'State',
'Binary'
'Binary',
)
key_value = {
@@ -232,21 +251,23 @@ class ListNetworkAgent(command.Lister):
'metadata': 'Metadata agent',
'macvtap': 'Macvtap agent',
'nic': 'NIC Switch agent',
'baremetal': 'Baremetal Node'
'baremetal': 'Baremetal Node',
}
filters = {}
if parsed_args.network is not None:
network = client.find_network(
parsed_args.network, ignore_missing=False)
parsed_args.network, ignore_missing=False
)
data = client.network_hosting_dhcp_agents(network)
elif parsed_args.router is not None:
if parsed_args.long:
columns += ('ha_state',)
column_headers += ('HA State',)
router = client.find_router(parsed_args.router,
ignore_missing=False)
router = client.find_router(
parsed_args.router, ignore_missing=False
)
data = client.routers_hosting_l3_agents(router)
else:
if parsed_args.agent_type is not None:
@@ -255,10 +276,17 @@ class ListNetworkAgent(command.Lister):
filters['host'] = parsed_args.host
data = client.agents(**filters)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters=_formatters,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters=_formatters,
)
for s in data
),
)
class RemoveNetworkFromAgent(command.Command):
@@ -269,28 +297,33 @@ class RemoveNetworkFromAgent(command.Command):
parser.add_argument(
'--dhcp',
action='store_true',
help=_('Remove network from DHCP agent'))
help=_('Remove network from DHCP agent'),
)
parser.add_argument(
'agent_id',
metavar='<agent-id>',
help=_('Agent to which a network is removed (ID only)'))
help=_('Agent to which a network is removed (ID only)'),
)
parser.add_argument(
'network',
metavar='<network>',
help=_('Network to be removed from an agent (name or ID)'))
help=_('Network to be removed from an agent (name or ID)'),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
agent = client.get_agent(parsed_args.agent_id)
network = client.find_network(
parsed_args.network, ignore_missing=False)
parsed_args.network, ignore_missing=False
)
if parsed_args.dhcp:
try:
client.remove_dhcp_agent_from_network(agent, network)
except Exception:
msg = 'Failed to remove {} to {}'.format(
network.name, agent.agent_type)
network.name, agent.agent_type
)
exceptions.CommandError(msg)
@@ -302,17 +335,17 @@ class RemoveRouterFromAgent(command.Command):
parser.add_argument(
'--l3',
action='store_true',
help=_('Remove router from an L3 agent')
help=_('Remove router from an L3 agent'),
)
parser.add_argument(
'agent_id',
metavar='<agent-id>',
help=_("Agent from which router will be removed (ID only)")
help=_("Agent from which router will be removed (ID only)"),
)
parser.add_argument(
'router',
metavar='<router>',
help=_("Router to be removed from an agent (name or ID)")
help=_("Router to be removed from an agent (name or ID)"),
)
return parser
@@ -335,23 +368,19 @@ class SetNetworkAgent(command.Command):
parser.add_argument(
'network_agent',
metavar="<network-agent>",
help=(_("Network agent to modify (ID only)"))
help=(_("Network agent to modify (ID only)")),
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("Set network agent description")
help=_("Set network agent description"),
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
help=_("Enable network agent")
'--enable', action='store_true', help=_("Enable network agent")
)
admin_group.add_argument(
'--disable',
action='store_true',
help=_("Disable network agent")
'--disable', action='store_true', help=_("Disable network agent")
)
return parser
@@ -378,7 +407,7 @@ class ShowNetworkAgent(command.ShowOne):
parser.add_argument(
'network_agent',
metavar="<network-agent>",
help=(_("Network agent to display (ID only)"))
help=(_("Network agent to display (ID only)")),
)
return parser
@@ -386,5 +415,9 @@ class ShowNetworkAgent(command.ShowOne):
client = self.app.client_manager.network
obj = client.get_agent(parsed_args.network_agent)
display_columns, columns = _get_network_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters,)
data = utils.get_item_properties(
obj,
columns,
formatters=_formatters,
)
return display_columns, data

View File

@@ -28,9 +28,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['name', 'location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -71,22 +69,28 @@ class CreateAutoAllocatedTopology(command.ShowOne):
parser.add_argument(
'--project',
metavar='<project>',
help=_("Return the auto allocated topology for a given project. "
"Default is current project")
help=_(
"Return the auto allocated topology for a given project. "
"Default is current project"
),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--check-resources',
action='store_true',
help=_("Validate the requirements for auto allocated topology. "
"Does not return a topology.")
help=_(
"Validate the requirements for auto allocated topology. "
"Does not return a topology."
),
)
parser.add_argument(
'--or-show',
action='store_true',
default=True,
help=_("If topology exists returns the topology's "
"information (Default)")
help=_(
"If topology exists returns the topology's "
"information (Default)"
),
)
return parser
@@ -95,9 +99,9 @@ class CreateAutoAllocatedTopology(command.ShowOne):
obj = client.validate_auto_allocated_topology(parsed_args.project)
columns = _format_check_resource_columns()
data = utils.get_item_properties(_format_check_resource(obj),
columns,
formatters={})
data = utils.get_item_properties(
_format_check_resource(obj), columns, formatters={}
)
return (columns, data)
@@ -126,8 +130,10 @@ class DeleteAutoAllocatedTopology(command.Command):
parser.add_argument(
'--project',
metavar='<project>',
help=_('Delete auto allocated topology for a given project. '
'Default is the current project')
help=_(
'Delete auto allocated topology for a given project. '
'Default is the current project'
),
)
identity_common.add_project_domain_option_to_parser(parser)

View File

@@ -33,9 +33,7 @@ def _get_columns(item):
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -65,28 +63,28 @@ class AddNetworkFlavorToProfile(command.Command):
_description = _("Add a service profile to a network flavor")
def get_parser(self, prog_name):
parser = super(
AddNetworkFlavorToProfile, self).get_parser(prog_name)
parser = super(AddNetworkFlavorToProfile, self).get_parser(prog_name)
parser.add_argument(
'flavor',
metavar="<flavor>",
help=_("Network flavor (name or ID)")
'flavor', metavar="<flavor>", help=_("Network flavor (name or ID)")
)
parser.add_argument(
'service_profile',
metavar="<service-profile>",
help=_("Service profile (ID only)")
help=_("Service profile (ID only)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj_flavor = client.find_flavor(
parsed_args.flavor, ignore_missing=False)
parsed_args.flavor, ignore_missing=False
)
obj_service_profile = client.find_service_profile(
parsed_args.service_profile, ignore_missing=False)
parsed_args.service_profile, ignore_missing=False
)
client.associate_flavor_with_service_profile(
obj_flavor, obj_service_profile)
obj_flavor, obj_service_profile
)
# TODO(dasanind): Use the SDK resource mapped attribute names once the
@@ -97,26 +95,25 @@ class CreateNetworkFlavor(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateNetworkFlavor, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar="<name>",
help=_("Name for the flavor")
'name', metavar="<name>", help=_("Name for the flavor")
)
parser.add_argument(
'--service-type',
metavar="<service-type>",
required=True,
help=_('Service type to which the flavor applies to: e.g. VPN '
'(See openstack network service provider list for loaded '
'examples.)')
help=_(
'Service type to which the flavor applies to: e.g. VPN '
'(See openstack network service provider list for loaded '
'examples.)'
),
)
parser.add_argument(
'--description',
help=_('Description for the flavor')
'--description', help=_('Description for the flavor')
)
parser.add_argument(
'--project',
metavar="<project>",
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -124,12 +121,10 @@ class CreateNetworkFlavor(command.ShowOne, common.NeutronCommandWithExtraArgs):
enable_group.add_argument(
'--enable',
action='store_true',
help=_("Enable the flavor (default)")
help=_("Enable the flavor (default)"),
)
enable_group.add_argument(
'--disable',
action='store_true',
help=_("Disable the flavor")
'--disable', action='store_true', help=_("Disable the flavor")
)
return parser
@@ -138,7 +133,8 @@ class CreateNetworkFlavor(command.ShowOne, common.NeutronCommandWithExtraArgs):
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_flavor(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -156,7 +152,7 @@ class DeleteNetworkFlavor(command.Command):
'flavor',
metavar='<flavor>',
nargs='+',
help=_('Flavor(s) to delete (name or ID)')
help=_('Flavor(s) to delete (name or ID)'),
)
return parser
@@ -170,13 +166,19 @@ class DeleteNetworkFlavor(command.Command):
client.delete_flavor(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete flavor with "
"name or ID '%(flavor)s': %(e)s"),
{"flavor": flavor, "e": e})
LOG.error(
_(
"Failed to delete flavor with "
"name or ID '%(flavor)s': %(e)s"
),
{"flavor": flavor, "e": e},
)
if result > 0:
total = len(parsed_args.flavor)
msg = (_("%(result)s of %(total)s flavors failed "
"to delete.") % {"result": result, "total": total})
msg = _("%(result)s of %(total)s flavors failed " "to delete.") % {
"result": result,
"total": total,
}
raise exceptions.CommandError(msg)
@@ -186,55 +188,56 @@ class ListNetworkFlavor(command.Lister):
def take_action(self, parsed_args):
client = self.app.client_manager.network
columns = (
'id',
'name',
'is_enabled',
'service_type',
'description'
)
columns = ('id', 'name', 'is_enabled', 'service_type', 'description')
column_headers = (
'ID',
'Name',
'Enabled',
'Service Type',
'Description'
'Description',
)
data = client.flavors()
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
class RemoveNetworkFlavorFromProfile(command.Command):
_description = _(
"Remove service profile from network flavor")
_description = _("Remove service profile from network flavor")
def get_parser(self, prog_name):
parser = super(
RemoveNetworkFlavorFromProfile, self).get_parser(prog_name)
parser = super(RemoveNetworkFlavorFromProfile, self).get_parser(
prog_name
)
parser.add_argument(
'flavor',
metavar="<flavor>",
help=_("Network flavor (name or ID)")
'flavor', metavar="<flavor>", help=_("Network flavor (name or ID)")
)
parser.add_argument(
'service_profile',
metavar="<service-profile>",
help=_("Service profile (ID only)")
help=_("Service profile (ID only)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj_flavor = client.find_flavor(
parsed_args.flavor, ignore_missing=False)
parsed_args.flavor, ignore_missing=False
)
obj_service_profile = client.find_service_profile(
parsed_args.service_profile, ignore_missing=False)
parsed_args.service_profile, ignore_missing=False
)
client.disassociate_flavor_from_service_profile(
obj_flavor, obj_service_profile)
obj_flavor, obj_service_profile
)
# TODO(dasanind): Use only the SDK resource mapped attribute names once the
@@ -247,36 +250,27 @@ class SetNetworkFlavor(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'flavor',
metavar="<flavor>",
help=_("Flavor to update (name or ID)")
help=_("Flavor to update (name or ID)"),
)
parser.add_argument(
'--description',
help=_('Set network flavor description')
'--description', help=_('Set network flavor description')
)
enable_group = parser.add_mutually_exclusive_group()
enable_group.add_argument(
'--disable',
action='store_true',
help=_("Disable network flavor")
'--disable', action='store_true', help=_("Disable network flavor")
)
enable_group.add_argument(
'--enable',
action='store_true',
help=_("Enable network flavor")
'--enable', action='store_true', help=_("Enable network flavor")
)
parser.add_argument(
'--name',
metavar="<name>",
help=_('Set flavor name')
'--name', metavar="<name>", help=_('Set flavor name')
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_flavor(
parsed_args.flavor,
ignore_missing=False)
obj = client.find_flavor(parsed_args.flavor, ignore_missing=False)
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
@@ -287,7 +281,8 @@ class SetNetworkFlavor(common.NeutronCommandWithExtraArgs):
if parsed_args.disable:
attrs['enabled'] = False
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_flavor(obj, **attrs)
@@ -299,7 +294,7 @@ class ShowNetworkFlavor(command.ShowOne):
parser.add_argument(
'flavor',
metavar='<flavor>',
help=_('Flavor to display (name or ID)')
help=_('Flavor to display (name or ID)'),
)
return parser

View File

@@ -31,9 +31,7 @@ def _get_columns(item):
hidden_columns = ['location', 'name', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -63,8 +61,9 @@ def _get_attrs(client_manager, parsed_args):
# TODO(ndahiwade): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class CreateNetworkFlavorProfile(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetworkFlavorProfile(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create new network flavor profile")
def get_parser(self, prog_name):
@@ -72,34 +71,38 @@ class CreateNetworkFlavorProfile(command.ShowOne,
parser.add_argument(
'--project',
metavar="<project>",
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--description',
metavar="<description>",
help=_("Description for the flavor profile")
help=_("Description for the flavor profile"),
)
enable_group = parser.add_mutually_exclusive_group()
enable_group.add_argument(
'--enable',
action='store_true',
help=_("Enable the flavor profile")
help=_("Enable the flavor profile"),
)
enable_group.add_argument(
'--disable',
action='store_true',
help=_("Disable the flavor profile")
help=_("Disable the flavor profile"),
)
parser.add_argument(
'--driver',
help=_("Python module path to driver. This becomes "
"required if --metainfo is missing and vice versa")
help=_(
"Python module path to driver. This becomes "
"required if --metainfo is missing and vice versa"
),
)
parser.add_argument(
'--metainfo',
help=_("Metainfo for the flavor profile. This becomes "
"required if --driver is missing and vice versa")
help=_(
"Metainfo for the flavor profile. This becomes "
"required if --driver is missing and vice versa"
),
)
return parser
@@ -108,7 +111,8 @@ class CreateNetworkFlavorProfile(command.ShowOne,
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
if parsed_args.driver is None and parsed_args.metainfo is None:
msg = _("Either --driver or --metainfo or both are required")
@@ -131,7 +135,7 @@ class DeleteNetworkFlavorProfile(command.Command):
'flavor_profile',
metavar='<flavor-profile>',
nargs='+',
help=_("Flavor profile(s) to delete (ID only)")
help=_("Flavor profile(s) to delete (ID only)"),
)
return parser
@@ -141,18 +145,24 @@ class DeleteNetworkFlavorProfile(command.Command):
for flavor_profile in parsed_args.flavor_profile:
try:
obj = client.find_service_profile(flavor_profile,
ignore_missing=False)
obj = client.find_service_profile(
flavor_profile, ignore_missing=False
)
client.delete_service_profile(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete flavor profile with "
"ID '%(flavor_profile)s': %(e)s"),
{"flavor_profile": flavor_profile, "e": e})
LOG.error(
_(
"Failed to delete flavor profile with "
"ID '%(flavor_profile)s': %(e)s"
),
{"flavor_profile": flavor_profile, "e": e},
)
if result > 0:
total = len(parsed_args.flavor_profile)
msg = (_("%(result)s of %(total)s flavor_profiles failed "
"to delete.") % {"result": result, "total": total})
msg = _(
"%(result)s of %(total)s flavor_profiles failed " "to delete."
) % {"result": result, "total": total}
raise exceptions.CommandError(msg)
@@ -178,10 +188,16 @@ class ListNetworkFlavorProfile(command.Lister):
)
data = client.service_profiles()
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
# TODO(ndahiwade): Use the SDK resource mapped attribute names once the
@@ -194,45 +210,51 @@ class SetNetworkFlavorProfile(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'flavor_profile',
metavar="<flavor-profile>",
help=_("Flavor profile to update (ID only)")
help=_("Flavor profile to update (ID only)"),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--description',
metavar="<description>",
help=_("Description for the flavor profile")
help=_("Description for the flavor profile"),
)
enable_group = parser.add_mutually_exclusive_group()
enable_group.add_argument(
'--enable',
action='store_true',
help=_("Enable the flavor profile")
help=_("Enable the flavor profile"),
)
enable_group.add_argument(
'--disable',
action='store_true',
help=_("Disable the flavor profile")
help=_("Disable the flavor profile"),
)
parser.add_argument(
'--driver',
help=_("Python module path to driver. This becomes "
"required if --metainfo is missing and vice versa")
help=_(
"Python module path to driver. This becomes "
"required if --metainfo is missing and vice versa"
),
)
parser.add_argument(
'--metainfo',
help=_("Metainfo for the flavor profile. This becomes "
"required if --driver is missing and vice versa")
help=_(
"Metainfo for the flavor profile. This becomes "
"required if --driver is missing and vice versa"
),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_service_profile(parsed_args.flavor_profile,
ignore_missing=False)
obj = client.find_service_profile(
parsed_args.flavor_profile, ignore_missing=False
)
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_service_profile(obj, **attrs)
@@ -245,14 +267,15 @@ class ShowNetworkFlavorProfile(command.ShowOne):
parser.add_argument(
'flavor_profile',
metavar='<flavor-profile>',
help=_("Flavor profile to display (ID only)")
help=_("Flavor profile to display (ID only)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_service_profile(parsed_args.flavor_profile,
ignore_missing=False)
obj = client.find_service_profile(
parsed_args.flavor_profile, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return (display_columns, data)

View File

@@ -32,9 +32,7 @@ def _get_columns(item):
}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -72,12 +70,12 @@ class CreateMeter(command.ShowOne, common.NeutronCommandWithExtraArgs):
parser.add_argument(
'--description',
metavar='<description>',
help=_("Create description for meter")
help=_("Create description for meter"),
)
parser.add_argument(
'--project',
metavar='<project>',
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
@@ -86,12 +84,12 @@ class CreateMeter(command.ShowOne, common.NeutronCommandWithExtraArgs):
'--share',
action='store_true',
default=None,
help=_("Share meter between projects")
help=_("Share meter between projects"),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_("Do not share meter between projects")
help=_("Do not share meter between projects"),
)
parser.add_argument(
'name',
@@ -105,7 +103,8 @@ class CreateMeter(command.ShowOne, common.NeutronCommandWithExtraArgs):
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_metering_label(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -125,7 +124,7 @@ class DeleteMeter(command.Command):
'meter',
metavar='<meter>',
nargs='+',
help=_('Meter to delete (name or ID)')
help=_('Meter to delete (name or ID)'),
)
return parser
@@ -139,13 +138,16 @@ class DeleteMeter(command.Command):
client.delete_metering_label(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete meter with "
"ID '%(meter)s': %(e)s"),
{"meter": meter, "e": e})
LOG.error(
_("Failed to delete meter with " "ID '%(meter)s': %(e)s"),
{"meter": meter, "e": e},
)
if result > 0:
total = len(parsed_args.meter)
msg = (_("%(result)s of %(total)s meters failed "
"to delete.") % {"result": result, "total": total})
msg = _("%(result)s of %(total)s meters failed " "to delete.") % {
"result": result,
"total": total,
}
raise exceptions.CommandError(msg)
@@ -169,10 +171,16 @@ class ListMeter(command.Lister):
)
data = client.metering_labels()
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
class ShowMeter(command.ShowOne):
@@ -181,16 +189,15 @@ class ShowMeter(command.ShowOne):
def get_parser(self, prog_name):
parser = super(ShowMeter, self).get_parser(prog_name)
parser.add_argument(
'meter',
metavar='<meter>',
help=_('Meter to display (name or ID)')
'meter', metavar='<meter>', help=_('Meter to display (name or ID)')
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_metering_label(parsed_args.meter,
ignore_missing=False)
obj = client.find_metering_label(
parsed_args.meter, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return display_columns, data

View File

@@ -30,9 +30,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -76,30 +74,30 @@ class CreateMeterRule(command.ShowOne, common.NeutronCommandWithExtraArgs):
parser.add_argument(
'--project',
metavar='<project>',
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
exclude_group = parser.add_mutually_exclusive_group()
exclude_group.add_argument(
'--exclude',
action='store_true',
help=_("Exclude remote IP prefix from traffic count")
help=_("Exclude remote IP prefix from traffic count"),
)
exclude_group.add_argument(
'--include',
action='store_true',
help=_("Include remote IP prefix from traffic count (default)")
help=_("Include remote IP prefix from traffic count (default)"),
)
direction_group = parser.add_mutually_exclusive_group()
direction_group.add_argument(
'--ingress',
action='store_true',
help=_("Apply rule to incoming network traffic (default)")
help=_("Apply rule to incoming network traffic (default)"),
)
direction_group.add_argument(
'--egress',
action='store_true',
help=_('Apply rule to outgoing network traffic')
help=_('Apply rule to outgoing network traffic'),
)
parser.add_argument(
'--remote-ip-prefix',
@@ -129,12 +127,14 @@ class CreateMeterRule(command.ShowOne, common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
client = self.app.client_manager.network
_meter = client.find_metering_label(parsed_args.meter,
ignore_missing=False)
_meter = client.find_metering_label(
parsed_args.meter, ignore_missing=False
)
parsed_args.meter = _meter.id
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_metering_label_rule(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -152,7 +152,7 @@ class DeleteMeterRule(command.Command):
'meter_rule_id',
metavar='<meter-rule-id>',
nargs='+',
help=_('Meter rule to delete (ID only)')
help=_('Meter rule to delete (ID only)'),
)
return parser
@@ -167,14 +167,19 @@ class DeleteMeterRule(command.Command):
client.delete_metering_label_rule(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete meter rule with "
"ID '%(id)s': %(e)s"),
{"id": id, "e": e})
LOG.error(
_(
"Failed to delete meter rule with "
"ID '%(id)s': %(e)s"
),
{"id": id, "e": e},
)
if result > 0:
total = len(parsed_args.meter_rule_id)
msg = (_("%(result)s of %(total)s meter rules failed "
"to delete.") % {"result": result, "total": total})
msg = _(
"%(result)s of %(total)s meter rules failed " "to delete."
) % {"result": result, "total": total}
raise exceptions.CommandError(msg)
@@ -201,10 +206,16 @@ class ListMeterRule(command.Lister):
'Destination IP Prefix',
)
data = client.metering_label_rules()
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
class ShowMeterRule(command.ShowOne):
@@ -215,14 +226,15 @@ class ShowMeterRule(command.ShowOne):
parser.add_argument(
'meter_rule_id',
metavar='<meter-rule-id>',
help=_('Meter rule (ID only)')
help=_('Meter rule (ID only)'),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_metering_label_rule(parsed_args.meter_rule_id,
ignore_missing=False)
obj = client.find_metering_label_rule(
parsed_args.meter_rule_id, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return display_columns, data

View File

@@ -43,9 +43,7 @@ def _get_columns(item):
}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -81,39 +79,40 @@ def _get_attrs(client_manager, parsed_args):
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class CreateNetworkQosPolicy(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetworkQosPolicy(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create a QoS policy")
def get_parser(self, prog_name):
parser = super(CreateNetworkQosPolicy, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar='<name>',
help=_("Name of QoS policy to create")
'name', metavar='<name>', help=_("Name of QoS policy to create")
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("Description of the QoS policy")
help=_("Description of the QoS policy"),
)
share_group = parser.add_mutually_exclusive_group()
share_group.add_argument(
'--share',
action='store_true',
default=None,
help=_("Make the QoS policy accessible by other projects")
help=_("Make the QoS policy accessible by other projects"),
)
share_group.add_argument(
'--no-share',
action='store_true',
help=_("Make the QoS policy not accessible by other projects "
"(default)")
help=_(
"Make the QoS policy not accessible by other projects "
"(default)"
),
)
parser.add_argument(
'--project',
metavar='<project>',
help=_("Owner's project (name or ID)")
help=_("Owner's project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
default_group = parser.add_mutually_exclusive_group()
@@ -133,7 +132,8 @@ class CreateNetworkQosPolicy(command.ShowOne,
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_qos_policy(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={})
@@ -149,7 +149,7 @@ class DeleteNetworkQosPolicy(command.Command):
'policy',
metavar="<qos-policy>",
nargs="+",
help=_("QoS policy(s) to delete (name or ID)")
help=_("QoS policy(s) to delete (name or ID)"),
)
return parser
@@ -163,14 +163,19 @@ class DeleteNetworkQosPolicy(command.Command):
client.delete_qos_policy(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete QoS policy "
"name or ID '%(qos_policy)s': %(e)s"),
{'qos_policy': policy, 'e': e})
LOG.error(
_(
"Failed to delete QoS policy "
"name or ID '%(qos_policy)s': %(e)s"
),
{'qos_policy': policy, 'e': e},
)
if result > 0:
total = len(parsed_args.policy)
msg = (_("%(result)s of %(total)s QoS policies failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s QoS policies failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -184,19 +189,21 @@ class ListNetworkQosPolicy(command.Lister):
parser.add_argument(
'--project',
metavar='<project>',
help=_("List qos policies according to their project (name or ID)")
help=_(
"List qos policies according to their project (name or ID)"
),
)
identity_common.add_project_domain_option_to_parser(parser)
shared_group = parser.add_mutually_exclusive_group()
shared_group.add_argument(
'--share',
action='store_true',
help=_("List qos policies shared between projects")
help=_("List qos policies shared between projects"),
)
shared_group.add_argument(
'--no-share',
action='store_true',
help=_("List qos policies not shared between projects")
help=_("List qos policies not shared between projects"),
)
return parser
@@ -218,10 +225,17 @@ class ListNetworkQosPolicy(command.Lister):
)
attrs = _get_attrs(self.app.client_manager, parsed_args)
data = client.qos_policies(**attrs)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters={},
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -234,17 +248,15 @@ class SetNetworkQosPolicy(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'policy',
metavar="<qos-policy>",
help=_("QoS policy to modify (name or ID)")
help=_("QoS policy to modify (name or ID)"),
)
parser.add_argument(
'--name',
metavar="<name>",
help=_('Set QoS policy name')
'--name', metavar="<name>", help=_('Set QoS policy name')
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("Description of the QoS policy")
help=_("Description of the QoS policy"),
)
enable_group = parser.add_mutually_exclusive_group()
enable_group.add_argument(
@@ -272,12 +284,11 @@ class SetNetworkQosPolicy(common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_qos_policy(
parsed_args.policy,
ignore_missing=False)
obj = client.find_qos_policy(parsed_args.policy, ignore_missing=False)
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_qos_policy(obj, **attrs)
@@ -289,14 +300,13 @@ class ShowNetworkQosPolicy(command.ShowOne):
parser.add_argument(
'policy',
metavar="<qos-policy>",
help=_("QoS policy to display (name or ID)")
help=_("QoS policy to display (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_qos_policy(parsed_args.policy,
ignore_missing=False)
obj = client.find_qos_policy(parsed_args.policy, ignore_missing=False)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (display_columns, data)

View File

@@ -30,17 +30,40 @@ MANDATORY_PARAMETERS = {
RULE_TYPE_MINIMUM_BANDWIDTH: {'min_kbps', 'direction'},
RULE_TYPE_MINIMUM_PACKET_RATE: {'min_kpps', 'direction'},
RULE_TYPE_DSCP_MARKING: {'dscp_mark'},
RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps'}}
RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps'},
}
OPTIONAL_PARAMETERS = {
RULE_TYPE_MINIMUM_BANDWIDTH: set(),
RULE_TYPE_MINIMUM_PACKET_RATE: set(),
RULE_TYPE_DSCP_MARKING: set(),
RULE_TYPE_BANDWIDTH_LIMIT: {'direction', 'max_burst_kbps'}}
RULE_TYPE_BANDWIDTH_LIMIT: {'direction', 'max_burst_kbps'},
}
DIRECTION_EGRESS = 'egress'
DIRECTION_INGRESS = 'ingress'
DIRECTION_ANY = 'any'
DSCP_VALID_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
34, 36, 38, 40, 46, 48, 56]
DSCP_VALID_MARKS = [
0,
8,
10,
12,
14,
16,
18,
20,
22,
24,
26,
28,
30,
32,
34,
36,
38,
40,
46,
48,
56,
]
ACTION_CREATE = 'create'
ACTION_DELETE = 'delete'
@@ -53,9 +76,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -63,31 +84,38 @@ def _check_type_parameters(attrs, type, is_create):
req_params = MANDATORY_PARAMETERS[type]
opt_params = OPTIONAL_PARAMETERS[type]
type_params = req_params | opt_params
notreq_params = set(itertools.chain(
*[v for k, v in MANDATORY_PARAMETERS.items() if k != type]))
notreq_params = set(
itertools.chain(
*[v for k, v in MANDATORY_PARAMETERS.items() if k != type]
)
)
notreq_params -= type_params
if is_create and None in map(attrs.get, req_params):
msg = (_('"Create" rule command for type "%(rule_type)s" requires '
'arguments: %(args)s') %
{'rule_type': type, 'args': ", ".join(sorted(req_params))})
msg = _(
'"Create" rule command for type "%(rule_type)s" requires '
'arguments: %(args)s'
) % {'rule_type': type, 'args': ", ".join(sorted(req_params))}
raise exceptions.CommandError(msg)
if set(attrs.keys()) & notreq_params:
msg = (_('Rule type "%(rule_type)s" only requires arguments: %(args)s')
% {'rule_type': type, 'args': ", ".join(sorted(type_params))})
msg = _(
'Rule type "%(rule_type)s" only requires arguments: %(args)s'
) % {'rule_type': type, 'args': ", ".join(sorted(type_params))}
raise exceptions.CommandError(msg)
def _get_attrs(network_client, parsed_args, is_create=False):
attrs = {}
qos = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
qos = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
attrs['qos_policy_id'] = qos.id
if not is_create:
attrs['id'] = parsed_args.id
rule_type = _find_rule_type(qos, parsed_args.id)
if not rule_type:
msg = (_('Rule ID %(rule_id)s not found') %
{'rule_id': parsed_args.id})
msg = _('Rule ID %(rule_id)s not found') % {
'rule_id': parsed_args.id
}
raise exceptions.CommandError(msg)
else:
rule_type = parsed_args.type
@@ -112,9 +140,10 @@ def _get_attrs(network_client, parsed_args, is_create=False):
if rule_type == RULE_TYPE_MINIMUM_PACKET_RATE:
attrs['direction'] = DIRECTION_ANY
else:
msg = (_('Direction "any" can only be used with '
'%(rule_type_min_pps)s rule type') %
{'rule_type_min_pps': RULE_TYPE_MINIMUM_PACKET_RATE})
msg = _(
'Direction "any" can only be used with '
'%(rule_type_min_pps)s rule type'
) % {'rule_type_min_pps': RULE_TYPE_MINIMUM_PACKET_RATE}
raise exceptions.CommandError(msg)
_check_type_parameters(attrs, rule_type, is_create)
return attrs
@@ -130,8 +159,10 @@ def _get_item_properties(item, fields):
def _rule_action_call(client, action, rule_type):
rule_type = rule_type.replace('-', '_')
func_name = '%(action)s_qos_%(rule_type)s_rule' % {'action': action,
'rule_type': rule_type}
func_name = '%(action)s_qos_%(rule_type)s_rule' % {
'action': action,
'rule_type': rule_type,
}
return getattr(client, func_name)
@@ -147,81 +178,91 @@ def _add_rule_arguments(parser):
dest='max_kbps',
metavar='<max-kbps>',
type=int,
help=_('Maximum bandwidth in kbps')
help=_('Maximum bandwidth in kbps'),
)
parser.add_argument(
'--max-burst-kbits',
dest='max_burst_kbits',
metavar='<max-burst-kbits>',
type=int,
help=_('Maximum burst in kilobits, 0 or not specified means '
'automatic, which is 80%% of the bandwidth limit, which works '
'for typical TCP traffic. For details check the QoS user '
'workflow.')
help=_(
'Maximum burst in kilobits, 0 or not specified means '
'automatic, which is 80%% of the bandwidth limit, which works '
'for typical TCP traffic. For details check the QoS user '
'workflow.'
),
)
parser.add_argument(
'--dscp-mark',
dest='dscp_mark',
metavar='<dscp-mark>',
type=int,
help=_('DSCP mark: value can be 0, even numbers from 8-56, '
'excluding 42, 44, 50, 52, and 54')
help=_(
'DSCP mark: value can be 0, even numbers from 8-56, '
'excluding 42, 44, 50, 52, and 54'
),
)
parser.add_argument(
'--min-kbps',
dest='min_kbps',
metavar='<min-kbps>',
type=int,
help=_('Minimum guaranteed bandwidth in kbps')
help=_('Minimum guaranteed bandwidth in kbps'),
)
parser.add_argument(
'--min-kpps',
dest='min_kpps',
metavar='<min-kpps>',
type=int,
help=_('Minimum guaranteed packet rate in kpps')
help=_('Minimum guaranteed packet rate in kpps'),
)
direction_group = parser.add_mutually_exclusive_group()
direction_group.add_argument(
'--ingress',
action='store_true',
help=_("Ingress traffic direction from the project point of view")
help=_("Ingress traffic direction from the project point of view"),
)
direction_group.add_argument(
'--egress',
action='store_true',
help=_("Egress traffic direction from the project point of view")
help=_("Egress traffic direction from the project point of view"),
)
direction_group.add_argument(
'--any',
action='store_true',
help=_("Any traffic direction from the project point of view. Can be "
"used only with minimum packet rate rule.")
help=_(
"Any traffic direction from the project point of view. Can be "
"used only with minimum packet rate rule."
),
)
class CreateNetworkQosRule(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetworkQosRule(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create new Network QoS rule")
def get_parser(self, prog_name):
parser = super(CreateNetworkQosRule, self).get_parser(
prog_name)
parser = super(CreateNetworkQosRule, self).get_parser(prog_name)
parser.add_argument(
'qos_policy',
metavar='<qos-policy>',
help=_('QoS policy that contains the rule (name or ID)')
help=_('QoS policy that contains the rule (name or ID)'),
)
parser.add_argument(
'--type',
metavar='<type>',
required=True,
choices=[RULE_TYPE_MINIMUM_BANDWIDTH,
RULE_TYPE_MINIMUM_PACKET_RATE,
RULE_TYPE_DSCP_MARKING,
RULE_TYPE_BANDWIDTH_LIMIT],
help=(_('QoS rule type (%s)') %
", ".join(MANDATORY_PARAMETERS.keys()))
choices=[
RULE_TYPE_MINIMUM_BANDWIDTH,
RULE_TYPE_MINIMUM_PACKET_RATE,
RULE_TYPE_DSCP_MARKING,
RULE_TYPE_BANDWIDTH_LIMIT,
],
help=(
_('QoS rule type (%s)')
% ", ".join(MANDATORY_PARAMETERS.keys())
),
)
_add_rule_arguments(parser)
return parser
@@ -231,12 +272,13 @@ class CreateNetworkQosRule(command.ShowOne,
try:
attrs = _get_attrs(network_client, parsed_args, is_create=True)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = _rule_action_call(
network_client, ACTION_CREATE, parsed_args.type)(
attrs.pop('qos_policy_id'), **attrs)
network_client, ACTION_CREATE, parsed_args.type
)(attrs.pop('qos_policy_id'), **attrs)
except Exception as e:
msg = (_('Failed to create Network QoS rule: %(e)s') % {'e': e})
msg = _('Failed to create Network QoS rule: %(e)s') % {'e': e}
raise exceptions.CommandError(msg)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
@@ -251,12 +293,12 @@ class DeleteNetworkQosRule(command.Command):
parser.add_argument(
'qos_policy',
metavar='<qos-policy>',
help=_('QoS policy that contains the rule (name or ID)')
help=_('QoS policy that contains the rule (name or ID)'),
)
parser.add_argument(
'id',
metavar='<rule-id>',
help=_('Network QoS rule to delete (ID)')
help=_('Network QoS rule to delete (ID)'),
)
return parser
@@ -264,16 +306,19 @@ class DeleteNetworkQosRule(command.Command):
network_client = self.app.client_manager.network
rule_id = parsed_args.id
try:
qos = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
qos = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
rule_type = _find_rule_type(qos, rule_id)
if not rule_type:
raise Exception('Rule %s not found' % rule_id)
_rule_action_call(network_client, ACTION_DELETE, rule_type)(
rule_id, qos.id)
rule_id, qos.id
)
except Exception as e:
msg = (_('Failed to delete Network QoS rule ID "%(rule)s": %(e)s')
% {'rule': rule_id, 'e': e})
msg = _(
'Failed to delete Network QoS rule ID "%(rule)s": %(e)s'
) % {'rule': rule_id, 'e': e}
raise exceptions.CommandError(msg)
@@ -285,7 +330,7 @@ class ListNetworkQosRule(command.Lister):
parser.add_argument(
'qos_policy',
metavar='<qos-policy>',
help=_('QoS policy that contains the rule (name or ID)')
help=_('QoS policy that contains the rule (name or ID)'),
)
return parser
@@ -313,11 +358,14 @@ class ListNetworkQosRule(command.Lister):
'DSCP mark',
'Direction',
)
qos = client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
qos = client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
data = qos.rules
return (column_headers,
(_get_item_properties(s, columns) for s in data))
return (
column_headers,
(_get_item_properties(s, columns) for s in data),
)
class SetNetworkQosRule(common.NeutronCommandWithExtraArgs):
@@ -328,12 +376,12 @@ class SetNetworkQosRule(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'qos_policy',
metavar='<qos-policy>',
help=_('QoS policy that contains the rule (name or ID)')
help=_('QoS policy that contains the rule (name or ID)'),
)
parser.add_argument(
'id',
metavar='<rule-id>',
help=_('Network QoS rule to delete (ID)')
help=_('Network QoS rule to delete (ID)'),
)
_add_rule_arguments(parser)
return parser
@@ -341,22 +389,28 @@ class SetNetworkQosRule(common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
network_client = self.app.client_manager.network
try:
qos = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
qos = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
rule_type = _find_rule_type(qos, parsed_args.id)
if not rule_type:
raise Exception('Rule not found')
attrs = _get_attrs(network_client, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
qos_id = attrs.pop('qos_policy_id')
qos_rule = _rule_action_call(network_client, ACTION_FIND,
rule_type)(attrs.pop('id'), qos_id)
qos_rule = _rule_action_call(
network_client, ACTION_FIND, rule_type
)(attrs.pop('id'), qos_id)
_rule_action_call(network_client, ACTION_SET, rule_type)(
qos_rule, qos_id, **attrs)
qos_rule, qos_id, **attrs
)
except Exception as e:
msg = (_('Failed to set Network QoS rule ID "%(rule)s": %(e)s') %
{'rule': parsed_args.id, 'e': e})
msg = _('Failed to set Network QoS rule ID "%(rule)s": %(e)s') % {
'rule': parsed_args.id,
'e': e,
}
raise exceptions.CommandError(msg)
@@ -368,12 +422,12 @@ class ShowNetworkQosRule(command.ShowOne):
parser.add_argument(
'qos_policy',
metavar='<qos-policy>',
help=_('QoS policy that contains the rule (name or ID)')
help=_('QoS policy that contains the rule (name or ID)'),
)
parser.add_argument(
'id',
metavar='<rule-id>',
help=_('Network QoS rule to delete (ID)')
help=_('Network QoS rule to delete (ID)'),
)
return parser
@@ -381,16 +435,20 @@ class ShowNetworkQosRule(command.ShowOne):
network_client = self.app.client_manager.network
rule_id = parsed_args.id
try:
qos = network_client.find_qos_policy(parsed_args.qos_policy,
ignore_missing=False)
qos = network_client.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False
)
rule_type = _find_rule_type(qos, rule_id)
if not rule_type:
raise Exception('Rule not found')
obj = _rule_action_call(network_client, ACTION_SHOW, rule_type)(
rule_id, qos.id)
rule_id, qos.id
)
except Exception as e:
msg = (_('Failed to set Network QoS rule ID "%(rule)s": %(e)s') %
{'rule': rule_id, 'e': e})
msg = _('Failed to set Network QoS rule ID "%(rule)s": %(e)s') % {
'rule': rule_id,
'e': e,
}
raise exceptions.CommandError(msg)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)

View File

@@ -26,7 +26,8 @@ def _get_columns(item):
}
hidden_columns = ["id", "location", "name", 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden_columns)
item, column_map, hidden_columns
)
class ListNetworkQosRuleType(command.Lister):
@@ -38,25 +39,25 @@ class ListNetworkQosRuleType(command.Lister):
supported.add_argument(
'--all-supported',
action='store_true',
help=_("List all the QoS rule types supported by any loaded "
"mechanism drivers (the union of all sets of supported "
"rules)")
help=_(
"List all the QoS rule types supported by any loaded "
"mechanism drivers (the union of all sets of supported "
"rules)"
),
)
supported.add_argument(
'--all-rules',
action='store_true',
help=_("List all QoS rule types implemented in Neutron QoS driver")
help=_(
"List all QoS rule types implemented in Neutron QoS driver"
),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
columns = (
'type',
)
column_headers = (
'Type',
)
columns = ('type',)
column_headers = ('Type',)
args = {}
if parsed_args.all_supported:
@@ -65,10 +66,17 @@ class ListNetworkQosRuleType(command.Lister):
args['all_rules'] = True
data = client.qos_rule_types(**args)
return (column_headers,
(utils.get_item_properties(
s, columns, formatters={},
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
)
for s in data
),
)
class ShowNetworkQosRuleType(command.ShowOne):
@@ -79,7 +87,7 @@ class ShowNetworkQosRuleType(command.ShowOne):
parser.add_argument(
'rule_type',
metavar="<qos-rule-type-name>",
help=_("Name of QoS rule type")
help=_("Name of QoS rule type"),
)
return parser

View File

@@ -32,9 +32,7 @@ def _get_columns(item):
}
hidden_columns = ['location', 'name', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -46,27 +44,28 @@ def _get_attrs(client_manager, parsed_args):
network_client = client_manager.network
if parsed_args.type == 'network':
object_id = network_client.find_network(
parsed_args.rbac_object, ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
if parsed_args.type == 'qos_policy':
object_id = network_client.find_qos_policy(
parsed_args.rbac_object,
ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
if parsed_args.type == 'security_group':
object_id = network_client.find_security_group(
parsed_args.rbac_object,
ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
if parsed_args.type == 'address_scope':
object_id = network_client.find_address_scope(
parsed_args.rbac_object,
ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
if parsed_args.type == 'subnetpool':
object_id = network_client.find_subnet_pool(
parsed_args.rbac_object,
ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
if parsed_args.type == 'address_group':
object_id = network_client.find_address_group(
parsed_args.rbac_object,
ignore_missing=False).id
parsed_args.rbac_object, ignore_missing=False
).id
attrs['object_id'] = object_id
@@ -101,51 +100,68 @@ class CreateNetworkRBAC(command.ShowOne, common.NeutronCommandWithExtraArgs):
parser.add_argument(
'rbac_object',
metavar="<rbac-object>",
help=_("The object to which this RBAC policy affects (name or ID)")
help=_(
"The object to which this RBAC policy affects (name or ID)"
),
)
parser.add_argument(
'--type',
metavar="<type>",
required=True,
choices=['address_group', 'address_scope', 'security_group',
'subnetpool', 'qos_policy', 'network'],
help=_('Type of the object that RBAC policy '
'affects ("address_group", "address_scope", '
'"security_group", "subnetpool", "qos_policy" or '
'"network")')
choices=[
'address_group',
'address_scope',
'security_group',
'subnetpool',
'qos_policy',
'network',
],
help=_(
'Type of the object that RBAC policy '
'affects ("address_group", "address_scope", '
'"security_group", "subnetpool", "qos_policy" or '
'"network")'
),
)
parser.add_argument(
'--action',
metavar="<action>",
required=True,
choices=['access_as_external', 'access_as_shared'],
help=_('Action for the RBAC policy '
'("access_as_external" or "access_as_shared")')
help=_(
'Action for the RBAC policy '
'("access_as_external" or "access_as_shared")'
),
)
target_project_group = parser.add_mutually_exclusive_group(
required=True)
required=True
)
target_project_group.add_argument(
'--target-project',
metavar="<target-project>",
help=_('The project to which the RBAC policy '
'will be enforced (name or ID)')
help=_(
'The project to which the RBAC policy '
'will be enforced (name or ID)'
),
)
target_project_group.add_argument(
'--target-all-projects',
action='store_true',
help=_('Allow creating RBAC policy for all projects.')
help=_('Allow creating RBAC policy for all projects.'),
)
parser.add_argument(
'--target-project-domain',
metavar='<target-project-domain>',
help=_('Domain the target project belongs to (name or ID). '
'This can be used in case collisions between project names '
'exist.'),
help=_(
'Domain the target project belongs to (name or ID). '
'This can be used in case collisions between project names '
'exist.'
),
)
parser.add_argument(
'--project',
metavar="<project>",
help=_('The owner project (name or ID)')
help=_('The owner project (name or ID)'),
)
identity_common.add_project_domain_option_to_parser(parser)
return parser
@@ -154,7 +170,8 @@ class CreateNetworkRBAC(command.ShowOne, common.NeutronCommandWithExtraArgs):
client = self.app.client_manager.network
attrs = _get_attrs(self.app.client_manager, parsed_args)
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_rbac_policy(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
@@ -170,7 +187,7 @@ class DeleteNetworkRBAC(command.Command):
'rbac_policy',
metavar="<rbac-policy>",
nargs='+',
help=_("RBAC policy(s) to delete (ID only)")
help=_("RBAC policy(s) to delete (ID only)"),
)
return parser
@@ -184,14 +201,19 @@ class DeleteNetworkRBAC(command.Command):
client.delete_rbac_policy(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete RBAC policy with "
"ID '%(rbac)s': %(e)s"),
{'rbac': rbac, 'e': e})
LOG.error(
_(
"Failed to delete RBAC policy with "
"ID '%(rbac)s': %(e)s"
),
{'rbac': rbac, 'e': e},
)
if result > 0:
total = len(parsed_args.rbac_policy)
msg = (_("%(result)s of %(total)s RBAC policies failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s RBAC policies failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -203,30 +225,40 @@ class ListNetworkRBAC(command.Lister):
parser.add_argument(
'--type',
metavar='<type>',
choices=['address_group', 'address_scope', 'security_group',
'subnetpool', 'qos_policy', 'network'],
help=_('List network RBAC policies according to '
'given object type ("address_group", "address_scope", '
'"security_group", "subnetpool", "qos_policy" or '
'"network")')
choices=[
'address_group',
'address_scope',
'security_group',
'subnetpool',
'qos_policy',
'network',
],
help=_(
'List network RBAC policies according to '
'given object type ("address_group", "address_scope", '
'"security_group", "subnetpool", "qos_policy" or '
'"network")'
),
)
parser.add_argument(
'--action',
metavar='<action>',
choices=['access_as_external', 'access_as_shared'],
help=_('List network RBAC policies according to given '
'action ("access_as_external" or "access_as_shared")')
help=_(
'List network RBAC policies according to given '
'action ("access_as_external" or "access_as_shared")'
),
)
parser.add_argument(
'--target-project',
metavar='<target-project>',
help=_('List network RBAC policies for a specific target project')
help=_('List network RBAC policies for a specific target project'),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=_("List additional fields in output")
help=_("List additional fields in output"),
)
return parser
@@ -265,10 +297,16 @@ class ListNetworkRBAC(command.Lister):
data = client.rbac_policies(**query)
return (column_headers,
(utils.get_item_properties(
s, columns,
) for s in data))
return (
column_headers,
(
utils.get_item_properties(
s,
columns,
)
for s in data
),
)
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -281,27 +319,32 @@ class SetNetworkRBAC(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'rbac_policy',
metavar="<rbac-policy>",
help=_("RBAC policy to be modified (ID only)")
help=_("RBAC policy to be modified (ID only)"),
)
parser.add_argument(
'--target-project',
metavar="<target-project>",
help=_('The project to which the RBAC policy '
'will be enforced (name or ID)')
help=_(
'The project to which the RBAC policy '
'will be enforced (name or ID)'
),
)
parser.add_argument(
'--target-project-domain',
metavar='<target-project-domain>',
help=_('Domain the target project belongs to (name or ID). '
'This can be used in case collisions between project names '
'exist.'),
help=_(
'Domain the target project belongs to (name or ID). '
'This can be used in case collisions between project names '
'exist.'
),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_rbac_policy(parsed_args.rbac_policy,
ignore_missing=False)
obj = client.find_rbac_policy(
parsed_args.rbac_policy, ignore_missing=False
)
attrs = {}
if parsed_args.target_project:
identity_client = self.app.client_manager.identity
@@ -312,7 +355,8 @@ class SetNetworkRBAC(common.NeutronCommandWithExtraArgs):
).id
attrs['target_tenant'] = project_id
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_rbac_policy(obj, **attrs)
@@ -324,14 +368,15 @@ class ShowNetworkRBAC(command.ShowOne):
parser.add_argument(
'rbac_policy',
metavar="<rbac-policy>",
help=_("RBAC policy (ID only)")
help=_("RBAC policy (ID only)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_rbac_policy(parsed_args.rbac_policy,
ignore_missing=False)
obj = client.find_rbac_policy(
parsed_args.rbac_policy, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return display_columns, data

View File

@@ -29,22 +29,19 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
class CreateNetworkSegment(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetworkSegment(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create new network segment")
def get_parser(self, prog_name):
parser = super(CreateNetworkSegment, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar='<name>',
help=_('New network segment name')
'name', metavar='<name>', help=_('New network segment name')
)
parser.add_argument(
'--description',
@@ -60,10 +57,12 @@ class CreateNetworkSegment(command.ShowOne,
'--segment',
metavar='<segment>',
type=int,
help=_('Segment identifier for this network segment which is '
'based on the network type, VLAN ID for vlan network '
'type and tunnel ID for geneve, gre and vxlan network '
'types'),
help=_(
'Segment identifier for this network segment which is '
'based on the network type, VLAN ID for vlan network '
'type and tunnel ID for geneve, gre and vxlan network '
'types'
),
)
parser.add_argument(
'--network',
@@ -76,8 +75,10 @@ class CreateNetworkSegment(command.ShowOne,
metavar='<network-type>',
choices=['flat', 'geneve', 'gre', 'local', 'vlan', 'vxlan'],
required=True,
help=_('Network type of this network segment '
'(flat, geneve, gre, local, vlan or vxlan)'),
help=_(
'Network type of this network segment '
'(flat, geneve, gre, local, vlan or vxlan)'
),
)
return parser
@@ -85,8 +86,9 @@ class CreateNetworkSegment(command.ShowOne,
client = self.app.client_manager.network
attrs = {}
attrs['name'] = parsed_args.name
attrs['network_id'] = client.find_network(parsed_args.network,
ignore_missing=False).id
attrs['network_id'] = client.find_network(
parsed_args.network, ignore_missing=False
).id
attrs['network_type'] = parsed_args.network_type
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
@@ -95,7 +97,8 @@ class CreateNetworkSegment(command.ShowOne,
if parsed_args.segment is not None:
attrs['segmentation_id'] = parsed_args.segment
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = client.create_segment(**attrs)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
@@ -121,19 +124,25 @@ class DeleteNetworkSegment(command.Command):
result = 0
for network_segment in parsed_args.network_segment:
try:
obj = client.find_segment(network_segment,
ignore_missing=False)
obj = client.find_segment(
network_segment, ignore_missing=False
)
client.delete_segment(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete network segment with "
"ID '%(network_segment)s': %(e)s"),
{'network_segment': network_segment, 'e': e})
LOG.error(
_(
"Failed to delete network segment with "
"ID '%(network_segment)s': %(e)s"
),
{'network_segment': network_segment, 'e': e},
)
if result > 0:
total = len(parsed_args.network_segment)
msg = (_("%(result)s of %(total)s network segments failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s network segments failed " "to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -151,8 +160,10 @@ class ListNetworkSegment(command.Lister):
parser.add_argument(
'--network',
metavar='<network>',
help=_('List network segments that belong to this '
'network (name or ID)'),
help=_(
'List network segments that belong to this '
'network (name or ID)'
),
)
return parser
@@ -162,8 +173,7 @@ class ListNetworkSegment(command.Lister):
filters = {}
if parsed_args.network:
_network = network_client.find_network(
parsed_args.network,
ignore_missing=False
parsed_args.network, ignore_missing=False
)
filters = {'network_id': _network.id}
data = network_client.segments(**filters)
@@ -183,18 +193,20 @@ class ListNetworkSegment(command.Lister):
'segmentation_id',
)
if parsed_args.long:
headers = headers + (
'Physical Network',
)
columns = columns + (
'physical_network',
)
headers = headers + ('Physical Network',)
columns = columns + ('physical_network',)
return (headers,
(utils.get_item_properties(
s, columns,
return (
headers,
(
utils.get_item_properties(
s,
columns,
formatters={},
) for s in data))
)
for s in data
),
)
class SetNetworkSegment(common.NeutronCommandWithExtraArgs):
@@ -221,15 +233,17 @@ class SetNetworkSegment(common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_segment(parsed_args.network_segment,
ignore_missing=False)
obj = client.find_segment(
parsed_args.network_segment, ignore_missing=False
)
attrs = {}
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
client.update_segment(obj, **attrs)
@@ -248,8 +262,7 @@ class ShowNetworkSegment(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_segment(
parsed_args.network_segment,
ignore_missing=False
parsed_args.network_segment, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)

View File

@@ -35,9 +35,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -45,8 +43,9 @@ def _get_ranges(item):
item = sorted([int(i) for i in item])
for a, b in itertools.groupby(enumerate(item), lambda xy: xy[1] - xy[0]):
b = list(b)
yield "%s-%s" % (b[0][1], b[-1][1]) if b[0][1] != b[-1][1] else \
str(b[0][1])
yield "%s-%s" % (b[0][1], b[-1][1]) if b[0][1] != b[-1][1] else str(
b[0][1]
)
def _hack_tuple_value_update_by_index(tup, index, value):
@@ -73,7 +72,8 @@ def _exchange_dict_keys_with_values(orig_dict):
def _update_available_from_props(columns, props):
index_available = columns.index('available')
props = _hack_tuple_value_update_by_index(
props, index_available, list(_get_ranges(props[index_available])))
props, index_available, list(_get_ranges(props[index_available]))
)
return props
@@ -82,8 +82,7 @@ def _update_used_from_props(columns, props):
updated_used = _exchange_dict_keys_with_values(props[index_used])
for k, v in updated_used.items():
updated_used[k] = list(_get_ranges(v))
props = _hack_tuple_value_update_by_index(
props, index_used, updated_used)
props = _hack_tuple_value_update_by_index(props, index_used, updated_used)
return props
@@ -93,8 +92,9 @@ def _update_additional_fields_from_props(columns, props):
return props
class CreateNetworkSegmentRange(command.ShowOne,
common.NeutronCommandWithExtraArgs):
class CreateNetworkSegmentRange(
command.ShowOne, common.NeutronCommandWithExtraArgs
):
_description = _("Create new network segment range")
def get_parser(self, prog_name):
@@ -104,8 +104,10 @@ class CreateNetworkSegmentRange(command.ShowOne,
"--private",
dest="private",
action="store_true",
help=_('Network segment range is assigned specifically to the '
'project'),
help=_(
'Network segment range is assigned specifically to the '
'project'
),
)
shared_group.add_argument(
"--shared",
@@ -116,13 +118,15 @@ class CreateNetworkSegmentRange(command.ShowOne,
parser.add_argument(
'name',
metavar='<name>',
help=_('Name of new network segment range')
help=_('Name of new network segment range'),
)
parser.add_argument(
'--project',
metavar='<project>',
help=_('Network segment range owner (name or ID). Optional when '
'the segment range is shared'),
help=_(
'Network segment range owner (name or ID). Optional when '
'the segment range is shared'
),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
@@ -130,8 +134,10 @@ class CreateNetworkSegmentRange(command.ShowOne,
metavar='<network-type>',
choices=['geneve', 'gre', 'vlan', 'vxlan'],
required=True,
help=_('Network type of this network segment range '
'(geneve, gre, vlan or vxlan)'),
help=_(
'Network type of this network segment range '
'(geneve, gre, vlan or vxlan)'
),
)
parser.add_argument(
'--physical-network',
@@ -143,20 +149,24 @@ class CreateNetworkSegmentRange(command.ShowOne,
metavar='<minimum-segmentation-id>',
type=int,
required=True,
help=_('Minimum segment identifier for this network segment '
'range which is based on the network type, VLAN ID for '
'vlan network type and tunnel ID for geneve, gre and vxlan '
'network types'),
help=_(
'Minimum segment identifier for this network segment '
'range which is based on the network type, VLAN ID for '
'vlan network type and tunnel ID for geneve, gre and vxlan '
'network types'
),
)
parser.add_argument(
'--maximum',
metavar='<maximum-segmentation-id>',
type=int,
required=True,
help=_('Maximum segment identifier for this network segment '
'range which is based on the network type, VLAN ID for '
'vlan network type and tunnel ID for geneve, gre and vxlan '
'network types'),
help=_(
'Maximum segment identifier for this network segment '
'range which is based on the network type, VLAN ID for '
'vlan network type and tunnel ID for geneve, gre and vxlan '
'network types'
),
)
return parser
@@ -165,11 +175,14 @@ class CreateNetworkSegmentRange(command.ShowOne,
network_client = self.app.client_manager.network
try:
# Verify that the extension exists.
network_client.find_extension('network-segment-range',
ignore_missing=False)
network_client.find_extension(
'network-segment-range', ignore_missing=False
)
except Exception as e:
msg = (_('Network segment range create not supported by '
'Network API: %(e)s') % {'e': e})
msg = _(
'Network segment range create not supported by '
'Network API: %(e)s'
) % {'e': e}
raise exceptions.CommandError(msg)
identity_client = self.app.client_manager.identity
@@ -178,10 +191,14 @@ class CreateNetworkSegmentRange(command.ShowOne,
msg = _("--project is only allowed with --private")
raise exceptions.CommandError(msg)
if (parsed_args.network_type.lower() != 'vlan' and
parsed_args.physical_network):
msg = _("--physical-network is only allowed with --network-type "
"vlan")
if (
parsed_args.network_type.lower() != 'vlan'
and parsed_args.physical_network
):
msg = _(
"--physical-network is only allowed with --network-type "
"vlan"
)
raise exceptions.CommandError(msg)
attrs = {}
@@ -205,8 +222,13 @@ class CreateNetworkSegmentRange(command.ShowOne,
if project_id:
attrs['project_id'] = project_id
else:
msg = (_("Failed to create the network segment range for "
"project %(project_id)s") % parsed_args.project_id)
msg = (
_(
"Failed to create the network segment range for "
"project %(project_id)s"
)
% parsed_args.project_id
)
raise exceptions.CommandError(msg)
elif not attrs['shared']:
# default to the current project if no project specified and shared
@@ -218,7 +240,8 @@ class CreateNetworkSegmentRange(command.ShowOne,
attrs['physical_network'] = parsed_args.physical_network
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
obj = network_client.create_network_segment_range(**attrs)
display_columns, columns = _get_columns(obj)
@@ -244,30 +267,39 @@ class DeleteNetworkSegmentRange(command.Command):
network_client = self.app.client_manager.network
try:
# Verify that the extension exists.
network_client.find_extension('network-segment-range',
ignore_missing=False)
network_client.find_extension(
'network-segment-range', ignore_missing=False
)
except Exception as e:
msg = (_('Network segment range delete not supported by '
'Network API: %(e)s') % {'e': e})
msg = _(
'Network segment range delete not supported by '
'Network API: %(e)s'
) % {'e': e}
raise exceptions.CommandError(msg)
result = 0
for network_segment_range in parsed_args.network_segment_range:
try:
obj = network_client.find_network_segment_range(
network_segment_range, ignore_missing=False)
network_segment_range, ignore_missing=False
)
network_client.delete_network_segment_range(obj)
except Exception as e:
result += 1
LOG.error(_("Failed to delete network segment range with "
"ID '%(network_segment_range)s': %(e)s"),
{'network_segment_range': network_segment_range,
'e': e})
LOG.error(
_(
"Failed to delete network segment range with "
"ID '%(network_segment_range)s': %(e)s"
),
{'network_segment_range': network_segment_range, 'e': e},
)
if result > 0:
total = len(parsed_args.network_segment_range)
msg = (_("%(result)s of %(total)s network segment ranges failed "
"to delete.") % {'result': result, 'total': total})
msg = _(
"%(result)s of %(total)s network segment ranges failed "
"to delete."
) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -290,8 +322,9 @@ class ListNetworkSegmentRange(command.Lister):
used_group.add_argument(
'--unused',
action='store_true',
help=_('List network segment ranges that have segments '
'not in use'),
help=_(
'List network segment ranges that have segments ' 'not in use'
),
)
available_group = parser.add_mutually_exclusive_group()
available_group.add_argument(
@@ -310,11 +343,14 @@ class ListNetworkSegmentRange(command.Lister):
network_client = self.app.client_manager.network
try:
# Verify that the extension exists.
network_client.find_extension('network-segment-range',
ignore_missing=False)
network_client.find_extension(
'network-segment-range', ignore_missing=False
)
except Exception as e:
msg = (_('Network segment ranges list not supported by '
'Network API: %(e)s') % {'e': e})
msg = _(
'Network segment ranges list not supported by '
'Network API: %(e)s'
) % {'e': e}
raise exceptions.CommandError(msg)
filters = {}
@@ -329,7 +365,7 @@ class ListNetworkSegmentRange(command.Lister):
'Network Type',
'Physical Network',
'Minimum ID',
'Maximum ID'
'Maximum ID',
)
columns = (
'id',
@@ -342,8 +378,12 @@ class ListNetworkSegmentRange(command.Lister):
'minimum',
'maximum',
)
if parsed_args.available or parsed_args.unavailable or \
parsed_args.used or parsed_args.unused:
if (
parsed_args.available
or parsed_args.unavailable
or parsed_args.used
or parsed_args.unused
):
# If one of `--available`, `--unavailable`, `--used`,
# `--unused` is specified, we assume that additional fields
# should be listed in output.
@@ -361,13 +401,16 @@ class ListNetworkSegmentRange(command.Lister):
display_props = tuple()
for s in data:
props = utils.get_item_properties(s, columns)
if parsed_args.available and \
_is_prop_empty(columns, props, 'available') or \
parsed_args.unavailable and \
not _is_prop_empty(columns, props, 'available') or \
parsed_args.used and _is_prop_empty(columns, props, 'used') or \
parsed_args.unused and \
not _is_prop_empty(columns, props, 'used'):
if (
parsed_args.available
and _is_prop_empty(columns, props, 'available')
or parsed_args.unavailable
and not _is_prop_empty(columns, props, 'available')
or parsed_args.used
and _is_prop_empty(columns, props, 'used')
or parsed_args.unused
and not _is_prop_empty(columns, props, 'used')
):
continue
if parsed_args.long:
props = _update_additional_fields_from_props(columns, props)
@@ -409,20 +452,25 @@ class SetNetworkSegmentRange(common.NeutronCommandWithExtraArgs):
network_client = self.app.client_manager.network
try:
# Verify that the extension exists.
network_client.find_extension('network-segment-range',
ignore_missing=False)
network_client.find_extension(
'network-segment-range', ignore_missing=False
)
except Exception as e:
msg = (_('Network segment range set not supported by '
'Network API: %(e)s') % {'e': e})
msg = _(
'Network segment range set not supported by '
'Network API: %(e)s'
) % {'e': e}
raise exceptions.CommandError(msg)
if (parsed_args.minimum and not parsed_args.maximum) or \
(parsed_args.maximum and not parsed_args.minimum):
if (parsed_args.minimum and not parsed_args.maximum) or (
parsed_args.maximum and not parsed_args.minimum
):
msg = _("--minimum and --maximum are both required")
raise exceptions.CommandError(msg)
obj = network_client.find_network_segment_range(
parsed_args.network_segment_range, ignore_missing=False)
parsed_args.network_segment_range, ignore_missing=False
)
attrs = {}
if parsed_args.name:
attrs['name'] = parsed_args.name
@@ -431,7 +479,8 @@ class SetNetworkSegmentRange(common.NeutronCommandWithExtraArgs):
if parsed_args.maximum:
attrs['maximum'] = parsed_args.maximum
attrs.update(
self._parse_extra_properties(parsed_args.extra_properties))
self._parse_extra_properties(parsed_args.extra_properties)
)
network_client.update_network_segment_range(obj, **attrs)
@@ -451,16 +500,18 @@ class ShowNetworkSegmentRange(command.ShowOne):
network_client = self.app.client_manager.network
try:
# Verify that the extension exists.
network_client.find_extension('network-segment-range',
ignore_missing=False)
network_client.find_extension(
'network-segment-range', ignore_missing=False
)
except Exception as e:
msg = (_('Network segment range show not supported by '
'Network API: %(e)s') % {'e': e})
msg = _(
'Network segment range show not supported by '
'Network API: %(e)s'
) % {'e': e}
raise exceptions.CommandError(msg)
obj = network_client.find_network_segment_range(
parsed_args.network_segment_range,
ignore_missing=False
parsed_args.network_segment_range, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)

View File

@@ -45,55 +45,54 @@ class CreateNetworkTrunk(command.ShowOne):
def get_parser(self, prog_name):
parser = super(CreateNetworkTrunk, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar='<name>',
help=_("Name of the trunk to create")
'name', metavar='<name>', help=_("Name of the trunk to create")
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("A description of the trunk")
help=_("A description of the trunk"),
)
parser.add_argument(
'--parent-port',
metavar='<parent-port>',
required=True,
help=_("Parent port belonging to this trunk (name or ID)")
help=_("Parent port belonging to this trunk (name or ID)"),
)
parser.add_argument(
'--subport',
metavar='<port=,segmentation-type=,segmentation-id=>',
action=parseractions.MultiKeyValueAction, dest='add_subports',
action=parseractions.MultiKeyValueAction,
dest='add_subports',
optional_keys=['segmentation-id', 'segmentation-type'],
required_keys=['port'],
help=_("Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>,"
"segmentation-id=<segmentation-ID>\' (--subport) option "
"can be repeated")
help=_(
"Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>,"
"segmentation-id=<segmentation-ID>\' (--subport) option "
"can be repeated"
),
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
default=True,
help=_("Enable trunk (default)")
help=_("Enable trunk (default)"),
)
admin_group.add_argument(
'--disable',
action='store_true',
help=_("Disable trunk")
'--disable', action='store_true', help=_("Disable trunk")
)
identity_utils.add_project_owner_option_to_parser(parser)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
attrs = _get_attrs_for_trunk(self.app.client_manager,
parsed_args)
attrs = _get_attrs_for_trunk(self.app.client_manager, parsed_args)
obj = client.create_trunk(**attrs)
display_columns, columns = _get_columns(obj)
data = osc_utils.get_dict_properties(obj, columns,
formatters=_formatters)
data = osc_utils.get_dict_properties(
obj, columns, formatters=_formatters
)
return display_columns, data
@@ -106,7 +105,7 @@ class DeleteNetworkTrunk(command.Command):
'trunk',
metavar="<trunk>",
nargs="+",
help=_("Trunk(s) to delete (name or ID)")
help=_("Trunk(s) to delete (name or ID)"),
)
return parser
@@ -119,13 +118,19 @@ class DeleteNetworkTrunk(command.Command):
client.delete_trunk(trunk_id)
except Exception as e:
result += 1
LOG.error(_("Failed to delete trunk with name "
"or ID '%(trunk)s': %(e)s"),
{'trunk': trunk, 'e': e})
LOG.error(
_(
"Failed to delete trunk with name "
"or ID '%(trunk)s': %(e)s"
),
{'trunk': trunk, 'e': e},
)
if result > 0:
total = len(parsed_args.trunk)
msg = (_("%(result)s of %(total)s trunks failed "
"to delete.") % {'result': result, 'total': total})
msg = _("%(result)s of %(total)s trunks failed " "to delete.") % {
'result': result,
'total': total,
}
raise exceptions.CommandError(msg)
@@ -138,25 +143,15 @@ class ListNetworkTrunk(command.Lister):
'--long',
action='store_true',
default=False,
help=_("List additional fields in output")
help=_("List additional fields in output"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
data = client.trunks()
headers = (
'ID',
'Name',
'Parent Port',
'Description'
)
columns = (
'id',
'name',
'port_id',
'description'
)
headers = ('ID', 'Name', 'Parent Port', 'Description')
columns = ('id', 'name', 'port_id', 'description')
if parsed_args.long:
headers += (
'Status',
@@ -164,17 +159,18 @@ class ListNetworkTrunk(command.Lister):
'Created At',
'Updated At',
)
columns += (
'status',
'admin_state_up',
'created_at',
'updated_at'
)
return (headers,
(osc_utils.get_item_properties(
s, columns,
columns += ('status', 'admin_state_up', 'created_at', 'updated_at')
return (
headers,
(
osc_utils.get_item_properties(
s,
columns,
formatters=_formatters,
) for s in data))
)
for s in data
),
)
class SetNetworkTrunk(command.Command):
@@ -183,41 +179,36 @@ class SetNetworkTrunk(command.Command):
def get_parser(self, prog_name):
parser = super(SetNetworkTrunk, self).get_parser(prog_name)
parser.add_argument(
'trunk',
metavar="<trunk>",
help=_("Trunk to modify (name or ID)")
'trunk', metavar="<trunk>", help=_("Trunk to modify (name or ID)")
)
parser.add_argument(
'--name',
metavar="<name>",
help=_("Set trunk name")
'--name', metavar="<name>", help=_("Set trunk name")
)
parser.add_argument(
'--description',
metavar='<description>',
help=_("A description of the trunk")
help=_("A description of the trunk"),
)
parser.add_argument(
'--subport',
metavar='<port=,segmentation-type=,segmentation-id=>',
action=parseractions.MultiKeyValueAction, dest='set_subports',
action=parseractions.MultiKeyValueAction,
dest='set_subports',
optional_keys=['segmentation-id', 'segmentation-type'],
required_keys=['port'],
help=_("Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>"
",segmentation-id=<segmentation-ID>\' (--subport) option "
"can be repeated")
help=_(
"Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>"
",segmentation-id=<segmentation-ID>\' (--subport) option "
"can be repeated"
),
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
help=_("Enable trunk")
'--enable', action='store_true', help=_("Enable trunk")
)
admin_group.add_argument(
'--disable',
action='store_true',
help=_("Disable trunk")
'--disable', action='store_true', help=_("Disable trunk")
)
return parser
@@ -228,28 +219,32 @@ class SetNetworkTrunk(command.Command):
try:
client.update_trunk(trunk_id, **attrs)
except Exception as e:
msg = (_("Failed to set trunk '%(t)s': %(e)s")
% {'t': parsed_args.trunk, 'e': e})
msg = _("Failed to set trunk '%(t)s': %(e)s") % {
't': parsed_args.trunk,
'e': e,
}
raise exceptions.CommandError(msg)
if parsed_args.set_subports:
subport_attrs = _get_attrs_for_subports(self.app.client_manager,
parsed_args)
subport_attrs = _get_attrs_for_subports(
self.app.client_manager, parsed_args
)
try:
client.add_trunk_subports(trunk_id, subport_attrs)
except Exception as e:
msg = (_("Failed to add subports to trunk '%(t)s': %(e)s")
% {'t': parsed_args.trunk, 'e': e})
msg = _("Failed to add subports to trunk '%(t)s': %(e)s") % {
't': parsed_args.trunk,
'e': e,
}
raise exceptions.CommandError(msg)
class ShowNetworkTrunk(command.ShowOne):
"""Show information of a given network trunk"""
def get_parser(self, prog_name):
parser = super(ShowNetworkTrunk, self).get_parser(prog_name)
parser.add_argument(
'trunk',
metavar="<trunk>",
help=_("Trunk to display (name or ID)")
'trunk', metavar="<trunk>", help=_("Trunk to display (name or ID)")
)
return parser
@@ -258,8 +253,9 @@ class ShowNetworkTrunk(command.ShowOne):
trunk_id = client.find_trunk(parsed_args.trunk).id
obj = client.get_trunk(trunk_id)
display_columns, columns = _get_columns(obj)
data = osc_utils.get_dict_properties(obj, columns,
formatters=_formatters)
data = osc_utils.get_dict_properties(
obj, columns, formatters=_formatters
)
return display_columns, data
@@ -272,7 +268,7 @@ class ListNetworkSubport(command.Lister):
'--trunk',
required=True,
metavar="<trunk>",
help=_("List subports belonging to this trunk (name or ID)")
help=_("List subports belonging to this trunk (name or ID)"),
)
return parser
@@ -282,10 +278,16 @@ class ListNetworkSubport(command.Lister):
data = client.get_trunk_subports(trunk_id)
headers = ('Port', 'Segmentation Type', 'Segmentation ID')
columns = ('port_id', 'segmentation_type', 'segmentation_id')
return (headers,
(osc_utils.get_dict_properties(
s, columns,
) for s in data[SUB_PORTS]))
return (
headers,
(
osc_utils.get_dict_properties(
s,
columns,
)
for s in data[SUB_PORTS]
),
)
class UnsetNetworkTrunk(command.Command):
@@ -296,15 +298,18 @@ class UnsetNetworkTrunk(command.Command):
parser.add_argument(
'trunk',
metavar="<trunk>",
help=_("Unset subports from this trunk (name or ID)")
help=_("Unset subports from this trunk (name or ID)"),
)
parser.add_argument(
'--subport',
metavar="<subport>",
required=True,
action='append', dest='unset_subports',
help=_("Subport to delete (name or ID of the port) "
"(--subport) option can be repeated")
action='append',
dest='unset_subports',
help=_(
"Subport to delete (name or ID of the port) "
"(--subport) option can be repeated"
),
)
return parser
@@ -325,9 +330,7 @@ def _get_columns(item):
column_map = {}
hidden_columns = ['location', 'tenant_id']
return osc_utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -342,12 +345,14 @@ def _get_attrs_for_trunk(client_manager, parsed_args):
if parsed_args.disable:
attrs['admin_state_up'] = False
if 'parent_port' in parsed_args and parsed_args.parent_port is not None:
port_id = client_manager.network.find_port(
parsed_args.parent_port)['id']
port_id = client_manager.network.find_port(parsed_args.parent_port)[
'id'
]
attrs['port_id'] = port_id
if 'add_subports' in parsed_args and parsed_args.add_subports is not None:
attrs[SUB_PORTS] = _format_subports(client_manager,
parsed_args.add_subports)
attrs[SUB_PORTS] = _format_subports(
client_manager, parsed_args.add_subports
)
# "trunk set" command doesn't support setting project.
if 'project' in parsed_args and parsed_args.project is not None:
@@ -372,10 +377,13 @@ def _format_subports(client_manager, subports):
if subport.get('segmentation-id'):
try:
subport_attrs['segmentation_id'] = int(
subport['segmentation-id'])
subport['segmentation-id']
)
except ValueError:
msg = (_("Segmentation-id '%s' is not an integer") %
subport['segmentation-id'])
msg = (
_("Segmentation-id '%s' is not an integer")
% subport['segmentation-id']
)
raise exceptions.CommandError(msg)
if subport.get('segmentation-type'):
subport_attrs['segmentation_type'] = subport['segmentation-type']
@@ -386,10 +394,11 @@ def _format_subports(client_manager, subports):
def _get_attrs_for_subports(client_manager, parsed_args):
attrs = {}
if 'set_subports' in parsed_args and parsed_args.set_subports is not None:
attrs = _format_subports(client_manager,
parsed_args.set_subports)
if ('unset_subports' in parsed_args and
parsed_args.unset_subports is not None):
attrs = _format_subports(client_manager, parsed_args.set_subports)
if (
'unset_subports' in parsed_args
and parsed_args.unset_subports is not None
):
subports_list = []
for subport in parsed_args.unset_subports:
port_id = client_manager.network.find_port(subport)['id']

View File

@@ -66,9 +66,7 @@ def _get_columns(item):
}
hidden_columns = ['location', 'tenant_id']
return utils.get_osc_show_columns_for_sdk_resource(
item,
column_map,
hidden_columns
item, column_map, hidden_columns
)
@@ -79,7 +77,6 @@ class JSONKeyValueAction(argparse.Action):
"""
def __call__(self, parser, namespace, values, option_string=None):
# Make sure we have an empty dict rather than None
if getattr(namespace, self.dest, None) is None:
setattr(namespace, self.dest, {})
@@ -92,9 +89,11 @@ class JSONKeyValueAction(argparse.Action):
if '=' in values:
current_dest.update([values.split('=', 1)])
else:
msg = _("Expected '<key>=<value>' or JSON data for option "
"%(option)s, but encountered JSON parsing error: "
"%(error)s") % {"option": option_string, "error": e}
msg = _(
"Expected '<key>=<value>' or JSON data for option "
"%(option)s, but encountered JSON parsing error: "
"%(error)s"
) % {"option": option_string, "error": e}
raise argparse.ArgumentTypeError(msg)
@@ -151,23 +150,33 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.qos_policy:
attrs['qos_policy_id'] = client_manager.network.find_qos_policy(
parsed_args.qos_policy, ignore_missing=False).id
parsed_args.qos_policy, ignore_missing=False
).id
if ('enable_uplink_status_propagation' in parsed_args and
parsed_args.enable_uplink_status_propagation):
if (
'enable_uplink_status_propagation' in parsed_args
and parsed_args.enable_uplink_status_propagation
):
attrs['propagate_uplink_status'] = True
if ('disable_uplink_status_propagation' in parsed_args and
parsed_args.disable_uplink_status_propagation):
if (
'disable_uplink_status_propagation' in parsed_args
and parsed_args.disable_uplink_status_propagation
):
attrs['propagate_uplink_status'] = False
if ('numa_policy_required' in parsed_args and
parsed_args.numa_policy_required):
if (
'numa_policy_required' in parsed_args
and parsed_args.numa_policy_required
):
attrs['numa_affinity_policy'] = 'required'
elif ('numa_policy_preferred' in parsed_args and
parsed_args.numa_policy_preferred):
elif (
'numa_policy_preferred' in parsed_args
and parsed_args.numa_policy_preferred
):
attrs['numa_affinity_policy'] = 'preferred'
elif ('numa_policy_legacy' in parsed_args and
parsed_args.numa_policy_legacy):
elif (
'numa_policy_legacy' in parsed_args and parsed_args.numa_policy_legacy
):
attrs['numa_affinity_policy'] = 'legacy'
if 'device_profile' in parsed_args and parsed_args.device_profile:
@@ -191,8 +200,9 @@ def _prepare_fixed_ips(client_manager, parsed_args):
if 'subnet' in ip_spec:
subnet_name_id = ip_spec['subnet']
if subnet_name_id:
_subnet = client.find_subnet(subnet_name_id,
ignore_missing=False)
_subnet = client.find_subnet(
subnet_name_id, ignore_missing=False
)
ip_spec['subnet_id'] = _subnet.id
del ip_spec['subnet']
@@ -220,8 +230,9 @@ def _prepare_filter_fixed_ips(client_manager, parsed_args):
if 'subnet' in ip_spec:
subnet_name_id = ip_spec['subnet']
if subnet_name_id:
_subnet = client.find_subnet(subnet_name_id,
ignore_missing=False)
_subnet = client.find_subnet(
subnet_name_id, ignore_missing=False
)
ips.append('subnet_id=%s' % _subnet.id)
if 'ip-address' in ip_spec:
@@ -236,30 +247,36 @@ def _add_updatable_args(parser):
parser.add_argument(
'--description',
metavar='<description>',
help=_("Description of this port")
help=_("Description of this port"),
)
parser.add_argument(
'--device',
metavar='<device-id>',
help=_("Port device ID")
'--device', metavar='<device-id>', help=_("Port device ID")
)
parser.add_argument(
'--mac-address',
metavar='<mac-address>',
help=_("MAC address of this port (admin only)")
help=_("MAC address of this port (admin only)"),
)
parser.add_argument(
'--device-owner',
metavar='<device-owner>',
help=_("Device owner of this port. This is the entity that uses "
"the port (for example, network:dhcp).")
help=_(
"Device owner of this port. This is the entity that uses "
"the port (for example, network:dhcp)."
),
)
parser.add_argument(
'--vnic-type',
metavar='<vnic-type>',
choices=(
'direct', 'direct-physical', 'macvtap',
'normal', 'baremetal', 'virtio-forwarder', 'vdpa', 'remote-managed'
'direct',
'direct-physical',
'macvtap',
'normal',
'baremetal',
'virtio-forwarder',
'vdpa',
'remote-managed',
),
help=_(
"VNIC type for this port (direct | direct-physical | "
@@ -271,35 +288,39 @@ def _add_updatable_args(parser):
parser.add_argument(
'--host',
metavar='<host-id>',
help=_("Allocate port on host <host-id> (ID only)")
help=_("Allocate port on host <host-id> (ID only)"),
)
parser.add_argument(
'--dns-domain',
metavar='dns-domain',
help=_("Set DNS domain to this port "
"(requires dns_domain extension for ports)")
help=_(
"Set DNS domain to this port "
"(requires dns_domain extension for ports)"
),
)
parser.add_argument(
'--dns-name',
metavar='<dns-name>',
help=_("Set DNS name for this port "
"(requires DNS integration extension)")
help=_(
"Set DNS name for this port "
"(requires DNS integration extension)"
),
)
numa_affinity_policy_group = parser.add_mutually_exclusive_group()
numa_affinity_policy_group.add_argument(
'--numa-policy-required',
action='store_true',
help=_("NUMA affinity policy required to schedule this port")
help=_("NUMA affinity policy required to schedule this port"),
)
numa_affinity_policy_group.add_argument(
'--numa-policy-preferred',
action='store_true',
help=_("NUMA affinity policy preferred to schedule this port")
help=_("NUMA affinity policy preferred to schedule this port"),
)
numa_affinity_policy_group.add_argument(
'--numa-policy-legacy',
action='store_true',
help=_("NUMA affinity policy using legacy mode to schedule this port")
help=_("NUMA affinity policy using legacy mode to schedule this port"),
)
@@ -339,7 +360,7 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
'--network',
metavar='<network>',
required=True,
help=_("Network this port belongs to (name or ID)")
help=_("Network this port belongs to (name or ID)"),
)
_add_updatable_args(parser)
fixed_ip = parser.add_mutually_exclusive_group()
@@ -348,56 +369,56 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
help=_("Desired IP and/or subnet for this port (name or ID): "
"subnet=<subnet>,ip-address=<ip-address> "
"(repeat option to set multiple fixed IP addresses)")
help=_(
"Desired IP and/or subnet for this port (name or ID): "
"subnet=<subnet>,ip-address=<ip-address> "
"(repeat option to set multiple fixed IP addresses)"
),
)
fixed_ip.add_argument(
'--no-fixed-ip',