diff options
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/v2/floating_ip.py | 109 | ||||
| -rw-r--r-- | openstackclient/network/v2/network.py | 30 | ||||
| -rw-r--r-- | openstackclient/network/v2/network_rbac.py | 75 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet.py | 3 |
4 files changed, 210 insertions, 7 deletions
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index 8fbf049e..454335f1 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -13,6 +13,8 @@ """IP Floating action implementations""" +import logging + from osc_lib import utils from openstackclient.i18n import _ @@ -31,25 +33,26 @@ def _get_attrs(client_manager, parsed_args): attrs = {} network_client = client_manager.network + # 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) attrs['floating_network_id'] = network.id - if parsed_args.subnet is not None: + if parsed_args.subnet: subnet = network_client.find_subnet(parsed_args.subnet, ignore_missing=False) attrs['subnet_id'] = subnet.id - if parsed_args.port is not None: + if parsed_args.port: port = network_client.find_port(parsed_args.port, ignore_missing=False) attrs['port_id'] = port.id - if parsed_args.floating_ip_address is not None: + if parsed_args.floating_ip_address: attrs['floating_ip_address'] = parsed_args.floating_ip_address - if parsed_args.fixed_ip_address is not None: + if parsed_args.fixed_ip_address: attrs['fixed_ip_address'] = parsed_args.fixed_ip_address return attrs @@ -110,6 +113,30 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne): return (columns, data) +class CreateIPFloating(CreateFloatingIP): + """Create floating IP""" + + # TODO(tangchen): Remove this class and ``ip floating create`` command + # two cycles after Mitaka. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action_network(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip create" instead.')) + return super(CreateIPFloating, self).take_action_network( + client, parsed_args) + + def take_action_compute(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip create" instead.')) + return super(CreateIPFloating, self).take_action_compute( + client, parsed_args) + + class DeleteFloatingIP(common.NetworkAndComputeDelete): """Delete floating IP(s)""" @@ -135,6 +162,30 @@ class DeleteFloatingIP(common.NetworkAndComputeDelete): client.floating_ips.delete(obj.id) +class DeleteIPFloating(DeleteFloatingIP): + """Delete floating IP(s)""" + + # TODO(tangchen): Remove this class and ``ip floating delete`` command + # two cycles after Mitaka. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action_network(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip delete" instead.')) + return super(DeleteIPFloating, self).take_action_network( + client, parsed_args) + + def take_action_compute(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip delete" instead.')) + return super(DeleteIPFloating, self).take_action_compute( + client, parsed_args) + + class ListFloatingIP(common.NetworkAndComputeLister): """List floating IP(s)""" @@ -186,8 +237,32 @@ class ListFloatingIP(common.NetworkAndComputeLister): ) for s in data)) +class ListIPFloating(ListFloatingIP): + """List floating IP(s)""" + + # TODO(tangchen): Remove this class and ``ip floating list`` command + # two cycles after Mitaka. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action_network(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip list" instead.')) + return super(ListIPFloating, self).take_action_network( + client, parsed_args) + + def take_action_compute(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip list" instead.')) + return super(ListIPFloating, self).take_action_compute( + client, parsed_args) + + class ShowFloatingIP(common.NetworkAndComputeShowOne): - """Show floating IP details""" + """Display floating IP details""" def update_parser_common(self, parser): parser.add_argument( @@ -211,3 +286,27 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne): columns = _get_columns(obj._info) data = utils.get_dict_properties(obj._info, columns) return (columns, data) + + +class ShowIPFloating(ShowFloatingIP): + """Display floating IP details""" + + # TODO(tangchen): Remove this class and ``ip floating show`` command + # two cycles after Mitaka. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action_network(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip show" instead.')) + return super(ShowIPFloating, self).take_action_network( + client, parsed_args) + + def take_action_compute(self, client, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "floating ip show" instead.')) + return super(ShowIPFloating, self).take_action_compute( + client, parsed_args) diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 31dfc798..ccc02fd8 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -58,6 +58,10 @@ def _get_attrs(client_manager, parsed_args): attrs['shared'] = True if parsed_args.no_share: attrs['shared'] = False + if parsed_args.enable_port_security: + attrs['port_security_enabled'] = True + if parsed_args.disable_port_security: + attrs['port_security_enabled'] = False # "network set" command doesn't support setting project. if 'project' in parsed_args and parsed_args.project is not None: @@ -197,6 +201,19 @@ class CreateNetwork(common.NetworkAndComputeShowOne): "(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=_("Enable port security by default for ports created on " + "this network (default)") + ) + port_security_group.add_argument( + '--disable-port-security', + action='store_true', + 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', @@ -403,6 +420,19 @@ class SetNetwork(command.Command): action='store_true', help=_("Do not share the network between projects") ) + 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") + ) + port_security_group.add_argument( + '--disable-port-security', + action='store_true', + 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', diff --git a/openstackclient/network/v2/network_rbac.py b/openstackclient/network/v2/network_rbac.py new file mode 100644 index 00000000..7a759449 --- /dev/null +++ b/openstackclient/network/v2/network_rbac.py @@ -0,0 +1,75 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""RBAC action implementations""" + +from osc_lib.command import command +from osc_lib import utils + +from openstackclient.i18n import _ + + +def _get_columns(item): + columns = list(item.keys()) + if 'tenant_id' in columns: + columns.remove('tenant_id') + columns.append('project_id') + if 'target_tenant' in columns: + columns.remove('target_tenant') + columns.append('target_project') + return tuple(sorted(columns)) + + +class ListNetworkRBAC(command.Lister): + """List network RBAC policies""" + + def take_action(self, parsed_args): + client = self.app.client_manager.network + + columns = ( + 'id', + 'object_type', + 'object_id', + ) + column_headers = ( + 'ID', + 'Object Type', + 'Object ID', + ) + + data = client.rbac_policies() + return (column_headers, + (utils.get_item_properties( + s, columns, + ) for s in data)) + + +class ShowNetworkRBAC(command.ShowOne): + """Display network RBAC policy details""" + + def get_parser(self, prog_name): + parser = super(ShowNetworkRBAC, self).get_parser(prog_name) + parser.add_argument( + 'rbac_policy', + metavar="<rbac-policy>", + 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) + columns = _get_columns(obj) + data = utils.get_item_properties(obj, columns) + return columns, data diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index 45d3442d..f26f6804 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -168,7 +168,7 @@ def _get_attrs(client_manager, parsed_args, is_create=True): attrs['allocation_pools'] = parsed_args.allocation_pools if parsed_args.dhcp: attrs['enable_dhcp'] = True - elif parsed_args.no_dhcp: + if parsed_args.no_dhcp: attrs['enable_dhcp'] = False if ('dns_nameservers' in parsed_args and parsed_args.dns_nameservers is not None): @@ -223,7 +223,6 @@ class CreateSubnet(command.ShowOne): dhcp_enable_group.add_argument( '--dhcp', action='store_true', - default=True, help=_("Enable DHCP (default)") ) dhcp_enable_group.add_argument( |
