summaryrefslogtreecommitdiff
path: root/openstackclient/network/v2/network.py
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/v2/network.py
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/v2/network.py')
-rw-r--r--openstackclient/network/v2/network.py321
1 files changed, 194 insertions, 127 deletions
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