summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2023-05-08 11:03:05 +0100
committerStephen Finucane <sfinucan@redhat.com>2023-05-10 10:51:30 +0100
commit6475dc58e8baa199d948c4b2d250c1fb45e0bd30 (patch)
tree063e722cef74bdedadd6458be13cbfedb880e55e /openstackclient/network
parent35ba1d8f1304d3255b96b704d524666ec5b6fea2 (diff)
downloadpython-openstackclient-6475dc58e8baa199d948c4b2d250c1fb45e0bd30.tar.gz
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>
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/client.py6
-rw-r--r--openstackclient/network/common.py102
-rw-r--r--openstackclient/network/v2/address_group.py106
-rw-r--r--openstackclient/network/v2/address_scope.py92
-rw-r--r--openstackclient/network/v2/floating_ip.py199
-rw-r--r--openstackclient/network/v2/floating_ip_pool.py24
-rw-r--r--openstackclient/network/v2/floating_ip_port_forwarding.py219
-rw-r--r--openstackclient/network/v2/ip_availability.py34
-rw-r--r--openstackclient/network/v2/l3_conntrack_helper.py93
-rw-r--r--openstackclient/network/v2/local_ip.py108
-rw-r--r--openstackclient/network/v2/local_ip_association.py69
-rw-r--r--openstackclient/network/v2/ndp_proxy.py105
-rw-r--r--openstackclient/network/v2/network.py321
-rw-r--r--openstackclient/network/v2/network_agent.py149
-rw-r--r--openstackclient/network/v2/network_auto_allocated_topology.py34
-rw-r--r--openstackclient/network/v2/network_flavor.py139
-rw-r--r--openstackclient/network/v2/network_flavor_profile.py103
-rw-r--r--openstackclient/network/v2/network_meter.py53
-rw-r--r--openstackclient/network/v2/network_meter_rule.py60
-rw-r--r--openstackclient/network/v2/network_qos_policy.py88
-rw-r--r--openstackclient/network/v2/network_qos_rule.py218
-rw-r--r--openstackclient/network/v2/network_qos_rule_type.py40
-rw-r--r--openstackclient/network/v2/network_rbac.py173
-rw-r--r--openstackclient/network/v2/network_segment.py101
-rw-r--r--openstackclient/network/v2/network_segment_range.py205
-rw-r--r--openstackclient/network/v2/network_trunk.py207
-rw-r--r--openstackclient/network/v2/port.py458
-rw-r--r--openstackclient/network/v2/router.py412
-rw-r--r--openstackclient/network/v2/security_group.py154
-rw-r--r--openstackclient/network/v2/security_group_rule.py195
-rw-r--r--openstackclient/network/v2/subnet.py456
-rw-r--r--openstackclient/network/v2/subnet_pool.py172
32 files changed, 2889 insertions, 2006 deletions
diff --git a/openstackclient/network/client.py b/openstackclient/network/client.py
index 39936fde..887be52c 100644
--- a/openstackclient/network/client.py
+++ b/openstackclient/network/client.py
@@ -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
diff --git a/openstackclient/network/common.py b/openstackclient/network/common.py
index b1902a6c..63c845cd 100644
--- a/openstackclient/network/common.py
+++ b/openstackclient/network/common.py
@@ -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:
diff --git a/openstackclient/network/v2/address_group.py b/openstackclient/network/v2/address_group.py
index b22fd8aa..7c737184 100644
--- a/openstackclient/network/v2/address_group.py
+++ b/openstackclient/network/v2/address_group.py
@@ -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)
+ )
diff --git a/openstackclient/network/v2/address_scope.py b/openstackclient/network/v2/address_scope.py
index 91f581b5..f6f9c6d3 100644
--- a/openstackclient/network/v2/address_scope.py
+++ b/openstackclient/network/v2/address_scope.py
@@ -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={})
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py
index 22096bc4..f878a389 100644
--- a/openstackclient/network/v2/floating_ip.py
+++ b/openstackclient/network/v2/floating_ip.py
@@ -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)
diff --git a/openstackclient/network/v2/floating_ip_pool.py b/openstackclient/network/v2/floating_ip_pool.py
index 32852004..43d7ac85 100644
--- a/openstackclient/network/v2/floating_ip_pool.py
+++ b/openstackclient/network/v2/floating_ip_pool.py
@@ -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
+ ),
+ )
diff --git a/openstackclient/network/v2/floating_ip_port_forwarding.py b/openstackclient/network/v2/floating_ip_port_forwarding.py
index 0156af8e..324708ae 100644
--- a/openstackclient/network/v2/floating_ip_port_forwarding.py
+++ b/openstackclient/network/v2/floating_ip_port_forwarding.py
@@ -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
diff --git a/openstackclient/network/v2/ip_availability.py b/openstackclient/network/v2/ip_availability.py
index b065ab1e..49b0c07c 100644
--- a/openstackclient/network/v2/ip_availability.py
+++ b/openstackclient/network/v2/ip_availability.py
@@ -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)
diff --git a/openstackclient/network/v2/l3_conntrack_helper.py b/openstackclient/network/v2/l3_conntrack_helper.py
index df153dd8..f55a4613 100644
--- a/openstackclient/network/v2/l3_conntrack_helper.py
+++ b/openstackclient/network/v2/l3_conntrack_helper.py
@@ -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={})
diff --git a/openstackclient/network/v2/local_ip.py b/openstackclient/network/v2/local_ip.py
index e8fb5f8a..0d92f2c1 100644
--- a/openstackclient/network/v2/local_ip.py
+++ b/openstackclient/network/v2/local_ip.py
@@ -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={})
diff --git a/openstackclient/network/v2/local_ip_association.py b/openstackclient/network/v2/local_ip_association.py
index 4cd7707a..d54ac9c9 100644
--- a/openstackclient/network/v2/local_ip_association.py
+++ b/openstackclient/network/v2/local_ip_association.py
@@ -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
+ ),
+ )
diff --git a/openstackclient/network/v2/ndp_proxy.py b/openstackclient/network/v2/ndp_proxy.py
index 25b287f3..8699d2fb 100644
--- a/openstackclient/network/v2/ndp_proxy.py
+++ b/openstackclient/network/v2/ndp_proxy.py
@@ -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)
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py
index 54e2821c..1901e219 100644
--- a/openstackclient/network/v2/network.py
+++ b/openstackclient/network/v2/network.py
@@ -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
diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py
index f67f67bd..085e6cff 100644
--- a/openstackclient/network/v2/network_agent.py
+++ b/openstackclient/network/v2/network_agent.py
@@ -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
diff --git a/openstackclient/network/v2/network_auto_allocated_topology.py b/openstackclient/network/v2/network_auto_allocated_topology.py
index c612f053..b2d0fe1d 100644
--- a/openstackclient/network/v2/network_auto_allocated_topology.py
+++ b/openstackclient/network/v2/network_auto_allocated_topology.py
@@ -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)
diff --git a/openstackclient/network/v2/network_flavor.py b/openstackclient/network/v2/network_flavor.py
index 864184c0..7c088d50 100644
--- a/openstackclient/network/v2/network_flavor.py
+++ b/openstackclient/network/v2/network_flavor.py
@@ -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
diff --git a/openstackclient/network/v2/network_flavor_profile.py b/openstackclient/network/v2/network_flavor_profile.py
index 66c6dcff..c063d5dd 100644
--- a/openstackclient/network/v2/network_flavor_profile.py
+++ b/openstackclient/network/v2/network_flavor_profile.py
@@ -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)
diff --git a/openstackclient/network/v2/network_meter.py b/openstackclient/network/v2/network_meter.py
index 99b0bdd4..d39bc31f 100644
--- a/openstackclient/network/v2/network_meter.py
+++ b/openstackclient/network/v2/network_meter.py
@@ -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
diff --git a/openstackclient/network/v2/network_meter_rule.py b/openstackclient/network/v2/network_meter_rule.py
index 2c50e5a6..4e513e34 100644
--- a/openstackclient/network/v2/network_meter_rule.py
+++ b/openstackclient/network/v2/network_meter_rule.py
@@ -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
diff --git a/openstackclient/network/v2/network_qos_policy.py b/openstackclient/network/v2/network_qos_policy.py
index 29967d7d..ca0f8711 100644
--- a/openstackclient/network/v2/network_qos_policy.py
+++ b/openstackclient/network/v2/network_qos_policy.py
@@ -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)
diff --git a/openstackclient/network/v2/network_qos_rule.py b/openstackclient/network/v2/network_qos_rule.py
index cb2d2339..a6529c8b 100644
--- a/openstackclient/network/v2/network_qos_rule.py
+++ b/openstackclient/network/v2/network_qos_rule.py
@@ -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)
diff --git a/openstackclient/network/v2/network_qos_rule_type.py b/openstackclient/network/v2/network_qos_rule_type.py
index 3f4f6a19..24702070 100644
--- a/openstackclient/network/v2/network_qos_rule_type.py
+++ b/openstackclient/network/v2/network_qos_rule_type.py
@@ -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
diff --git a/openstackclient/network/v2/network_rbac.py b/openstackclient/network/v2/network_rbac.py
index fa4fca7c..cb28ea3b 100644
--- a/openstackclient/network/v2/network_rbac.py
+++ b/openstackclient/network/v2/network_rbac.py
@@ -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
diff --git a/openstackclient/network/v2/network_segment.py b/openstackclient/network/v2/network_segment.py
index c6c88e30..a17f37c0 100644
--- a/openstackclient/network/v2/network_segment.py
+++ b/openstackclient/network/v2/network_segment.py
@@ -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',
- )
-
- return (headers,
- (utils.get_item_properties(
- s, columns,
+ headers = headers + ('Physical Network',)
+ columns = columns + ('physical_network',)
+
+ 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)
diff --git a/openstackclient/network/v2/network_segment_range.py b/openstackclient/network/v2/network_segment_range.py
index 1291d9d8..96a03cf6 100644
--- a/openstackclient/network/v2/network_segment_range.py
+++ b/openstackclient/network/v2/network_segment_range.py
@@ -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)
diff --git a/openstackclient/network/v2/network_trunk.py b/openstackclient/network/v2/network_trunk.py
index c5f62901..6050ba65 100644
--- a/openstackclient/network/v2/network_trunk.py
+++ b/openstackclient/network/v2/network_trunk.py
@@ -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']
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 8bf14d6a..814e82ab 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -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',
action='store_true',
- help=_("No IP or subnet for this port.")
+ help=_("No IP or subnet for this port."),
)
parser.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=JSONKeyValueAction,
- help=_("Custom data to be passed as binding:profile. Data may "
- "be passed as <key>=<value> or JSON. "
- "(repeat option to set multiple binding:profile data)")
+ help=_(
+ "Custom data to be passed as binding:profile. Data may "
+ "be passed as <key>=<value> or JSON. "
+ "(repeat option to set multiple binding:profile data)"
+ ),
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
default=True,
- help=_("Enable port (default)")
+ help=_("Enable port (default)"),
)
admin_group.add_argument(
- '--disable',
- action='store_true',
- help=_("Disable port")
+ '--disable', action='store_true', help=_("Disable port")
)
uplink_status_group = parser.add_mutually_exclusive_group()
uplink_status_group.add_argument(
'--enable-uplink-status-propagation',
action='store_true',
- help=_("Enable uplink status propagate")
+ help=_("Enable uplink status propagate"),
)
uplink_status_group.add_argument(
'--disable-uplink-status-propagation',
action='store_true',
- help=_("Disable uplink status propagate (default)")
+ help=_("Disable uplink status propagate (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)
parser.add_argument(
- 'name',
- metavar='<name>',
- help=_("Name of this port")
+ 'name', metavar='<name>', help=_("Name of this port")
)
parser.add_argument(
'--extra-dhcp-option',
@@ -407,9 +428,12 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
dest='extra_dhcp_options',
required_keys=['name'],
optional_keys=['value', "ip-version"],
- help=_('Extra DHCP options to be assigned to this port: '
- 'name=<name>[,value=<value>,ip-version={4,6}] '
- '(repeat option to set multiple extra DHCP options)'))
+ help=_(
+ 'Extra DHCP options to be assigned to this port: '
+ 'name=<name>[,value=<value>,ip-version={4,6}] '
+ '(repeat option to set multiple extra DHCP options)'
+ ),
+ )
secgroups = parser.add_mutually_exclusive_group()
secgroups.add_argument(
@@ -417,30 +441,32 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
metavar='<security-group>',
action='append',
dest='security_group',
- help=_("Security group to associate with this port (name or ID) "
- "(repeat option to set multiple security groups)")
+ help=_(
+ "Security group to associate with this port (name or ID) "
+ "(repeat option to set multiple security groups)"
+ ),
)
secgroups.add_argument(
'--no-security-group',
dest='no_security_group',
action='store_true',
- help=_("Associate no security groups with this port")
+ help=_("Associate no security groups with this port"),
)
parser.add_argument(
'--qos-policy',
metavar='<qos-policy>',
- help=_("Attach QoS policy to this port (name or ID)")
+ help=_("Attach QoS policy to this port (name or ID)"),
)
port_security = parser.add_mutually_exclusive_group()
port_security.add_argument(
'--enable-port-security',
action='store_true',
- help=_("Enable port security for this port (Default)")
+ help=_("Enable port security for this port (Default)"),
)
port_security.add_argument(
'--disable-port-security',
action='store_true',
- help=_("Disable port security for this port")
+ help=_("Disable port security for this port"),
)
parser.add_argument(
'--allowed-address',
@@ -449,22 +475,25 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
dest='allowed_address_pairs',
required_keys=['ip-address'],
optional_keys=['mac-address'],
- help=_("Add allowed-address pair associated with this port: "
- "ip-address=<ip-address>[,mac-address=<mac-address>] "
- "(repeat option to set multiple allowed-address pairs)")
+ help=_(
+ "Add allowed-address pair associated with this port: "
+ "ip-address=<ip-address>[,mac-address=<mac-address>] "
+ "(repeat option to set multiple allowed-address pairs)"
+ ),
)
parser.add_argument(
'--device-profile',
metavar='<device-profile>',
- help=_('Cyborg port device profile')
+ help=_('Cyborg port device profile'),
)
_tag.add_tag_option_to_parser_for_create(parser, _('port'))
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
- _network = client.find_network(parsed_args.network,
- ignore_missing=False)
+ _network = client.find_network(
+ parsed_args.network, ignore_missing=False
+ )
parsed_args.network = _network.id
_prepare_fixed_ips(self.app.client_manager, parsed_args)
attrs = _get_attrs(self.app.client_manager, parsed_args)
@@ -478,26 +507,29 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
attrs['fixed_ips'] = []
if parsed_args.security_group:
- attrs['security_group_ids'] = [client.find_security_group(
- sg, ignore_missing=False).id
- for sg in
- parsed_args.security_group]
+ attrs['security_group_ids'] = [
+ client.find_security_group(sg, ignore_missing=False).id
+ for sg in parsed_args.security_group
+ ]
elif parsed_args.no_security_group:
attrs['security_group_ids'] = []
if parsed_args.allowed_address_pairs:
- attrs['allowed_address_pairs'] = (
- _convert_address_pairs(parsed_args))
+ attrs['allowed_address_pairs'] = _convert_address_pairs(
+ parsed_args
+ )
if parsed_args.extra_dhcp_options:
attrs["extra_dhcp_opts"] = _convert_extra_dhcp_options(parsed_args)
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
set_tags_in_post = bool(
- client.find_extension('tag-ports-during-bulk-creation'))
+ client.find_extension('tag-ports-during-bulk-creation')
+ )
if set_tags_in_post:
if parsed_args.no_tag:
attrs['tags'] = []
@@ -505,10 +537,12 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs):
attrs['tags'] = list(set(parsed_args.tags))
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_port(**attrs)
if not set_tags_in_post:
@@ -530,7 +564,7 @@ class DeletePort(command.Command):
'port',
metavar="<port>",
nargs="+",
- help=_("Port(s) to delete (name or ID)")
+ help=_("Port(s) to delete (name or ID)"),
)
return parser
@@ -544,14 +578,20 @@ class DeletePort(command.Command):
client.delete_port(obj)
except Exception as e:
result += 1
- LOG.error(_("Failed to delete port with "
- "name or ID '%(port)s': %(e)s"),
- {'port': port, 'e': e})
+ LOG.error(
+ _(
+ "Failed to delete port with "
+ "name or ID '%(port)s': %(e)s"
+ ),
+ {'port': port, 'e': e},
+ )
if result > 0:
total = len(parsed_args.port)
- msg = (_("%(result)s of %(total)s ports failed "
- "to delete.") % {'result': result, 'total': total})
+ msg = _("%(result)s of %(total)s ports failed " "to delete.") % {
+ 'result': result,
+ 'total': total,
+ }
raise exceptions.CommandError(msg)
@@ -565,24 +605,28 @@ class ListPort(command.Lister):
parser.add_argument(
'--device-owner',
metavar='<device-owner>',
- help=_("List only ports with the specified device owner. "
- "This is the entity that uses the port (for example, "
- "network:dhcp).")
+ help=_(
+ "List only ports with the specified device owner. "
+ "This is the entity that uses the port (for example, "
+ "network:dhcp)."
+ ),
)
parser.add_argument(
'--host',
metavar='<host-id>',
- help=_("List only ports bound to this host ID"))
+ help=_("List only ports bound to this host ID"),
+ )
parser.add_argument(
'--network',
metavar='<network>',
- help=_("List only ports connected to this network (name or ID)"))
+ help=_("List only ports connected to this network (name or ID)"),
+ )
device_group = parser.add_mutually_exclusive_group()
device_group.add_argument(
'--router',
metavar='<router>',
dest='router',
- help=_("List only ports attached to this router (name or ID)")
+ help=_("List only ports attached to this router (name or ID)"),
)
device_group.add_argument(
'--server',
@@ -592,47 +636,51 @@ class ListPort(command.Lister):
device_group.add_argument(
'--device-id',
metavar='<device-id>',
- help=_("List only ports with the specified device ID")
+ help=_("List only ports with the specified device ID"),
)
parser.add_argument(
'--mac-address',
metavar='<mac-address>',
- help=_("List only ports with this MAC address")
+ help=_("List only ports with this MAC address"),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
- help=_("List additional fields in output")
+ help=_("List additional fields in output"),
)
parser.add_argument(
'--project',
metavar='<project>',
- help=_("List ports according to their project (name or ID)")
+ help=_("List ports according to their project (name or ID)"),
)
parser.add_argument(
'--name',
metavar='<name>',
- help=_("List ports according to their name")
+ help=_("List ports according to their name"),
)
parser.add_argument(
'--security-group',
action='append',
dest='security_groups',
metavar='<security-group>',
- help=_("List only ports associated with this security group")
+ help=_("List only ports associated with this security group"),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--fixed-ip',
- metavar=('subnet=<subnet>,ip-address=<ip-address>,'
- 'ip-substring=<ip-substring>'),
+ metavar=(
+ 'subnet=<subnet>,ip-address=<ip-address>,'
+ 'ip-substring=<ip-substring>'
+ ),
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address', 'ip-substring'],
- help=_("Desired IP and/or subnet for filtering ports "
- "(name or ID): subnet=<subnet>,ip-address=<ip-address>,"
- "ip-substring=<ip-substring> "
- "(repeat option to set multiple fixed IP addresses)"),
+ help=_(
+ "Desired IP and/or subnet for filtering ports "
+ "(name or ID): subnet=<subnet>,ip-address=<ip-address>,"
+ "ip-substring=<ip-substring> "
+ "(repeat option to set multiple fixed IP addresses)"
+ ),
)
_tag.add_tag_filtering_option_to_parser(parser, _('ports'))
return parser
@@ -665,19 +713,22 @@ class ListPort(command.Lister):
if parsed_args.device_id is not None:
filters['device_id'] = parsed_args.device_id
if parsed_args.router:
- _router = network_client.find_router(parsed_args.router,
- ignore_missing=False)
+ _router = network_client.find_router(
+ parsed_args.router, ignore_missing=False
+ )
filters['device_id'] = _router.id
if parsed_args.server:
compute_client = self.app.client_manager.compute
- server = utils.find_resource(compute_client.servers,
- parsed_args.server)
+ server = utils.find_resource(
+ compute_client.servers, parsed_args.server
+ )
filters['device_id'] = server.id
if parsed_args.host:
filters['binding:host_id'] = parsed_args.host
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
+ )
filters['network_id'] = network.id
if parsed_args.mac_address:
filters['mac_address'] = parsed_args.mac_address
@@ -692,7 +743,8 @@ class ListPort(command.Lister):
filters['name'] = parsed_args.name
if parsed_args.fixed_ip:
filters['fixed_ips'] = _prepare_filter_fixed_ips(
- self.app.client_manager, parsed_args)
+ self.app.client_manager, parsed_args
+ )
if parsed_args.security_groups:
filters['security_groups'] = parsed_args.security_groups
@@ -701,12 +753,19 @@ class ListPort(command.Lister):
data = network_client.ports(fields=columns, **filters)
headers, attrs = utils.calculate_header_and_attrs(
- column_headers, columns, parsed_args)
- return (headers,
- (utils.get_item_properties(
- s, attrs,
+ column_headers, columns, parsed_args
+ )
+ return (
+ headers,
+ (
+ utils.get_item_properties(
+ s,
+ attrs,
formatters=_formatters,
- ) for s in data))
+ )
+ for s in data
+ ),
+ )
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -722,83 +781,87 @@ class SetPort(common.NeutronCommandWithExtraArgs):
'--enable',
action='store_true',
default=None,
- help=_("Enable port")
+ help=_("Enable port"),
)
admin_group.add_argument(
- '--disable',
- action='store_true',
- help=_("Disable port")
+ '--disable', action='store_true', help=_("Disable port")
)
parser.add_argument(
- '--name',
- metavar="<name>",
- help=_("Set port name")
+ '--name', metavar="<name>", help=_("Set port name")
)
parser.add_argument(
'--fixed-ip',
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)"
+ ),
)
parser.add_argument(
'--no-fixed-ip',
action='store_true',
- help=_("Clear existing information of fixed IP addresses."
- "Specify both --fixed-ip and --no-fixed-ip "
- "to overwrite the current fixed IP addresses.")
+ help=_(
+ "Clear existing information of fixed IP addresses."
+ "Specify both --fixed-ip and --no-fixed-ip "
+ "to overwrite the current fixed IP addresses."
+ ),
)
parser.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=JSONKeyValueAction,
- help=_("Custom data to be passed as binding:profile. Data may "
- "be passed as <key>=<value> or JSON. "
- "(repeat option to set multiple binding:profile data)")
+ help=_(
+ "Custom data to be passed as binding:profile. Data may "
+ "be passed as <key>=<value> or JSON. "
+ "(repeat option to set multiple binding:profile data)"
+ ),
)
parser.add_argument(
'--no-binding-profile',
action='store_true',
- help=_("Clear existing information of binding:profile. "
- "Specify both --binding-profile and --no-binding-profile "
- "to overwrite the current binding:profile information.")
+ help=_(
+ "Clear existing information of binding:profile. "
+ "Specify both --binding-profile and --no-binding-profile "
+ "to overwrite the current binding:profile information."
+ ),
)
parser.add_argument(
'--qos-policy',
metavar='<qos-policy>',
- help=_("Attach QoS policy to this port (name or ID)")
+ help=_("Attach QoS policy to this port (name or ID)"),
)
parser.add_argument(
- 'port',
- metavar="<port>",
- help=_("Port to modify (name or ID)")
+ 'port', metavar="<port>", help=_("Port to modify (name or ID)")
)
parser.add_argument(
'--security-group',
metavar='<security-group>',
action='append',
dest='security_group',
- help=_("Security group to associate with this port (name or ID) "
- "(repeat option to set multiple security groups)")
+ help=_(
+ "Security group to associate with this port (name or ID) "
+ "(repeat option to set multiple security groups)"
+ ),
)
parser.add_argument(
'--no-security-group',
dest='no_security_group',
action='store_true',
- help=_("Clear existing security groups associated with this port")
+ help=_("Clear existing security groups associated with this port"),
)
port_security = parser.add_mutually_exclusive_group()
port_security.add_argument(
'--enable-port-security',
action='store_true',
- help=_("Enable port security for this port")
+ help=_("Enable port security for this port"),
)
port_security.add_argument(
'--disable-port-security',
action='store_true',
- help=_("Disable port security for this port")
+ help=_("Disable port security for this port"),
)
parser.add_argument(
'--allowed-address',
@@ -807,18 +870,22 @@ class SetPort(common.NeutronCommandWithExtraArgs):
dest='allowed_address_pairs',
required_keys=['ip-address'],
optional_keys=['mac-address'],
- help=_("Add allowed-address pair associated with this port: "
- "ip-address=<ip-address>[,mac-address=<mac-address>] "
- "(repeat option to set multiple allowed-address pairs)")
+ help=_(
+ "Add allowed-address pair associated with this port: "
+ "ip-address=<ip-address>[,mac-address=<mac-address>] "
+ "(repeat option to set multiple allowed-address pairs)"
+ ),
)
parser.add_argument(
'--no-allowed-address',
dest='no_allowed_address_pair',
action='store_true',
- help=_("Clear existing allowed-address pairs associated "
- "with this port. "
- "(Specify both --allowed-address and --no-allowed-address "
- "to overwrite the current allowed-address pairs)")
+ help=_(
+ "Clear existing allowed-address pairs associated "
+ "with this port. "
+ "(Specify both --allowed-address and --no-allowed-address "
+ "to overwrite the current allowed-address pairs)"
+ ),
)
parser.add_argument(
'--extra-dhcp-option',
@@ -828,16 +895,21 @@ class SetPort(common.NeutronCommandWithExtraArgs):
dest='extra_dhcp_options',
required_keys=['name'],
optional_keys=['value', "ip-version"],
- help=_('Extra DHCP options to be assigned to this port: '
- 'name=<name>[,value=<value>,ip-version={4,6}] '
- '(repeat option to set multiple extra DHCP options)'))
+ help=_(
+ 'Extra DHCP options to be assigned to this port: '
+ 'name=<name>[,value=<value>,ip-version={4,6}] '
+ '(repeat option to set multiple extra DHCP options)'
+ ),
+ )
parser.add_argument(
'--data-plane-status',
metavar='<status>',
choices=['ACTIVE', 'DOWN'],
- help=_("Set data plane status of this port (ACTIVE | DOWN). "
- "Unset it to None with the 'port unset' command "
- "(requires data plane status extension)")
+ help=_(
+ "Set data plane status of this port (ACTIVE | DOWN). "
+ "Unset it to None with the 'port unset' command "
+ "(requires data plane status extension)"
+ ),
)
_tag.add_tag_option_to_parser_for_set(parser, _('port'))
@@ -887,9 +959,9 @@ class SetPort(common.NeutronCommandWithExtraArgs):
attrs['allowed_address_pairs'] = []
if parsed_args.allowed_address_pairs:
if 'allowed_address_pairs' not in attrs:
- attrs['allowed_address_pairs'] = (
- [addr for addr in obj.allowed_address_pairs if addr]
- )
+ attrs['allowed_address_pairs'] = [
+ addr for addr in obj.allowed_address_pairs if addr
+ ]
attrs['allowed_address_pairs'].extend(
_convert_address_pairs(parsed_args)
)
@@ -901,11 +973,13 @@ class SetPort(common.NeutronCommandWithExtraArgs):
attrs['data_plane_status'] = parsed_args.data_plane_status
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_port(obj, **attrs)
# tags is a subresource and it needs to be updated separately.
@@ -918,9 +992,7 @@ class ShowPort(command.ShowOne):
def get_parser(self, prog_name):
parser = super(ShowPort, self).get_parser(prog_name)
parser.add_argument(
- 'port',
- metavar="<port>",
- help=_("Port to display (name or ID)")
+ 'port', metavar="<port>", help=_("Port to display (name or ID)")
)
return parser
@@ -944,30 +1016,36 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
- help=_("Desired IP and/or subnet which should be "
- "removed from this port (name or ID): subnet=<subnet>,"
- "ip-address=<ip-address> (repeat option to unset multiple "
- "fixed IP addresses)"))
+ help=_(
+ "Desired IP and/or subnet which should be "
+ "removed from this port (name or ID): subnet=<subnet>,"
+ "ip-address=<ip-address> (repeat option to unset multiple "
+ "fixed IP addresses)"
+ ),
+ )
parser.add_argument(
'--binding-profile',
metavar='<binding-profile-key>',
action='append',
- help=_("Desired key which should be removed from binding:profile "
- "(repeat option to unset multiple binding:profile data)"))
+ help=_(
+ "Desired key which should be removed from binding:profile "
+ "(repeat option to unset multiple binding:profile data)"
+ ),
+ )
parser.add_argument(
'--security-group',
metavar='<security-group>',
action='append',
dest='security_group_ids',
- help=_("Security group which should be removed this port (name "
- "or ID) (repeat option to unset multiple security groups)")
+ help=_(
+ "Security group which should be removed this port (name "
+ "or ID) (repeat option to unset multiple security groups)"
+ ),
)
parser.add_argument(
- 'port',
- metavar="<port>",
- help=_("Port to modify (name or ID)")
+ 'port', metavar="<port>", help=_("Port to modify (name or ID)")
)
parser.add_argument(
'--allowed-address',
@@ -976,32 +1054,34 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
dest='allowed_address_pairs',
required_keys=['ip-address'],
optional_keys=['mac-address'],
- help=_("Desired allowed-address pair which should be removed "
- "from this port: ip-address=<ip-address>"
- "[,mac-address=<mac-address>] (repeat option to unset "
- "multiple allowed-address pairs)")
+ help=_(
+ "Desired allowed-address pair which should be removed "
+ "from this port: ip-address=<ip-address>"
+ "[,mac-address=<mac-address>] (repeat option to unset "
+ "multiple allowed-address pairs)"
+ ),
)
parser.add_argument(
'--qos-policy',
action='store_true',
default=False,
- help=_("Remove the QoS policy attached to the port")
+ help=_("Remove the QoS policy attached to the port"),
)
parser.add_argument(
'--data-plane-status',
action='store_true',
- help=_("Clear existing information of data plane status")
+ help=_("Clear existing information of data plane status"),
)
parser.add_argument(
'--numa-policy',
action='store_true',
- help=_("Clear existing NUMA affinity policy")
+ help=_("Clear existing NUMA affinity policy"),
)
parser.add_argument(
'--host',
action='store_true',
default=False,
- help=_("Clear host binding for the port.")
+ help=_("Clear host binding for the port."),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('port'))
@@ -1040,7 +1120,8 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
try:
for sg in parsed_args.security_group_ids:
sg_id = client.find_security_group(
- sg, ignore_missing=False).id
+ sg, ignore_missing=False
+ ).id
tmp_secgroups.remove(sg_id)
except ValueError:
msg = _("Port does not contain security group %s") % sg
@@ -1064,7 +1145,8 @@ class UnsetPort(common.NeutronUnsetCommandWithExtraArgs):
attrs['binding:host_id'] = None
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if attrs:
client.update_port(obj, **attrs)
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 8302ee01..e601f98e 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -81,7 +81,8 @@ def _get_columns(item):
invisible_columns.append('is_distributed')
column_map.pop('is_distributed')
return utils.get_osc_show_columns_for_sdk_resource(
- item, column_map, invisible_columns)
+ item, column_map, invisible_columns
+ )
def _get_attrs(client_manager, parsed_args):
@@ -96,8 +97,10 @@ def _get_attrs(client_manager, parsed_args):
attrs['distributed'] = False
if parsed_args.distributed:
attrs['distributed'] = True
- 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
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
@@ -114,7 +117,8 @@ def _get_attrs(client_manager, parsed_args):
gateway_info = {}
n_client = client_manager.network
network = n_client.find_network(
- parsed_args.external_gateway, ignore_missing=False)
+ parsed_args.external_gateway, ignore_missing=False
+ )
gateway_info['network_id'] = network.id
if parsed_args.disable_snat:
gateway_info['enable_snat'] = False
@@ -126,8 +130,9 @@ def _get_attrs(client_manager, parsed_args):
if ip_spec.get('subnet', False):
subnet_name_id = ip_spec.pop('subnet')
if subnet_name_id:
- subnet = n_client.find_subnet(subnet_name_id,
- ignore_missing=False)
+ subnet = n_client.find_subnet(
+ subnet_name_id, ignore_missing=False
+ )
ip_spec['subnet_id'] = subnet.id
if ip_spec.get('ip-address', False):
ip_spec['ip_address'] = ip_spec.pop('ip-address')
@@ -146,20 +151,20 @@ class AddPortToRouter(command.Command):
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router to which port will be added (name or ID)")
+ help=_("Router to which port will be added (name or ID)"),
)
parser.add_argument(
- 'port',
- metavar='<port>',
- help=_("Port to be added (name or ID)")
+ 'port', metavar='<port>', help=_("Port to be added (name or ID)")
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
- client.add_interface_to_router(client.find_router(
- parsed_args.router, ignore_missing=False), port_id=port.id)
+ client.add_interface_to_router(
+ client.find_router(parsed_args.router, ignore_missing=False),
+ port_id=port.id,
+ )
class AddSubnetToRouter(command.Command):
@@ -170,23 +175,22 @@ class AddSubnetToRouter(command.Command):
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router to which subnet will be added (name or ID)")
+ help=_("Router to which subnet will be added (name or ID)"),
)
parser.add_argument(
'subnet',
metavar='<subnet>',
- help=_("Subnet to be added (name or ID)")
+ help=_("Subnet to be added (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
- subnet = client.find_subnet(parsed_args.subnet,
- ignore_missing=False)
+ subnet = client.find_subnet(parsed_args.subnet, ignore_missing=False)
client.add_interface_to_router(
- client.find_router(parsed_args.router,
- ignore_missing=False),
- subnet_id=subnet.id)
+ client.find_router(parsed_args.router, ignore_missing=False),
+ subnet_id=subnet.id,
+ )
class AddExtraRoutesToRouter(command.ShowOne):
@@ -197,8 +201,10 @@ class AddExtraRoutesToRouter(command.ShowOne):
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router to which extra static routes "
- "will be added (name or ID).")
+ help=_(
+ "Router to which extra static routes "
+ "will be added (name or ID)."
+ ),
)
parser.add_argument(
'--route',
@@ -207,14 +213,16 @@ class AddExtraRoutesToRouter(command.ShowOne):
dest='routes',
default=[],
required_keys=['destination', 'gateway'],
- help=_("Add extra static route to the router. "
- "destination: destination subnet (in CIDR notation), "
- "gateway: nexthop IP address. "
- "Repeat option to add multiple routes. "
- "Trying to add a route that's already present "
- "(exactly, including destination and nexthop) "
- "in the routing table is allowed and is considered "
- "a successful operation.")
+ help=_(
+ "Add extra static route to the router. "
+ "destination: destination subnet (in CIDR notation), "
+ "gateway: nexthop IP address. "
+ "Repeat option to add multiple routes. "
+ "Trying to add a route that's already present "
+ "(exactly, including destination and nexthop) "
+ "in the routing table is allowed and is considered "
+ "a successful operation."
+ ),
)
return parser
@@ -225,24 +233,29 @@ class AddExtraRoutesToRouter(command.ShowOne):
client = self.app.client_manager.network
router_obj = client.add_extra_routes_to_router(
client.find_router(parsed_args.router, ignore_missing=False),
- body={'router': {'routes': parsed_args.routes}})
+ body={'router': {'routes': parsed_args.routes}},
+ )
display_columns, columns = _get_columns(router_obj)
data = utils.get_item_properties(
- router_obj, columns, formatters=_formatters)
+ router_obj, columns, formatters=_formatters
+ )
return (display_columns, data)
class RemoveExtraRoutesFromRouter(command.ShowOne):
_description = _(
- "Remove extra static routes from a router's routing table.")
+ "Remove extra static routes from a router's routing table."
+ )
def get_parser(self, prog_name):
parser = super(RemoveExtraRoutesFromRouter, self).get_parser(prog_name)
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router from which extra static routes "
- "will be removed (name or ID).")
+ help=_(
+ "Router from which extra static routes "
+ "will be removed (name or ID)."
+ ),
)
parser.add_argument(
'--route',
@@ -251,14 +264,16 @@ class RemoveExtraRoutesFromRouter(command.ShowOne):
dest='routes',
default=[],
required_keys=['destination', 'gateway'],
- help=_("Remove extra static route from the router. "
- "destination: destination subnet (in CIDR notation), "
- "gateway: nexthop IP address. "
- "Repeat option to remove multiple routes. "
- "Trying to remove a route that's already missing "
- "(fully, including destination and nexthop) "
- "from the routing table is allowed and is considered "
- "a successful operation.")
+ help=_(
+ "Remove extra static route from the router. "
+ "destination: destination subnet (in CIDR notation), "
+ "gateway: nexthop IP address. "
+ "Repeat option to remove multiple routes. "
+ "Trying to remove a route that's already missing "
+ "(fully, including destination and nexthop) "
+ "from the routing table is allowed and is considered "
+ "a successful operation."
+ ),
)
return parser
@@ -269,10 +284,12 @@ class RemoveExtraRoutesFromRouter(command.ShowOne):
client = self.app.client_manager.network
router_obj = client.remove_extra_routes_from_router(
client.find_router(parsed_args.router, ignore_missing=False),
- body={'router': {'routes': parsed_args.routes}})
+ body={'router': {'routes': parsed_args.routes}},
+ )
display_columns, columns = _get_columns(router_obj)
data = utils.get_item_properties(
- router_obj, columns, formatters=_formatters)
+ router_obj, columns, formatters=_formatters
+ )
return (display_columns, data)
@@ -284,53 +301,47 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateRouter, self).get_parser(prog_name)
parser.add_argument(
- 'name',
- metavar='<name>',
- help=_("New router name")
+ 'name', metavar='<name>', help=_("New router name")
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
default=True,
- help=_("Enable router (default)")
+ help=_("Enable router (default)"),
)
admin_group.add_argument(
- '--disable',
- action='store_true',
- help=_("Disable router")
+ '--disable', action='store_true', help=_("Disable router")
)
distribute_group = parser.add_mutually_exclusive_group()
distribute_group.add_argument(
'--distributed',
action='store_true',
- help=_("Create a distributed router")
+ help=_("Create a distributed router"),
)
distribute_group.add_argument(
'--centralized',
action='store_true',
- help=_("Create a centralized router")
+ help=_("Create a centralized router"),
)
ha_group = parser.add_mutually_exclusive_group()
ha_group.add_argument(
'--ha',
action='store_true',
- help=_("Create a highly available router")
+ help=_("Create a highly available router"),
)
ha_group.add_argument(
- '--no-ha',
- action='store_true',
- help=_("Create a legacy router")
+ '--no-ha', action='store_true', help=_("Create a legacy router")
)
parser.add_argument(
'--description',
metavar='<description>',
- help=_("Set router description")
+ help=_("Set router description"),
)
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(
@@ -338,36 +349,40 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
metavar='<availability-zone>',
action='append',
dest='availability_zone_hints',
- help=_("Availability Zone in which to create this router "
- "(Router Availability Zone extension required, "
- "repeat option to set multiple availability zones)")
+ help=_(
+ "Availability Zone in which to create this router "
+ "(Router Availability Zone extension required, "
+ "repeat option to set multiple availability zones)"
+ ),
)
_tag.add_tag_option_to_parser_for_create(parser, _('router'))
parser.add_argument(
'--external-gateway',
metavar="<network>",
- help=_("External Network used as router's gateway (name or ID)")
+ help=_("External Network used as router's gateway (name or ID)"),
)
parser.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
- help=_("Desired IP and/or subnet (name or ID) "
- "on external gateway: "
- "subnet=<subnet>,ip-address=<ip-address> "
- "(repeat option to set multiple fixed IP addresses)")
+ help=_(
+ "Desired IP and/or subnet (name or ID) "
+ "on external gateway: "
+ "subnet=<subnet>,ip-address=<ip-address> "
+ "(repeat option to set multiple fixed IP addresses)"
+ ),
)
snat_group = parser.add_mutually_exclusive_group()
snat_group.add_argument(
'--enable-snat',
action='store_true',
- help=_("Enable Source NAT on external gateway")
+ help=_("Enable Source NAT on external gateway"),
)
snat_group.add_argument(
'--disable-snat',
action='store_true',
- help=_("Disable Source NAT on external gateway")
+ help=_("Disable Source NAT on external gateway"),
)
ndp_proxy_group = parser.add_mutually_exclusive_group()
ndp_proxy_group.add_argument(
@@ -375,14 +390,14 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
dest='enable_ndp_proxy',
default=None,
action='store_true',
- help=_("Enable IPv6 NDP proxy on external gateway")
+ help=_("Enable IPv6 NDP proxy on external gateway"),
)
ndp_proxy_group.add_argument(
'--disable-ndp-proxy',
dest='enable_ndp_proxy',
default=None,
action='store_false',
- help=_("Disable IPv6 NDP proxy on external gateway")
+ help=_("Disable IPv6 NDP proxy on external gateway"),
)
return parser
@@ -396,11 +411,14 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
if parsed_args.no_ha:
attrs['ha'] = False
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if parsed_args.enable_ndp_proxy and not parsed_args.external_gateway:
- msg = (_("You must specify '--external-gateway' in order "
- "to enable router's NDP proxy"))
+ msg = _(
+ "You must specify '--external-gateway' in order "
+ "to enable router's NDP proxy"
+ )
raise exceptions.CommandError(msg)
if parsed_args.enable_ndp_proxy is not None:
@@ -410,10 +428,15 @@ class CreateRouter(command.ShowOne, common.NeutronCommandWithExtraArgs):
# tags cannot be set when created, so tags need to be set later.
_tag.update_tags_for_set(client, obj, parsed_args)
- if (parsed_args.disable_snat or parsed_args.enable_snat or
- parsed_args.fixed_ip) and not parsed_args.external_gateway:
- msg = (_("You must specify '--external-gateway' in order "
- "to specify SNAT or fixed-ip values"))
+ if (
+ parsed_args.disable_snat
+ or parsed_args.enable_snat
+ or parsed_args.fixed_ip
+ ) and not parsed_args.external_gateway:
+ msg = _(
+ "You must specify '--external-gateway' in order "
+ "to specify SNAT or fixed-ip values"
+ )
raise exceptions.CommandError(msg)
display_columns, columns = _get_columns(obj)
@@ -431,7 +454,7 @@ class DeleteRouter(command.Command):
'router',
metavar="<router>",
nargs="+",
- help=_("Router(s) to delete (name or ID)")
+ help=_("Router(s) to delete (name or ID)"),
)
return parser
@@ -445,14 +468,20 @@ class DeleteRouter(command.Command):
client.delete_router(obj)
except Exception as e:
result += 1
- LOG.error(_("Failed to delete router with "
- "name or ID '%(router)s': %(e)s"),
- {'router': router, 'e': e})
+ LOG.error(
+ _(
+ "Failed to delete router with "
+ "name or ID '%(router)s': %(e)s"
+ ),
+ {'router': router, 'e': e},
+ )
if result > 0:
total = len(parsed_args.router)
- msg = (_("%(result)s of %(total)s routers failed "
- "to delete.") % {'result': result, 'total': total})
+ msg = _("%(result)s of %(total)s routers failed " "to delete.") % {
+ 'result': result,
+ 'total': total,
+ }
raise exceptions.CommandError(msg)
@@ -466,35 +495,31 @@ class ListRouter(command.Lister):
parser.add_argument(
'--name',
metavar='<name>',
- help=_("List routers according to their name")
+ help=_("List routers according to their name"),
)
admin_state_group = parser.add_mutually_exclusive_group()
admin_state_group.add_argument(
- '--enable',
- action='store_true',
- help=_("List enabled routers")
+ '--enable', action='store_true', help=_("List enabled routers")
)
admin_state_group.add_argument(
- '--disable',
- action='store_true',
- help=_("List disabled routers")
+ '--disable', action='store_true', help=_("List disabled routers")
)
parser.add_argument(
'--long',
action='store_true',
default=False,
- help=_("List additional fields in output")
+ help=_("List additional fields in output"),
)
parser.add_argument(
'--project',
metavar='<project>',
- help=_("List routers according to their project (name or ID)")
+ help=_("List routers according to their project (name or ID)"),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--agent',
metavar='<agent-id>',
- help=_("List routers hosted by an agent (ID only)")
+ help=_("List routers hosted by an agent (ID only)"),
)
_tag.add_tag_filtering_option_to_parser(parser, _('routers'))
@@ -553,8 +578,10 @@ class ListRouter(command.Lister):
# check if "HA" and "Distributed" columns should be displayed also
data = list(data)
for d in data:
- if (d.is_distributed is not None and
- 'is_distributed' not in columns):
+ if (
+ d.is_distributed is not None
+ and 'is_distributed' not in columns
+ ):
columns = columns + ('is_distributed',)
column_headers = column_headers + ('Distributed',)
if d.is_ha is not None and 'is_ha' not in columns:
@@ -572,20 +599,22 @@ class ListRouter(command.Lister):
# availability zone will be available only when
# router_availability_zone extension is enabled
if client.find_extension("router_availability_zone"):
- columns = columns + (
- 'availability_zones',
- )
- column_headers = column_headers + (
- 'Availability zones',
- )
+ columns = columns + ('availability_zones',)
+ column_headers = column_headers + ('Availability zones',)
columns = columns + ('tags',)
column_headers = column_headers + ('Tags',)
- 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
+ ),
+ )
@staticmethod
def _filter_match(data, conditions):
@@ -610,20 +639,22 @@ class RemovePortFromRouter(command.Command):
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router from which port will be removed (name or ID)")
+ help=_("Router from which port will be removed (name or ID)"),
)
parser.add_argument(
'port',
metavar='<port>',
- help=_("Port to be removed and deleted (name or ID)")
+ help=_("Port to be removed and deleted (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
- client.remove_interface_from_router(client.find_router(
- parsed_args.router, ignore_missing=False), port_id=port.id)
+ client.remove_interface_from_router(
+ client.find_router(parsed_args.router, ignore_missing=False),
+ port_id=port.id,
+ )
class RemoveSubnetFromRouter(command.Command):
@@ -634,23 +665,24 @@ class RemoveSubnetFromRouter(command.Command):
parser.add_argument(
'router',
metavar='<router>',
- help=_("Router from which the subnet will be removed (name or ID)")
+ help=_(
+ "Router from which the subnet will be removed (name or ID)"
+ ),
)
parser.add_argument(
'subnet',
metavar='<subnet>',
- help=_("Subnet to be removed (name or ID)")
+ help=_("Subnet to be removed (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
- subnet = client.find_subnet(parsed_args.subnet,
- ignore_missing=False)
+ subnet = client.find_subnet(parsed_args.subnet, ignore_missing=False)
client.remove_interface_from_router(
- client.find_router(parsed_args.router,
- ignore_missing=False),
- subnet_id=subnet.id)
+ client.find_router(parsed_args.router, ignore_missing=False),
+ subnet_id=subnet.id,
+ )
# TODO(yanxing'an): Use the SDK resource mapped attribute names once the
@@ -663,40 +695,36 @@ class SetRouter(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'router',
metavar="<router>",
- help=_("Router to modify (name or ID)")
+ help=_("Router to modify (name or ID)"),
)
parser.add_argument(
- '--name',
- metavar='<name>',
- help=_("Set router name")
+ '--name', metavar='<name>', help=_("Set router name")
)
parser.add_argument(
'--description',
metavar='<description>',
- help=_('Set router description')
+ help=_('Set router description'),
)
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
action='store_true',
default=None,
- help=_("Enable router")
+ help=_("Enable router"),
)
admin_group.add_argument(
- '--disable',
- action='store_true',
- help=_("Disable router")
+ '--disable', action='store_true', help=_("Disable router")
)
distribute_group = parser.add_mutually_exclusive_group()
distribute_group.add_argument(
'--distributed',
action='store_true',
- help=_("Set router to distributed mode (disabled router only)")
+ help=_("Set router to distributed mode (disabled router only)"),
)
distribute_group.add_argument(
'--centralized',
action='store_true',
- help=_("Set router to centralized mode (disabled router only)")
+ help=_("Set router to centralized mode (disabled router only)"),
)
parser.add_argument(
'--route',
@@ -705,60 +733,69 @@ class SetRouter(common.NeutronCommandWithExtraArgs):
dest='routes',
default=None,
required_keys=['destination', 'gateway'],
- help=_("Add routes to the router "
- "destination: destination subnet (in CIDR notation) "
- "gateway: nexthop IP address "
- "(repeat option to add multiple routes). "
- "This is deprecated in favor of 'router add/remove route' "
- "since it is prone to race conditions between concurrent "
- "clients when not used together with --no-route to "
- "overwrite the current value of 'routes'.")
+ help=_(
+ "Add routes to the router "
+ "destination: destination subnet (in CIDR notation) "
+ "gateway: nexthop IP address "
+ "(repeat option to add multiple routes). "
+ "This is deprecated in favor of 'router add/remove route' "
+ "since it is prone to race conditions between concurrent "
+ "clients when not used together with --no-route to "
+ "overwrite the current value of 'routes'."
+ ),
)
parser.add_argument(
'--no-route',
action='store_true',
- help=_("Clear routes associated with the router. "
- "Specify both --route and --no-route to overwrite "
- "current value of routes.")
+ help=_(
+ "Clear routes associated with the router. "
+ "Specify both --route and --no-route to overwrite "
+ "current value of routes."
+ ),
)
routes_ha = parser.add_mutually_exclusive_group()
routes_ha.add_argument(
'--ha',
action='store_true',
- help=_("Set the router as highly available "
- "(disabled router only)")
+ help=_(
+ "Set the router as highly available " "(disabled router only)"
+ ),
)
routes_ha.add_argument(
'--no-ha',
action='store_true',
- help=_("Clear high availability attribute of the router "
- "(disabled router only)")
+ help=_(
+ "Clear high availability attribute of the router "
+ "(disabled router only)"
+ ),
)
parser.add_argument(
'--external-gateway',
metavar="<network>",
- help=_("External Network used as router's gateway (name or ID)")
+ help=_("External Network used as router's gateway (name or ID)"),
)
parser.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
optional_keys=['subnet', 'ip-address'],
- help=_("Desired IP and/or subnet (name or ID) "
- "on external gateway: "
- "subnet=<subnet>,ip-address=<ip-address> "
- "(repeat option to set multiple fixed IP addresses)")
+ help=_(
+ "Desired IP and/or subnet (name or ID) "
+ "on external gateway: "
+ "subnet=<subnet>,ip-address=<ip-address> "
+ "(repeat option to set multiple fixed IP addresses)"
+ ),
)
snat_group = parser.add_mutually_exclusive_group()
snat_group.add_argument(
'--enable-snat',
action='store_true',
- help=_("Enable Source NAT on external gateway")
+ help=_("Enable Source NAT on external gateway"),
)
snat_group.add_argument(
'--disable-snat',
action='store_true',
- help=_("Disable Source NAT on external gateway")
+ help=_("Disable Source NAT on external gateway"),
)
ndp_proxy_group = parser.add_mutually_exclusive_group()
ndp_proxy_group.add_argument(
@@ -766,25 +803,25 @@ class SetRouter(common.NeutronCommandWithExtraArgs):
dest='enable_ndp_proxy',
default=None,
action='store_true',
- help=_("Enable IPv6 NDP proxy on external gateway")
+ help=_("Enable IPv6 NDP proxy on external gateway"),
)
ndp_proxy_group.add_argument(
'--disable-ndp-proxy',
dest='enable_ndp_proxy',
default=None,
action='store_false',
- help=_("Disable IPv6 NDP proxy on external gateway")
+ help=_("Disable IPv6 NDP proxy on external gateway"),
)
qos_policy_group = parser.add_mutually_exclusive_group()
qos_policy_group.add_argument(
'--qos-policy',
metavar='<qos-policy>',
- help=_("Attach QoS policy to router gateway IPs")
+ help=_("Attach QoS policy to router gateway IPs"),
)
qos_policy_group.add_argument(
'--no-qos-policy',
action='store_true',
- help=_("Remove QoS policy from router gateway IPs")
+ help=_("Remove QoS policy from router gateway IPs"),
)
_tag.add_tag_option_to_parser_for_set(parser, _('router'))
return parser
@@ -812,20 +849,28 @@ class SetRouter(common.NeutronCommandWithExtraArgs):
attrs['routes'] += obj.routes
elif parsed_args.no_route:
attrs['routes'] = []
- if (parsed_args.disable_snat or parsed_args.enable_snat or
- parsed_args.fixed_ip) and not parsed_args.external_gateway:
- msg = (_("You must specify '--external-gateway' in order "
- "to update the SNAT or fixed-ip values"))
+ if (
+ parsed_args.disable_snat
+ or parsed_args.enable_snat
+ or parsed_args.fixed_ip
+ ) and not parsed_args.external_gateway:
+ msg = _(
+ "You must specify '--external-gateway' in order "
+ "to update the SNAT or fixed-ip values"
+ )
raise exceptions.CommandError(msg)
- if ((parsed_args.qos_policy or parsed_args.no_qos_policy) and
- not parsed_args.external_gateway):
+ if (
+ parsed_args.qos_policy or parsed_args.no_qos_policy
+ ) and not parsed_args.external_gateway:
try:
original_net_id = obj.external_gateway_info['network_id']
except (KeyError, TypeError):
- msg = (_("You must specify '--external-gateway' or the router "
- "must already have an external network in order to "
- "set router gateway IP QoS"))
+ msg = _(
+ "You must specify '--external-gateway' or the router "
+ "must already have an external network in order to "
+ "set router gateway IP QoS"
+ )
raise exceptions.CommandError(msg)
else:
if not attrs.get('external_gateway_info'):
@@ -833,14 +878,16 @@ class SetRouter(common.NeutronCommandWithExtraArgs):
attrs['external_gateway_info']['network_id'] = original_net_id
if parsed_args.qos_policy:
check_qos_id = client.find_qos_policy(
- parsed_args.qos_policy, ignore_missing=False).id
+ parsed_args.qos_policy, ignore_missing=False
+ ).id
attrs['external_gateway_info']['qos_policy_id'] = check_qos_id
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
attrs['external_gateway_info']['qos_policy_id'] = None
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if parsed_args.enable_ndp_proxy is not None:
attrs['enable_ndp_proxy'] = parsed_args.enable_ndp_proxy
@@ -859,7 +906,7 @@ class ShowRouter(command.ShowOne):
parser.add_argument(
'router',
metavar="<router>",
- help=_("Router to display (name or ID)")
+ help=_("Router to display (name or ID)"),
)
return parser
@@ -875,7 +922,7 @@ class ShowRouter(command.ShowOne):
int_info = {
'port_id': port.id,
'ip_address': ip_spec.get('ip_address'),
- 'subnet_id': ip_spec.get('subnet_id')
+ 'subnet_id': ip_spec.get('subnet_id'),
}
interfaces_info.append(int_info)
@@ -899,25 +946,29 @@ class UnsetRouter(common.NeutronUnsetCommandWithExtraArgs):
dest='routes',
default=None,
required_keys=['destination', 'gateway'],
- help=_("Routes to be removed from the router "
- "destination: destination subnet (in CIDR notation) "
- "gateway: nexthop IP address "
- "(repeat option to unset multiple routes)"))
+ help=_(
+ "Routes to be removed from the router "
+ "destination: destination subnet (in CIDR notation) "
+ "gateway: nexthop IP address "
+ "(repeat option to unset multiple routes)"
+ ),
+ )
parser.add_argument(
'--external-gateway',
action='store_true',
default=False,
- help=_("Remove external gateway information from the router"))
+ help=_("Remove external gateway information from the router"),
+ )
parser.add_argument(
'--qos-policy',
action='store_true',
default=False,
- help=_("Remove QoS policy from router gateway IPs")
+ help=_("Remove QoS policy from router gateway IPs"),
)
parser.add_argument(
'router',
metavar="<router>",
- help=_("Router to modify (name or ID)")
+ help=_("Router to modify (name or ID)"),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('router'))
return parser
@@ -934,13 +985,15 @@ class UnsetRouter(common.NeutronUnsetCommandWithExtraArgs):
route['nexthop'] = route.pop('gateway')
tmp_routes.remove(route)
except ValueError:
- msg = (_("Router does not contain route %s") % route)
+ msg = _("Router does not contain route %s") % route
raise exceptions.CommandError(msg)
attrs['routes'] = tmp_routes
if parsed_args.qos_policy:
try:
- if (tmp_external_gateway_info['network_id'] and
- tmp_external_gateway_info['qos_policy_id']):
+ if (
+ tmp_external_gateway_info['network_id']
+ and tmp_external_gateway_info['qos_policy_id']
+ ):
pass
except (KeyError, TypeError):
msg = _("Router does not have external network or qos policy")
@@ -948,14 +1001,15 @@ class UnsetRouter(common.NeutronUnsetCommandWithExtraArgs):
else:
attrs['external_gateway_info'] = {
'network_id': tmp_external_gateway_info['network_id'],
- 'qos_policy_id': None
+ 'qos_policy_id': None,
}
if parsed_args.external_gateway:
attrs['external_gateway_info'] = {}
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if attrs:
client.update_router(obj, **attrs)
diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py
index ffad9988..6de9cad3 100644
--- a/openstackclient/network/v2/security_group.py
+++ b/openstackclient/network/v2/security_group.py
@@ -92,28 +92,25 @@ def _get_columns(item):
}
hidden_columns = ['location']
return utils.get_osc_show_columns_for_sdk_resource(
- item,
- column_map,
- hidden_columns
+ item, column_map, hidden_columns
)
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
-class CreateSecurityGroup(common.NetworkAndComputeShowOne,
- common.NeutronCommandWithExtraArgs):
+class CreateSecurityGroup(
+ common.NetworkAndComputeShowOne, common.NeutronCommandWithExtraArgs
+):
_description = _("Create a new security group")
def update_parser_common(self, parser):
parser.add_argument(
- "name",
- metavar="<name>",
- help=_("New security group name")
+ "name", metavar="<name>", help=_("New security group name")
)
parser.add_argument(
"--description",
metavar="<description>",
- help=_("Security group description")
+ help=_("Security group description"),
)
return parser
@@ -121,26 +118,27 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne,
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)")),
)
stateful_group = parser.add_mutually_exclusive_group()
stateful_group.add_argument(
"--stateful",
action='store_true',
default=None,
- help=_("Security group is stateful (Default)")
+ help=_("Security group is stateful (Default)"),
)
stateful_group.add_argument(
"--stateless",
action='store_true',
default=None,
- help=_("Security group is stateless")
+ help=_("Security group is stateless"),
)
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, _('security group'),
- enhance_help=self.enhance_help_neutron)
+ parser, _('security group'), enhance_help=self.enhance_help_neutron
+ )
return parser
def _get_description(self, parsed_args):
@@ -167,7 +165,8 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne,
).id
attrs['project_id'] = project_id
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
# Create the security group and display the results.
obj = client.create_security_group(**attrs)
@@ -175,9 +174,7 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne,
_tag.update_tags_for_set(client, obj, parsed_args)
display_columns, property_columns = _get_columns(obj)
data = utils.get_item_properties(
- obj,
- property_columns,
- formatters=_formatters_network
+ obj, property_columns, formatters=_formatters_network
)
return (display_columns, data)
@@ -189,9 +186,7 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne,
)
display_columns, property_columns = _get_columns(obj)
data = utils.get_dict_properties(
- obj,
- property_columns,
- formatters=_formatters_compute
+ obj, property_columns, formatters=_formatters_compute
)
return (display_columns, data)
@@ -241,14 +236,18 @@ class ListSecurityGroup(common.NetworkAndComputeLister):
'--project',
metavar='<project>',
help=self.enhance_help_neutron(
- _("List security groups according to the project (name or "
- "ID)"))
+ _(
+ "List security groups according to the 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
+ )
_tag.add_tag_filtering_option_to_parser(
- parser, _('security group'),
- enhance_help=self.enhance_help_neutron)
+ parser, _('security group'), enhance_help=self.enhance_help_neutron
+ )
return parser
def update_parser_compute(self, parser):
@@ -257,7 +256,8 @@ class ListSecurityGroup(common.NetworkAndComputeLister):
action='store_true',
default=False,
help=self.enhance_help_nova_network(
- _("Display information from all projects (admin only)"))
+ _("Display information from all projects (admin only)")
+ ),
)
return parser
@@ -273,27 +273,22 @@ class ListSecurityGroup(common.NetworkAndComputeLister):
filters['project_id'] = project_id
_tag.get_tag_filtering_args(parsed_args, filters)
- data = client.security_groups(fields=self.FIELDS_TO_RETRIEVE,
- **filters)
-
- columns = (
- "ID",
- "Name",
- "Description",
- "Project ID",
- "tags"
+ data = client.security_groups(
+ fields=self.FIELDS_TO_RETRIEVE, **filters
)
- column_headers = (
- "ID",
- "Name",
- "Description",
- "Project",
- "Tags"
+
+ columns = ("ID", "Name", "Description", "Project ID", "tags")
+ column_headers = ("ID", "Name", "Description", "Project", "Tags")
+ 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))
def take_action_compute(self, client, parsed_args):
search = {'all_tenants': parsed_args.all_projects}
@@ -311,56 +306,62 @@ class ListSecurityGroup(common.NetworkAndComputeLister):
if parsed_args.all_projects:
columns = columns + ('Tenant ID',)
column_headers = column_headers + ('Project',)
- return (column_headers,
- (utils.get_dict_properties(
- s, columns,
- ) for s in data))
+ return (
+ column_headers,
+ (
+ utils.get_dict_properties(
+ s,
+ columns,
+ )
+ for s in data
+ ),
+ )
-class SetSecurityGroup(common.NetworkAndComputeCommand,
- common.NeutronCommandWithExtraArgs):
+class SetSecurityGroup(
+ common.NetworkAndComputeCommand, common.NeutronCommandWithExtraArgs
+):
_description = _("Set security group properties")
def update_parser_common(self, parser):
parser.add_argument(
'group',
metavar='<group>',
- help=_("Security group to modify (name or ID)")
+ help=_("Security group to modify (name or ID)"),
)
parser.add_argument(
- '--name',
- metavar='<new-name>',
- help=_("New security group name")
+ '--name', metavar='<new-name>', help=_("New security group name")
)
parser.add_argument(
"--description",
metavar="<description>",
- help=_("New security group description")
+ help=_("New security group description"),
)
stateful_group = parser.add_mutually_exclusive_group()
stateful_group.add_argument(
"--stateful",
action='store_true',
default=None,
- help=_("Security group is stateful (Default)")
+ help=_("Security group is stateful (Default)"),
)
stateful_group.add_argument(
"--stateless",
action='store_true',
default=None,
- help=_("Security group is stateless")
+ help=_("Security group is stateless"),
)
return parser
def update_parser_network(self, parser):
_tag.add_tag_option_to_parser_for_set(
- parser, _('security group'),
- enhance_help=self.enhance_help_neutron)
+ parser, _('security group'), enhance_help=self.enhance_help_neutron
+ )
return parser
def take_action_network(self, client, parsed_args):
- obj = client.find_security_group(parsed_args.group,
- ignore_missing=False)
+ obj = client.find_security_group(
+ parsed_args.group, ignore_missing=False
+ )
attrs = {}
if parsed_args.name is not None:
attrs['name'] = parsed_args.name
@@ -371,7 +372,8 @@ class SetSecurityGroup(common.NetworkAndComputeCommand,
if parsed_args.stateless:
attrs['stateful'] = False
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
# NOTE(rtheis): Previous behavior did not raise a CommandError
# if there were no updates. Maintain this behavior and issue
# the update.
@@ -405,18 +407,17 @@ class ShowSecurityGroup(common.NetworkAndComputeShowOne):
parser.add_argument(
'group',
metavar='<group>',
- help=_("Security group to display (name or ID)")
+ help=_("Security group to display (name or ID)"),
)
return parser
def take_action_network(self, client, parsed_args):
- obj = client.find_security_group(parsed_args.group,
- ignore_missing=False)
+ obj = client.find_security_group(
+ parsed_args.group, ignore_missing=False
+ )
display_columns, property_columns = _get_columns(obj)
data = utils.get_item_properties(
- obj,
- property_columns,
- formatters=_formatters_network
+ obj, property_columns, formatters=_formatters_network
)
return (display_columns, data)
@@ -424,9 +425,7 @@ class ShowSecurityGroup(common.NetworkAndComputeShowOne):
obj = client.api.security_group_find(parsed_args.group)
display_columns, property_columns = _get_columns(obj)
data = utils.get_dict_properties(
- obj,
- property_columns,
- formatters=_formatters_compute
+ obj, property_columns, formatters=_formatters_compute
)
return (display_columns, data)
@@ -439,15 +438,16 @@ class UnsetSecurityGroup(command.Command):
parser.add_argument(
'group',
metavar="<group>",
- help=_("Security group to modify (name or ID)")
+ help=_("Security group to modify (name or ID)"),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('security group'))
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
- obj = client.find_security_group(parsed_args.group,
- ignore_missing=False)
+ obj = client.find_security_group(
+ parsed_args.group, ignore_missing=False
+ )
# tags is a subresource and it needs to be updated separately.
_tag.update_tags_for_unset(client, obj, parsed_args)
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py
index 2179f33d..24a1fcfb 100644
--- a/openstackclient/network/v2/security_group_rule.py
+++ b/openstackclient/network/v2/security_group_rule.py
@@ -74,9 +74,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
)
@@ -105,23 +103,26 @@ def _is_icmp_protocol(protocol):
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
-class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
- common.NeutronCommandWithExtraArgs):
+class CreateSecurityGroupRule(
+ common.NetworkAndComputeShowOne, common.NeutronCommandWithExtraArgs
+):
_description = _("Create a new security group rule")
def update_parser_common(self, parser):
parser.add_argument(
'group',
metavar='<group>',
- help=_("Create rule in this security group (name or ID)")
+ help=_("Create rule in this security group (name or ID)"),
)
remote_group = parser.add_mutually_exclusive_group()
remote_group.add_argument(
"--remote-ip",
metavar="<ip-address>",
- help=_("Remote IP address block (may use CIDR notation; "
- "default for IPv4 rule: 0.0.0.0/0, "
- "default for IPv6 rule: ::/0)"),
+ help=_(
+ "Remote IP address block (may use CIDR notation; "
+ "default for IPv4 rule: 0.0.0.0/0, "
+ "default for IPv6 rule: ::/0)"
+ ),
)
remote_group.add_argument(
"--remote-group",
@@ -150,9 +151,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
'--dst-port',
metavar='<port-range>',
action=parseractions.RangeAction,
- help=_("Destination port, may be a single port or a starting and "
- "ending port range: 137:139. Required for IP protocols TCP "
- "and UDP. Ignored for ICMP IP protocols."),
+ help=_(
+ "Destination port, may be a single port or a starting and "
+ "ending port range: 137:139. Required for IP protocols TCP "
+ "and UDP. Ignored for ICMP IP protocols."
+ ),
**dst_port_default
)
@@ -170,7 +173,8 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
"IP protocol (ah, dccp, egp, esp, gre, icmp, igmp, ipv6-encap, "
"ipv6-frag, ipv6-icmp, ipv6-nonxt, ipv6-opts, ipv6-route, ospf, "
"pgm, rsvp, sctp, tcp, udp, udplite, vrrp and integer "
- "representations [0-255] or any; default: any (all protocols))")
+ "representations [0-255] or any; default: any (all protocols))"
+ )
if self.is_nova_network:
protocol_help = protocol_help_compute
elif self.is_neutron:
@@ -178,7 +182,8 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
else:
# Docs build: compose help for both nova-network and neutron
protocol_help = self.split_help(
- protocol_help_network, protocol_help_compute)
+ protocol_help_network, protocol_help_compute
+ )
protocol_group.add_argument(
'--protocol',
@@ -203,34 +208,39 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
'--description',
metavar='<description>',
help=self.enhance_help_neutron(
- _("Set security group rule description"))
+ _("Set security group rule description")
+ ),
)
parser.add_argument(
'--icmp-type',
metavar='<icmp-type>',
type=int,
help=self.enhance_help_neutron(
- _("ICMP type for ICMP IP protocols"))
+ _("ICMP type for ICMP IP protocols")
+ ),
)
parser.add_argument(
'--icmp-code',
metavar='<icmp-code>',
type=int,
help=self.enhance_help_neutron(
- _("ICMP code for ICMP IP protocols"))
+ _("ICMP code for ICMP IP protocols")
+ ),
)
direction_group = parser.add_mutually_exclusive_group()
direction_group.add_argument(
'--ingress',
action='store_true',
help=self.enhance_help_neutron(
- _("Rule applies to incoming network traffic (default)"))
+ _("Rule applies to incoming network traffic (default)")
+ ),
)
direction_group.add_argument(
'--egress',
action='store_true',
help=self.enhance_help_neutron(
- _("Rule applies to outgoing network traffic"))
+ _("Rule applies to outgoing network traffic")
+ ),
)
parser.add_argument(
'--ethertype',
@@ -238,16 +248,20 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
choices=['IPv4', 'IPv6'],
type=_convert_ipvx_case,
help=self.enhance_help_neutron(
- _("Ethertype of network traffic "
- "(IPv4, IPv6; default: based on IP protocol)"))
+ _(
+ "Ethertype of network traffic "
+ "(IPv4, IPv6; default: based on IP protocol)"
+ )
+ ),
)
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)")),
)
identity_common.add_project_domain_option_to_parser(
- parser, enhance_help=self.enhance_help_neutron)
+ parser, enhance_help=self.enhance_help_neutron
+ )
return parser
def _get_protocol(self, parsed_args, default_protocol='any'):
@@ -273,8 +287,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
# However, while the OSC CLI doesn't document the protocol,
# the code must still handle it. In addition, handle both
# protocol names and numbers.
- if (protocol is not None and protocol.startswith('ipv6-') or
- protocol in ['icmpv6', '41', '43', '44', '58', '59', '60']):
+ if (
+ protocol is not None
+ and protocol.startswith('ipv6-')
+ or protocol in ['icmpv6', '41', '43', '44', '58', '59', '60']
+ ):
return True
else:
return False
@@ -282,8 +299,7 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
def take_action_network(self, client, parsed_args):
# Get the security group ID to hold the rule.
security_group_id = client.find_security_group(
- parsed_args.group,
- ignore_missing=False
+ parsed_args.group, ignore_missing=False
).id
# Build the create attributes.
@@ -302,24 +318,31 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
# NOTE(rtheis): Use ethertype specified else default based
# on IP protocol.
- attrs['ethertype'] = self._get_ethertype(parsed_args,
- attrs['protocol'])
+ attrs['ethertype'] = self._get_ethertype(
+ parsed_args, attrs['protocol']
+ )
# NOTE(rtheis): Validate the port range and ICMP type and code.
# It would be ideal if argparse could do this.
- if parsed_args.dst_port and (parsed_args.icmp_type or
- parsed_args.icmp_code):
- msg = _('Argument --dst-port not allowed with arguments '
- '--icmp-type and --icmp-code')
+ if parsed_args.dst_port and (
+ parsed_args.icmp_type or parsed_args.icmp_code
+ ):
+ msg = _(
+ 'Argument --dst-port not allowed with arguments '
+ '--icmp-type and --icmp-code'
+ )
raise exceptions.CommandError(msg)
if parsed_args.icmp_type is None and parsed_args.icmp_code is not None:
msg = _('Argument --icmp-type required with argument --icmp-code')
raise exceptions.CommandError(msg)
is_icmp_protocol = _is_icmp_protocol(attrs['protocol'])
- if not is_icmp_protocol and (parsed_args.icmp_type or
- parsed_args.icmp_code):
- msg = _('ICMP IP protocol required with arguments '
- '--icmp-type and --icmp-code')
+ if not is_icmp_protocol and (
+ parsed_args.icmp_type or parsed_args.icmp_code
+ ):
+ msg = _(
+ 'ICMP IP protocol required with arguments '
+ '--icmp-type and --icmp-code'
+ )
raise exceptions.CommandError(msg)
# NOTE(rtheis): For backwards compatibility, continue ignoring
# the destination port range when an ICMP IP protocol is specified.
@@ -333,13 +356,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
if parsed_args.remote_group is not None:
attrs['remote_group_id'] = client.find_security_group(
- parsed_args.remote_group,
- ignore_missing=False
+ parsed_args.remote_group, ignore_missing=False
).id
elif parsed_args.remote_address_group is not None:
attrs['remote_address_group_id'] = client.find_address_group(
- parsed_args.remote_address_group,
- ignore_missing=False
+ parsed_args.remote_address_group, ignore_missing=False
).id
elif parsed_args.remote_ip is not None:
attrs['remote_ip_prefix'] = parsed_args.remote_ip
@@ -358,7 +379,8 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne,
attrs['project_id'] = project_id
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
# Create and show the security group rule.
obj = client.create_security_group_rule(**attrs)
@@ -407,13 +429,12 @@ class DeleteSecurityGroupRule(common.NetworkAndComputeDelete):
'rule',
metavar='<rule>',
nargs="+",
- help=_("Security group rule(s) to delete (ID only)")
+ help=_("Security group rule(s) to delete (ID only)"),
)
return parser
def take_action_network(self, client, parsed_args):
- obj = client.find_security_group_rule(
- self.r, ignore_missing=False)
+ obj = client.find_security_group_rule(self.r, ignore_missing=False)
client.delete_security_group_rule(obj)
def take_action_compute(self, client, parsed_args):
@@ -439,7 +460,7 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
'group',
metavar='<group>',
nargs='?',
- help=_("List all rules in this security group (name or ID)")
+ help=_("List all rules in this security group (name or ID)"),
)
return parser
@@ -451,7 +472,7 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
'--all-projects',
action='store_true',
default=False,
- help=argparse.SUPPRESS
+ help=argparse.SUPPRESS,
)
parser.add_argument(
@@ -459,38 +480,46 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
metavar='<protocol>',
type=_convert_to_lowercase,
help=self.enhance_help_neutron(
- _("List rules by the IP protocol (ah, dhcp, egp, esp, gre, "
- "icmp, igmp, ipv6-encap, ipv6-frag, ipv6-icmp, ipv6-nonxt, "
- "ipv6-opts, ipv6-route, ospf, pgm, rsvp, sctp, tcp, udp, "
- "udplite, vrrp and integer representations [0-255] or any; "
- "default: any (all protocols))"))
+ _(
+ "List rules by the IP protocol (ah, dhcp, egp, esp, gre, "
+ "icmp, igmp, ipv6-encap, ipv6-frag, ipv6-icmp, "
+ "ipv6-nonxt, ipv6-opts, ipv6-route, ospf, pgm, rsvp, "
+ "sctp, tcp, udp, udplite, vrrp and integer "
+ "representations [0-255] or any; "
+ "default: any (all protocols))"
+ )
+ ),
)
parser.add_argument(
'--ethertype',
metavar='<ethertype>',
type=_convert_to_lowercase,
help=self.enhance_help_neutron(
- _("List rules by the Ethertype (IPv4 or IPv6)"))
+ _("List rules by the Ethertype (IPv4 or IPv6)")
+ ),
)
direction_group = parser.add_mutually_exclusive_group()
direction_group.add_argument(
'--ingress',
action='store_true',
help=self.enhance_help_neutron(
- _("List rules applied to incoming network traffic"))
+ _("List rules applied to incoming network traffic")
+ ),
)
direction_group.add_argument(
'--egress',
action='store_true',
help=self.enhance_help_neutron(
- _("List rules applied to outgoing network traffic"))
+ _("List rules applied to outgoing network traffic")
+ ),
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help=self.enhance_help_neutron(
- _("**Deprecated** This argument is no longer needed"))
+ _("**Deprecated** This argument is no longer needed")
+ ),
)
return parser
@@ -500,7 +529,8 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
action='store_true',
default=False,
help=self.enhance_help_nova_network(
- _("Display information from all projects (admin only)"))
+ _("Display information from all projects (admin only)")
+ ),
)
if not self.is_docs_build:
# Accept but hide the argument for consistency with network.
@@ -509,7 +539,7 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
'--long',
action='store_false',
default=False,
- help=argparse.SUPPRESS
+ help=argparse.SUPPRESS,
)
return parser
@@ -531,9 +561,10 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
def take_action_network(self, client, parsed_args):
if parsed_args.long:
- self.log.warning(_(
+ msg = _(
"The --long option has been deprecated and is no longer needed"
- ))
+ )
+ self.log.warning(msg)
column_headers = self._get_column_headers(parsed_args)
columns = (
@@ -554,8 +585,7 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
# does not contain security group rules resources. So use
# the security group ID in a query to get the resources.
security_group_id = client.find_security_group(
- parsed_args.group,
- ignore_missing=False
+ parsed_args.group, ignore_missing=False
).id
query = {'security_group_id': security_group_id}
else:
@@ -573,10 +603,16 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
for r in client.security_group_rules(**query)
]
- return (column_headers,
- (utils.get_dict_properties(
- s, columns,
- ) for s in rules))
+ return (
+ column_headers,
+ (
+ utils.get_dict_properties(
+ s,
+ columns,
+ )
+ for s in rules
+ ),
+ )
def take_action_compute(self, client, parsed_args):
column_headers = self._get_column_headers(parsed_args)
@@ -612,10 +648,16 @@ class ListSecurityGroupRule(common.NetworkAndComputeLister):
# network_utils.transform_compute_security_group_rule(rule),
# ))
- return (column_headers,
- (utils.get_dict_properties(
- s, columns,
- ) for s in rules))
+ return (
+ column_headers,
+ (
+ utils.get_dict_properties(
+ s,
+ columns,
+ )
+ for s in rules
+ ),
+ )
class ShowSecurityGroupRule(common.NetworkAndComputeShowOne):
@@ -625,13 +667,14 @@ class ShowSecurityGroupRule(common.NetworkAndComputeShowOne):
parser.add_argument(
'rule',
metavar="<rule>",
- help=_("Security group rule to display (ID only)")
+ help=_("Security group rule to display (ID only)"),
)
return parser
def take_action_network(self, client, parsed_args):
- obj = client.find_security_group_rule(parsed_args.rule,
- ignore_missing=False)
+ obj = client.find_security_group_rule(
+ parsed_args.rule, ignore_missing=False
+ )
# necessary for old rules that have None in this field
if not obj['remote_ip_prefix']:
obj['remote_ip_prefix'] = _format_remote_ip_prefix(obj)
@@ -654,8 +697,10 @@ class ShowSecurityGroupRule(common.NetworkAndComputeShowOne):
break
if obj is None:
- msg = _("Could not find security group rule "
- "with ID '%s'") % parsed_args.rule
+ msg = (
+ _("Could not find security group rule " "with ID '%s'")
+ % parsed_args.rule
+ )
raise exceptions.CommandError(msg)
# NOTE(rtheis): Format security group rule
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 8e3a877f..32b2493a 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -36,16 +36,19 @@ def _update_arguments(obj_list, parsed_args_list, option):
try:
obj_list.remove(item)
except ValueError:
- msg = (_("Subnet does not contain %(option)s %(value)s") %
- {'option': option, 'value': item})
+ msg = _("Subnet does not contain %(option)s %(value)s") % {
+ 'option': option,
+ 'value': item,
+ }
raise exceptions.CommandError(msg)
class AllocationPoolsColumn(cliff_columns.FormattableColumn):
def human_readable(self):
- pool_formatted = ['%s-%s' % (pool.get('start', ''),
- pool.get('end', ''))
- for pool in self._value]
+ pool_formatted = [
+ '%s-%s' % (pool.get('start', ''), pool.get('end', ''))
+ for pool in self._value
+ ]
return ','.join(pool_formatted)
@@ -53,7 +56,8 @@ class HostRoutesColumn(cliff_columns.FormattableColumn):
def human_readable(self):
# Map the host route keys to match --host-route option.
return utils.format_list_of_dicts(
- convert_entries_to_gateway(self._value))
+ convert_entries_to_gateway(self._value)
+ )
_formatters = {
@@ -72,34 +76,42 @@ def _get_common_parse_arguments(parser, is_create=True):
dest='allocation_pools',
action=parseractions.MultiKeyValueAction,
required_keys=['start', 'end'],
- help=_("Allocation pool IP addresses for this subnet "
- "e.g.: start=192.168.199.2,end=192.168.199.254 "
- "(repeat option to add multiple IP addresses)")
+ help=_(
+ "Allocation pool IP addresses for this subnet "
+ "e.g.: start=192.168.199.2,end=192.168.199.254 "
+ "(repeat option to add multiple IP addresses)"
+ ),
)
if not is_create:
parser.add_argument(
'--no-allocation-pool',
action='store_true',
- help=_("Clear associated allocation-pools from the subnet. "
- "Specify both --allocation-pool and --no-allocation-pool "
- "to overwrite the current allocation pool information.")
+ help=_(
+ "Clear associated allocation-pools from the subnet. "
+ "Specify both --allocation-pool and --no-allocation-pool "
+ "to overwrite the current allocation pool information."
+ ),
)
parser.add_argument(
'--dns-nameserver',
metavar='<dns-nameserver>',
action='append',
dest='dns_nameservers',
- help=_("DNS server for this subnet "
- "(repeat option to set multiple DNS servers)")
+ help=_(
+ "DNS server for this subnet "
+ "(repeat option to set multiple DNS servers)"
+ ),
)
if not is_create:
parser.add_argument(
'--no-dns-nameservers',
action='store_true',
- help=_("Clear existing information of DNS Nameservers. "
- "Specify both --dns-nameserver and --no-dns-nameserver "
- "to overwrite the current DNS Nameserver information.")
+ help=_(
+ "Clear existing information of DNS Nameservers. "
+ "Specify both --dns-nameserver and --no-dns-nameserver "
+ "to overwrite the current DNS Nameserver information."
+ ),
)
parser.add_argument(
'--host-route',
@@ -107,29 +119,35 @@ def _get_common_parse_arguments(parser, is_create=True):
dest='host_routes',
action=parseractions.MultiKeyValueAction,
required_keys=['destination', 'gateway'],
- help=_("Additional route for this subnet "
- "e.g.: destination=10.10.0.0/16,gateway=192.168.71.254 "
- "destination: destination subnet (in CIDR notation) "
- "gateway: nexthop IP address "
- "(repeat option to add multiple routes)")
+ help=_(
+ "Additional route for this subnet "
+ "e.g.: destination=10.10.0.0/16,gateway=192.168.71.254 "
+ "destination: destination subnet (in CIDR notation) "
+ "gateway: nexthop IP address "
+ "(repeat option to add multiple routes)"
+ ),
)
if not is_create:
parser.add_argument(
'--no-host-route',
action='store_true',
- help=_("Clear associated host-routes from the subnet. "
- "Specify both --host-route and --no-host-route "
- "to overwrite the current host route information.")
+ help=_(
+ "Clear associated host-routes from the subnet. "
+ "Specify both --host-route and --no-host-route "
+ "to overwrite the current host route information."
+ ),
)
parser.add_argument(
'--service-type',
metavar='<service-type>',
action='append',
dest='service_types',
- help=_("Service type for this subnet "
- "e.g.: network:floatingip_agent_gateway. "
- "Must be a valid device owner value for a network port "
- "(repeat option to set multiple service types)")
+ help=_(
+ "Service type for this subnet "
+ "e.g.: network:floatingip_agent_gateway. "
+ "Must be a valid device owner value for a network port "
+ "(repeat option to set multiple service types)"
+ ),
)
@@ -146,9 +164,7 @@ def _get_columns(item):
'tenant_id',
]
return utils.get_osc_show_columns_for_sdk_resource(
- item,
- column_map,
- hidden_columns
+ item, column_map, hidden_columns
)
@@ -189,11 +205,13 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
parsed_args.project_domain,
).id
attrs['project_id'] = project_id
- 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
if parsed_args.subnet_pool is not None:
- subnet_pool = client.find_subnet_pool(parsed_args.subnet_pool,
- ignore_missing=False)
+ subnet_pool = client.find_subnet_pool(
+ parsed_args.subnet_pool, ignore_missing=False
+ )
attrs['subnetpool_id'] = subnet_pool.id
if parsed_args.use_prefix_delegation:
attrs['subnetpool_id'] = "prefix_delegation"
@@ -212,21 +230,26 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
if parsed_args.network_segment is not None:
attrs['segment_id'] = client.find_segment(
- parsed_args.network_segment, ignore_missing=False).id
+ parsed_args.network_segment, ignore_missing=False
+ ).id
if 'gateway' in parsed_args and parsed_args.gateway is not None:
gateway = parsed_args.gateway.lower()
if not is_create and gateway == 'auto':
- msg = _("Auto option is not available for Subnet Set. "
- "Valid options are <ip-address> or none")
+ msg = _(
+ "Auto option is not available for Subnet Set. "
+ "Valid options are <ip-address> or none"
+ )
raise exceptions.CommandError(msg)
elif gateway != 'auto':
if gateway == 'none':
attrs['gateway_ip'] = None
else:
attrs['gateway_ip'] = gateway
- if ('allocation_pools' in parsed_args and
- parsed_args.allocation_pools is not None):
+ if (
+ 'allocation_pools' in parsed_args
+ and parsed_args.allocation_pools is not None
+ ):
attrs['allocation_pools'] = parsed_args.allocation_pools
if parsed_args.dhcp:
attrs['enable_dhcp'] = True
@@ -236,15 +259,20 @@ def _get_attrs(client_manager, parsed_args, is_create=True):
attrs['dns_publish_fixed_ip'] = True
if parsed_args.no_dns_publish_fixed_ip:
attrs['dns_publish_fixed_ip'] = False
- if ('dns_nameservers' in parsed_args and
- parsed_args.dns_nameservers is not None):
+ if (
+ 'dns_nameservers' in parsed_args
+ and parsed_args.dns_nameservers is not None
+ ):
attrs['dns_nameservers'] = parsed_args.dns_nameservers
if 'host_routes' in parsed_args and parsed_args.host_routes is not None:
# Change 'gateway' entry to 'nexthop' to match the API
attrs['host_routes'] = convert_entries_to_nexthop(
- parsed_args.host_routes)
- if ('service_types' in parsed_args and
- parsed_args.service_types is not None):
+ parsed_args.host_routes
+ )
+ if (
+ 'service_types' in parsed_args
+ and parsed_args.service_types is not None
+ ):
attrs['service_types'] = parsed_args.service_types
if parsed_args.description is not None:
attrs['description'] = parsed_args.description
@@ -259,115 +287,124 @@ class CreateSubnet(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateSubnet, self).get_parser(prog_name)
parser.add_argument(
- 'name',
- metavar='<name>',
- help=_("New subnet name")
+ 'name', metavar='<name>', help=_("New subnet name")
)
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)
subnet_pool_group = parser.add_mutually_exclusive_group()
subnet_pool_group.add_argument(
'--subnet-pool',
metavar='<subnet-pool>',
- help=_("Subnet pool from which this subnet will obtain a CIDR "
- "(Name or ID)")
+ help=_(
+ "Subnet pool from which this subnet will obtain a CIDR "
+ "(Name or ID)"
+ ),
)
subnet_pool_group.add_argument(
'--use-prefix-delegation',
- help=_("Use 'prefix-delegation' if IP is IPv6 format "
- "and IP would be delegated externally")
+ help=_(
+ "Use 'prefix-delegation' if IP is IPv6 format "
+ "and IP would be delegated externally"
+ ),
)
subnet_pool_group.add_argument(
'--use-default-subnet-pool',
action='store_true',
- help=_("Use default subnet pool for --ip-version")
+ help=_("Use default subnet pool for --ip-version"),
)
parser.add_argument(
'--prefix-length',
metavar='<prefix-length>',
- help=_("Prefix length for subnet allocation from subnet pool")
+ help=_("Prefix length for subnet allocation from subnet pool"),
)
parser.add_argument(
'--subnet-range',
metavar='<subnet-range>',
- help=_("Subnet range in CIDR notation "
- "(required if --subnet-pool is not specified, "
- "optional otherwise)")
+ help=_(
+ "Subnet range in CIDR notation "
+ "(required if --subnet-pool is not specified, "
+ "optional otherwise)"
+ ),
)
dhcp_enable_group = parser.add_mutually_exclusive_group()
dhcp_enable_group.add_argument(
- '--dhcp',
- action='store_true',
- help=_("Enable DHCP (default)")
+ '--dhcp', action='store_true', help=_("Enable DHCP (default)")
)
dhcp_enable_group.add_argument(
- '--no-dhcp',
- action='store_true',
- help=_("Disable DHCP")
+ '--no-dhcp', action='store_true', help=_("Disable DHCP")
)
dns_publish_fixed_ip_group = parser.add_mutually_exclusive_group()
dns_publish_fixed_ip_group.add_argument(
'--dns-publish-fixed-ip',
action='store_true',
- help=_("Enable publishing fixed IPs in DNS")
+ help=_("Enable publishing fixed IPs in DNS"),
)
dns_publish_fixed_ip_group.add_argument(
'--no-dns-publish-fixed-ip',
action='store_true',
- help=_("Disable publishing fixed IPs in DNS (default)")
+ help=_("Disable publishing fixed IPs in DNS (default)"),
)
parser.add_argument(
'--gateway',
metavar='<gateway>',
default='auto',
- help=_("Specify a gateway for the subnet. The three options are: "
- "<ip-address>: Specific IP address to use as the gateway, "
- "'auto': Gateway address should automatically be chosen "
- "from within the subnet itself, 'none': This subnet will "
- "not use a gateway, e.g.: --gateway 192.168.9.1, "
- "--gateway auto, --gateway none (default is 'auto').")
+ help=_(
+ "Specify a gateway for the subnet. The three options are: "
+ "<ip-address>: Specific IP address to use as the gateway, "
+ "'auto': Gateway address should automatically be chosen "
+ "from within the subnet itself, 'none': This subnet will "
+ "not use a gateway, e.g.: --gateway 192.168.9.1, "
+ "--gateway auto, --gateway none (default is 'auto')."
+ ),
)
parser.add_argument(
'--ip-version',
type=int,
default=4,
choices=[4, 6],
- help=_("IP version (default is 4). Note that when subnet pool is "
- "specified, IP version is determined from the subnet pool "
- "and this option is ignored.")
+ help=_(
+ "IP version (default is 4). Note that when subnet pool is "
+ "specified, IP version is determined from the subnet pool "
+ "and this option is ignored."
+ ),
)
parser.add_argument(
'--ipv6-ra-mode',
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
- help=_("IPv6 RA (Router Advertisement) mode, "
- "valid modes: [dhcpv6-stateful, dhcpv6-stateless, slaac]")
+ help=_(
+ "IPv6 RA (Router Advertisement) mode, "
+ "valid modes: [dhcpv6-stateful, dhcpv6-stateless, slaac]"
+ ),
)
parser.add_argument(
'--ipv6-address-mode',
choices=['dhcpv6-stateful', 'dhcpv6-stateless', 'slaac'],
- help=_("IPv6 address mode, "
- "valid modes: [dhcpv6-stateful, dhcpv6-stateless, slaac]")
+ help=_(
+ "IPv6 address mode, "
+ "valid modes: [dhcpv6-stateful, dhcpv6-stateless, slaac]"
+ ),
)
parser.add_argument(
'--network-segment',
metavar='<network-segment>',
- help=_("Network segment to associate with this subnet "
- "(name or ID)")
+ help=_(
+ "Network segment to associate with this subnet " "(name or ID)"
+ ),
)
parser.add_argument(
'--network',
required=True,
metavar='<network>',
- help=_("Network this subnet belongs to (name or ID)")
+ help=_("Network this subnet belongs to (name or ID)"),
)
parser.add_argument(
'--description',
metavar='<description>',
- help=_("Set subnet description")
+ help=_("Set subnet description"),
)
_get_common_parse_arguments(parser)
_tag.add_tag_option_to_parser_for_create(parser, _('subnet'))
@@ -377,7 +414,8 @@ class CreateSubnet(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_subnet(**attrs)
# tags cannot be set when created, so tags need to be set later.
_tag.update_tags_for_set(client, obj, parsed_args)
@@ -395,7 +433,7 @@ class DeleteSubnet(command.Command):
'subnet',
metavar="<subnet>",
nargs='+',
- help=_("Subnet(s) to delete (name or ID)")
+ help=_("Subnet(s) to delete (name or ID)"),
)
return parser
@@ -409,14 +447,20 @@ class DeleteSubnet(command.Command):
client.delete_subnet(obj)
except Exception as e:
result += 1
- LOG.error(_("Failed to delete subnet with "
- "name or ID '%(subnet)s': %(e)s"),
- {'subnet': subnet, 'e': e})
+ LOG.error(
+ _(
+ "Failed to delete subnet with "
+ "name or ID '%(subnet)s': %(e)s"
+ ),
+ {'subnet': subnet, 'e': e},
+ )
if result > 0:
total = len(parsed_args.subnet)
- msg = (_("%(result)s of %(total)s subnets failed "
- "to delete.") % {'result': result, 'total': total})
+ msg = _("%(result)s of %(total)s subnets failed " "to delete.") % {
+ 'result': result,
+ 'total': total,
+ }
raise exceptions.CommandError(msg)
@@ -431,7 +475,7 @@ class ListSubnet(command.Lister):
'--long',
action='store_true',
default=False,
- help=_("List additional fields in output")
+ help=_("List additional fields in output"),
)
parser.add_argument(
'--ip-version',
@@ -439,65 +483,77 @@ class ListSubnet(command.Lister):
choices=[4, 6],
metavar='<ip-version>',
dest='ip_version',
- help=_("List only subnets of given IP version in output. "
- "Allowed values for IP version are 4 and 6."),
+ help=_(
+ "List only subnets of given IP version in output. "
+ "Allowed values for IP version are 4 and 6."
+ ),
)
dhcp_enable_group = parser.add_mutually_exclusive_group()
dhcp_enable_group.add_argument(
'--dhcp',
action='store_true',
- help=_("List subnets which have DHCP enabled")
+ help=_("List subnets which have DHCP enabled"),
)
dhcp_enable_group.add_argument(
'--no-dhcp',
action='store_true',
- help=_("List subnets which have DHCP disabled")
+ help=_("List subnets which have DHCP disabled"),
)
parser.add_argument(
'--service-type',
metavar='<service-type>',
action='append',
dest='service_types',
- help=_("List only subnets of a given service type in output "
- "e.g.: network:floatingip_agent_gateway. "
- "Must be a valid device owner value for a network port "
- "(repeat option to list multiple service types)")
+ help=_(
+ "List only subnets of a given service type in output "
+ "e.g.: network:floatingip_agent_gateway. "
+ "Must be a valid device owner value for a network port "
+ "(repeat option to list multiple service types)"
+ ),
)
parser.add_argument(
'--project',
metavar='<project>',
- help=_("List only subnets which belong to a given project "
- "in output (name or ID)")
+ help=_(
+ "List only subnets which belong to a given project "
+ "in output (name or ID)"
+ ),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--network',
metavar='<network>',
- help=_("List only subnets which belong to a given network "
- "in output (name or ID)")
+ help=_(
+ "List only subnets which belong to a given network "
+ "in output (name or ID)"
+ ),
)
parser.add_argument(
'--gateway',
metavar='<gateway>',
- help=_("List only subnets of given gateway IP in output")
+ help=_("List only subnets of given gateway IP in output"),
)
parser.add_argument(
'--name',
metavar='<name>',
- help=_("List only subnets of given name in output")
+ help=_("List only subnets of given name in output"),
)
parser.add_argument(
'--subnet-range',
metavar='<subnet-range>',
- help=_("List only subnets of given subnet range "
- "(in CIDR notation) in output "
- "e.g.: --subnet-range 10.10.0.0/16")
+ help=_(
+ "List only subnets of given subnet range "
+ "(in CIDR notation) in output "
+ "e.g.: --subnet-range 10.10.0.0/16"
+ ),
)
parser.add_argument(
'--subnet-pool',
metavar='<subnet-pool>',
- help=_("List only subnets which belong to a given subnet pool "
- "in output (Name or ID)")
+ help=_(
+ "List only subnets which belong to a given subnet pool "
+ "in output (Name or ID)"
+ ),
)
_tag.add_tag_filtering_option_to_parser(parser, _('subnets'))
return parser
@@ -524,8 +580,9 @@ class ListSubnet(command.Lister):
).id
filters['project_id'] = project_id
if parsed_args.network:
- network_id = network_client.find_network(parsed_args.network,
- ignore_missing=False).id
+ network_id = network_client.find_network(
+ parsed_args.network, ignore_missing=False
+ ).id
filters['network_id'] = network_id
if parsed_args.gateway:
filters['gateway_ip'] = parsed_args.gateway
@@ -535,7 +592,8 @@ class ListSubnet(command.Lister):
filters['cidr'] = parsed_args.subnet_range
if parsed_args.subnet_pool:
subnetpool_id = network_client.find_subnet_pool(
- parsed_args.subnet_pool, ignore_missing=False).id
+ parsed_args.subnet_pool, ignore_missing=False
+ ).id
filters['subnetpool_id'] = subnetpool_id
_tag.get_tag_filtering_args(parsed_args, filters)
data = network_client.subnets(**filters)
@@ -543,18 +601,40 @@ class ListSubnet(command.Lister):
headers = ('ID', 'Name', 'Network', 'Subnet')
columns = ('id', 'name', 'network_id', 'cidr')
if parsed_args.long:
- headers += ('Project', 'DHCP', 'Name Servers',
- 'Allocation Pools', 'Host Routes', 'IP Version',
- 'Gateway', 'Service Types', 'Tags')
- columns += ('project_id', 'is_dhcp_enabled', 'dns_nameservers',
- 'allocation_pools', 'host_routes', 'ip_version',
- 'gateway_ip', 'service_types', 'tags')
-
- return (headers,
- (utils.get_item_properties(
- s, columns,
+ headers += (
+ 'Project',
+ 'DHCP',
+ 'Name Servers',
+ 'Allocation Pools',
+ 'Host Routes',
+ 'IP Version',
+ 'Gateway',
+ 'Service Types',
+ 'Tags',
+ )
+ columns += (
+ 'project_id',
+ 'is_dhcp_enabled',
+ 'dns_nameservers',
+ 'allocation_pools',
+ 'host_routes',
+ 'ip_version',
+ 'gateway_ip',
+ 'service_types',
+ 'tags',
+ )
+
+ return (
+ headers,
+ (
+ utils.get_item_properties(
+ s,
+ columns,
formatters=_formatters,
- ) for s in data))
+ )
+ for s in data
+ ),
+ )
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -567,56 +647,53 @@ class SetSubnet(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'subnet',
metavar="<subnet>",
- help=_("Subnet to modify (name or ID)")
+ help=_("Subnet to modify (name or ID)"),
)
parser.add_argument(
- '--name',
- metavar='<name>',
- help=_("Updated name of the subnet")
+ '--name', metavar='<name>', help=_("Updated name of the subnet")
)
dhcp_enable_group = parser.add_mutually_exclusive_group()
dhcp_enable_group.add_argument(
- '--dhcp',
- action='store_true',
- default=None,
- help=_("Enable DHCP")
+ '--dhcp', action='store_true', default=None, help=_("Enable DHCP")
)
dhcp_enable_group.add_argument(
- '--no-dhcp',
- action='store_true',
- help=_("Disable DHCP")
+ '--no-dhcp', action='store_true', help=_("Disable DHCP")
)
dns_publish_fixed_ip_group = parser.add_mutually_exclusive_group()
dns_publish_fixed_ip_group.add_argument(
'--dns-publish-fixed-ip',
action='store_true',
- help=_("Enable publishing fixed IPs in DNS")
+ help=_("Enable publishing fixed IPs in DNS"),
)
dns_publish_fixed_ip_group.add_argument(
'--no-dns-publish-fixed-ip',
action='store_true',
- help=_("Disable publishing fixed IPs in DNS")
+ help=_("Disable publishing fixed IPs in DNS"),
)
parser.add_argument(
'--gateway',
metavar='<gateway>',
- help=_("Specify a gateway for the subnet. The options are: "
- "<ip-address>: Specific IP address to use as the gateway, "
- "'none': This subnet will not use a gateway, "
- "e.g.: --gateway 192.168.9.1, --gateway none.")
+ help=_(
+ "Specify a gateway for the subnet. The options are: "
+ "<ip-address>: Specific IP address to use as the gateway, "
+ "'none': This subnet will not use a gateway, "
+ "e.g.: --gateway 192.168.9.1, --gateway none."
+ ),
)
parser.add_argument(
'--network-segment',
metavar='<network-segment>',
- help=_("Network segment to associate with this subnet (name or "
- "ID). It is only allowed to set the segment if the current "
- "value is `None`, the network must also have only one "
- "segment and only one subnet can exist on the network.")
+ help=_(
+ "Network segment to associate with this subnet (name or "
+ "ID). It is only allowed to set the segment if the current "
+ "value is `None`, the network must also have only one "
+ "segment and only one subnet can exist on the network."
+ ),
)
parser.add_argument(
'--description',
metavar='<description>',
- help=_("Set subnet description")
+ help=_("Set subnet description"),
)
_tag.add_tag_option_to_parser_for_set(parser, _('subnet'))
_get_common_parse_arguments(parser, is_create=False)
@@ -625,8 +702,9 @@ class SetSubnet(common.NeutronCommandWithExtraArgs):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_subnet(parsed_args.subnet, ignore_missing=False)
- attrs = _get_attrs(self.app.client_manager, parsed_args,
- is_create=False)
+ attrs = _get_attrs(
+ self.app.client_manager, parsed_args, is_create=False
+ )
if 'dns_nameservers' in attrs:
if not parsed_args.no_dns_nameservers:
attrs['dns_nameservers'] += obj.dns_nameservers
@@ -645,7 +723,8 @@ class SetSubnet(common.NeutronCommandWithExtraArgs):
if 'service_types' in attrs:
attrs['service_types'] += obj.service_types
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if attrs:
client.update_subnet(obj, **attrs)
# tags is a subresource and it needs to be updated separately.
@@ -661,13 +740,14 @@ class ShowSubnet(command.ShowOne):
parser.add_argument(
'subnet',
metavar="<subnet>",
- help=_("Subnet to display (name or ID)")
+ help=_("Subnet to display (name or ID)"),
)
return parser
def take_action(self, parsed_args):
- obj = self.app.client_manager.network.find_subnet(parsed_args.subnet,
- ignore_missing=False)
+ obj = self.app.client_manager.network.find_subnet(
+ parsed_args.subnet, ignore_missing=False
+ )
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (display_columns, data)
@@ -684,22 +764,26 @@ class UnsetSubnet(common.NeutronUnsetCommandWithExtraArgs):
dest='allocation_pools',
action=parseractions.MultiKeyValueAction,
required_keys=['start', 'end'],
- help=_('Allocation pool IP addresses to be removed from this '
- 'subnet e.g.: start=192.168.199.2,end=192.168.199.254 '
- '(repeat option to unset multiple allocation pools)')
+ help=_(
+ 'Allocation pool IP addresses to be removed from this '
+ 'subnet e.g.: start=192.168.199.2,end=192.168.199.254 '
+ '(repeat option to unset multiple allocation pools)'
+ ),
)
parser.add_argument(
'--gateway',
action='store_true',
- help=_("Remove gateway IP from this subnet")
+ help=_("Remove gateway IP from this subnet"),
)
parser.add_argument(
'--dns-nameserver',
metavar='<dns-nameserver>',
action='append',
dest='dns_nameservers',
- help=_('DNS server to be removed from this subnet '
- '(repeat option to unset multiple DNS servers)')
+ help=_(
+ 'DNS server to be removed from this subnet '
+ '(repeat option to unset multiple DNS servers)'
+ ),
)
parser.add_argument(
'--host-route',
@@ -707,27 +791,31 @@ class UnsetSubnet(common.NeutronUnsetCommandWithExtraArgs):
dest='host_routes',
action=parseractions.MultiKeyValueAction,
required_keys=['destination', 'gateway'],
- help=_('Route to be removed from this subnet '
- 'e.g.: destination=10.10.0.0/16,gateway=192.168.71.254 '
- 'destination: destination subnet (in CIDR notation) '
- 'gateway: nexthop IP address '
- '(repeat option to unset multiple host routes)')
+ help=_(
+ 'Route to be removed from this subnet '
+ 'e.g.: destination=10.10.0.0/16,gateway=192.168.71.254 '
+ 'destination: destination subnet (in CIDR notation) '
+ 'gateway: nexthop IP address '
+ '(repeat option to unset multiple host routes)'
+ ),
)
parser.add_argument(
'--service-type',
metavar='<service-type>',
action='append',
dest='service_types',
- help=_('Service type to be removed from this subnet '
- 'e.g.: network:floatingip_agent_gateway. '
- 'Must be a valid device owner value for a network port '
- '(repeat option to unset multiple service types)')
+ help=_(
+ 'Service type to be removed from this subnet '
+ 'e.g.: network:floatingip_agent_gateway. '
+ 'Must be a valid device owner value for a network port '
+ '(repeat option to unset multiple service types)'
+ ),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('subnet'))
parser.add_argument(
'subnet',
metavar="<subnet>",
- help=_("Subnet to modify (name or ID)")
+ help=_("Subnet to modify (name or ID)"),
)
return parser
@@ -740,28 +828,36 @@ class UnsetSubnet(common.NeutronUnsetCommandWithExtraArgs):
attrs['gateway_ip'] = None
if parsed_args.dns_nameservers:
attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers)
- _update_arguments(attrs['dns_nameservers'],
- parsed_args.dns_nameservers,
- 'dns-nameserver')
+ _update_arguments(
+ attrs['dns_nameservers'],
+ parsed_args.dns_nameservers,
+ 'dns-nameserver',
+ )
if parsed_args.host_routes:
attrs['host_routes'] = copy.deepcopy(obj.host_routes)
_update_arguments(
attrs['host_routes'],
convert_entries_to_nexthop(parsed_args.host_routes),
- 'host-route')
+ 'host-route',
+ )
if parsed_args.allocation_pools:
attrs['allocation_pools'] = copy.deepcopy(obj.allocation_pools)
- _update_arguments(attrs['allocation_pools'],
- parsed_args.allocation_pools,
- 'allocation-pool')
+ _update_arguments(
+ attrs['allocation_pools'],
+ parsed_args.allocation_pools,
+ 'allocation-pool',
+ )
if parsed_args.service_types:
attrs['service_types'] = copy.deepcopy(obj.service_types)
- _update_arguments(attrs['service_types'],
- parsed_args.service_types,
- 'service-type')
+ _update_arguments(
+ attrs['service_types'],
+ parsed_args.service_types,
+ 'service-type',
+ )
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if attrs:
client.update_subnet(obj, **attrs)
diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py
index 2369960e..833fe325 100644
--- a/openstackclient/network/v2/subnet_pool.py
+++ b/openstackclient/network/v2/subnet_pool.py
@@ -39,9 +39,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
)
@@ -68,7 +66,8 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.address_scope is not None:
attrs['address_scope_id'] = network_client.find_address_scope(
- parsed_args.address_scope, ignore_missing=False).id
+ parsed_args.address_scope, ignore_missing=False
+ ).id
if 'no_address_scope' in parsed_args and parsed_args.no_address_scope:
attrs['address_scope_id'] = None
@@ -108,29 +107,31 @@ def _add_prefix_options(parser, for_create=False):
dest='prefixes',
action='append',
required=for_create,
- help=_("Set subnet pool prefixes (in CIDR notation) "
- "(repeat option to set multiple prefixes)")
+ help=_(
+ "Set subnet pool prefixes (in CIDR notation) "
+ "(repeat option to set multiple prefixes)"
+ ),
)
parser.add_argument(
'--default-prefix-length',
metavar='<default-prefix-length>',
type=int,
action=parseractions.NonNegativeAction,
- help=_("Set subnet pool default prefix length")
+ help=_("Set subnet pool default prefix length"),
)
parser.add_argument(
'--min-prefix-length',
metavar='<min-prefix-length>',
action=parseractions.NonNegativeAction,
type=int,
- help=_("Set subnet pool minimum prefix length")
+ help=_("Set subnet pool minimum prefix length"),
)
parser.add_argument(
'--max-prefix-length',
metavar='<max-prefix-length>',
type=int,
action=parseractions.NonNegativeAction,
- help=_("Set subnet pool maximum prefix length")
+ help=_("Set subnet pool maximum prefix length"),
)
@@ -156,23 +157,23 @@ class CreateSubnetPool(command.ShowOne, common.NeutronCommandWithExtraArgs):
def get_parser(self, prog_name):
parser = super(CreateSubnetPool, self).get_parser(prog_name)
parser.add_argument(
- 'name',
- metavar='<name>',
- help=_("Name of the new subnet pool")
+ 'name', metavar='<name>', help=_("Name of the new subnet pool")
)
_add_prefix_options(parser, for_create=True)
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(
'--address-scope',
metavar='<address-scope>',
- help=_("Set address scope associated with the subnet pool "
- "(name or ID), prefixes must be unique across address "
- "scopes")
+ help=_(
+ "Set address scope associated with the subnet pool "
+ "(name or ID), prefixes must be unique across address "
+ "scopes"
+ ),
)
_add_default_options(parser)
shared_group = parser.add_mutually_exclusive_group()
@@ -189,15 +190,18 @@ class CreateSubnetPool(command.ShowOne, common.NeutronCommandWithExtraArgs):
parser.add_argument(
'--description',
metavar='<description>',
- help=_("Set subnet pool description")
+ help=_("Set subnet pool description"),
)
parser.add_argument(
'--default-quota',
type=int,
metavar='<num-ip-addresses>',
- help=_("Set default per-project quota for this subnet pool "
- "as the number of IP addresses that can be allocated "
- "from the subnet pool")),
+ help=_(
+ "Set default per-project quota for this subnet pool "
+ "as the number of IP addresses that can be allocated "
+ "from the subnet pool"
+ ),
+ ),
_tag.add_tag_option_to_parser_for_create(parser, _('subnet pool'))
return parser
@@ -208,7 +212,8 @@ class CreateSubnetPool(command.ShowOne, common.NeutronCommandWithExtraArgs):
if "prefixes" not in attrs:
attrs['prefixes'] = []
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
obj = client.create_subnet_pool(**attrs)
# tags cannot be set when created, so tags need to be set later.
_tag.update_tags_for_set(client, obj, parsed_args)
@@ -226,7 +231,7 @@ class DeleteSubnetPool(command.Command):
'subnet_pool',
metavar='<subnet-pool>',
nargs='+',
- help=_("Subnet pool(s) to delete (name or ID)")
+ help=_("Subnet pool(s) to delete (name or ID)"),
)
return parser
@@ -240,14 +245,19 @@ class DeleteSubnetPool(command.Command):
client.delete_subnet_pool(obj)
except Exception as e:
result += 1
- LOG.error(_("Failed to delete subnet pool with "
- "name or ID '%(pool)s': %(e)s"),
- {'pool': pool, 'e': e})
+ LOG.error(
+ _(
+ "Failed to delete subnet pool with "
+ "name or ID '%(pool)s': %(e)s"
+ ),
+ {'pool': pool, 'e': e},
+ )
if result > 0:
total = len(parsed_args.subnet_pool)
- msg = (_("%(result)s of %(total)s subnet pools failed "
- "to delete.") % {'result': result, 'total': total})
+ msg = _(
+ "%(result)s of %(total)s subnet pools failed " "to delete."
+ ) % {'result': result, 'total': total}
raise exceptions.CommandError(msg)
@@ -262,7 +272,7 @@ class ListSubnetPool(command.Lister):
'--long',
action='store_true',
default=False,
- help=_("List additional fields in output")
+ help=_("List additional fields in output"),
)
shared_group = parser.add_mutually_exclusive_group()
shared_group.add_argument(
@@ -279,31 +289,38 @@ class ListSubnetPool(command.Lister):
default_group.add_argument(
'--default',
action='store_true',
- help=_("List subnet pools used as the default external "
- "subnet pool"),
+ help=_(
+ "List subnet pools used as the default external " "subnet pool"
+ ),
)
default_group.add_argument(
'--no-default',
action='store_true',
- help=_("List subnet pools not used as the default external "
- "subnet pool")
+ help=_(
+ "List subnet pools not used as the default external "
+ "subnet pool"
+ ),
)
parser.add_argument(
'--project',
metavar='<project>',
- help=_("List subnet pools according to their project (name or ID)")
+ help=_(
+ "List subnet pools according to their project (name or ID)"
+ ),
)
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--name',
metavar='<name>',
- help=_("List only subnet pools of given name in output")
+ help=_("List only subnet pools of given name in output"),
)
parser.add_argument(
'--address-scope',
metavar='<address-scope>',
- help=_("List only subnet pools of given address scope "
- "in output (name or ID)")
+ help=_(
+ "List only subnet pools of given address scope "
+ "in output (name or ID)"
+ ),
)
_tag.add_tag_filtering_option_to_parser(parser, _('subnet pools'))
return parser
@@ -333,8 +350,8 @@ class ListSubnetPool(command.Lister):
filters['name'] = parsed_args.name
if parsed_args.address_scope:
address_scope = network_client.find_address_scope(
- parsed_args.address_scope,
- ignore_missing=False)
+ parsed_args.address_scope, ignore_missing=False
+ )
filters['address_scope_id'] = address_scope.id
_tag.get_tag_filtering_args(parsed_args, filters)
data = network_client.subnet_pools(**filters)
@@ -342,16 +359,32 @@ class ListSubnetPool(command.Lister):
headers = ('ID', 'Name', 'Prefixes')
columns = ('id', 'name', 'prefixes')
if parsed_args.long:
- headers += ('Default Prefix Length', 'Address Scope',
- 'Default Subnet Pool', 'Shared', 'Tags')
- columns += ('default_prefix_length', 'address_scope_id',
- 'is_default', 'is_shared', 'tags')
-
- return (headers,
- (utils.get_item_properties(
- s, columns,
+ headers += (
+ 'Default Prefix Length',
+ 'Address Scope',
+ 'Default Subnet Pool',
+ 'Shared',
+ 'Tags',
+ )
+ columns += (
+ 'default_prefix_length',
+ 'address_scope_id',
+ 'is_default',
+ 'is_shared',
+ 'tags',
+ )
+
+ return (
+ headers,
+ (
+ utils.get_item_properties(
+ s,
+ columns,
formatters=_formatters,
- ) for s in data))
+ )
+ for s in data
+ ),
+ )
# TODO(rtheis): Use the SDK resource mapped attribute names once the
@@ -364,48 +397,52 @@ class SetSubnetPool(common.NeutronCommandWithExtraArgs):
parser.add_argument(
'subnet_pool',
metavar='<subnet-pool>',
- help=_("Subnet pool to modify (name or ID)")
+ help=_("Subnet pool to modify (name or ID)"),
)
parser.add_argument(
- '--name',
- metavar='<name>',
- help=_("Set subnet pool name")
+ '--name', metavar='<name>', help=_("Set subnet pool name")
)
_add_prefix_options(parser)
address_scope_group = parser.add_mutually_exclusive_group()
address_scope_group.add_argument(
'--address-scope',
metavar='<address-scope>',
- help=_("Set address scope associated with the subnet pool "
- "(name or ID), prefixes must be unique across address "
- "scopes")
+ help=_(
+ "Set address scope associated with the subnet pool "
+ "(name or ID), prefixes must be unique across address "
+ "scopes"
+ ),
)
address_scope_group.add_argument(
'--no-address-scope',
action='store_true',
- help=_("Remove address scope associated with the subnet pool")
+ help=_("Remove address scope associated with the subnet pool"),
)
_add_default_options(parser)
parser.add_argument(
'--description',
metavar='<description>',
- help=_("Set subnet pool description")
+ help=_("Set subnet pool description"),
)
parser.add_argument(
'--default-quota',
type=int,
metavar='<num-ip-addresses>',
- help=_("Set default per-project quota for this subnet pool "
- "as the number of IP addresses that can be allocated "
- "from the subnet pool")),
+ help=_(
+ "Set default per-project quota for this subnet pool "
+ "as the number of IP addresses that can be allocated "
+ "from the subnet pool"
+ ),
+ ),
_tag.add_tag_option_to_parser_for_set(parser, _('subnet pool'))
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
- obj = client.find_subnet_pool(parsed_args.subnet_pool,
- ignore_missing=False)
+ obj = client.find_subnet_pool(
+ parsed_args.subnet_pool, ignore_missing=False
+ )
attrs = _get_attrs(self.app.client_manager, parsed_args)
@@ -414,7 +451,8 @@ class SetSubnetPool(common.NeutronCommandWithExtraArgs):
attrs['prefixes'].extend(obj.prefixes)
attrs.update(
- self._parse_extra_properties(parsed_args.extra_properties))
+ self._parse_extra_properties(parsed_args.extra_properties)
+ )
if attrs:
client.update_subnet_pool(obj, **attrs)
@@ -430,15 +468,14 @@ class ShowSubnetPool(command.ShowOne):
parser.add_argument(
'subnet_pool',
metavar='<subnet-pool>',
- help=_("Subnet pool to display (name or ID)")
+ help=_("Subnet pool to display (name or ID)"),
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_subnet_pool(
- parsed_args.subnet_pool,
- ignore_missing=False
+ parsed_args.subnet_pool, ignore_missing=False
)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
@@ -453,7 +490,7 @@ class UnsetSubnetPool(command.Command):
parser.add_argument(
'subnet_pool',
metavar="<subnet-pool>",
- help=_("Subnet pool to modify (name or ID)")
+ help=_("Subnet pool to modify (name or ID)"),
)
_tag.add_tag_option_to_parser_for_unset(parser, _('subnet pool'))
return parser
@@ -461,6 +498,7 @@ class UnsetSubnetPool(command.Command):
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_subnet_pool(
- parsed_args.subnet_pool, ignore_missing=False)
+ parsed_args.subnet_pool, ignore_missing=False
+ )
# tags is a subresource and it needs to be updated separately.
_tag.update_tags_for_unset(client, obj, parsed_args)