diff options
Diffstat (limited to 'openstackclient/network')
| -rw-r--r-- | openstackclient/network/common.py | 5 | ||||
| -rw-r--r-- | openstackclient/network/v2/floating_ip.py | 130 | ||||
| -rw-r--r-- | openstackclient/network/v2/floating_ip_pool.py | 25 | ||||
| -rw-r--r-- | openstackclient/network/v2/network.py | 14 | ||||
| -rw-r--r-- | openstackclient/network/v2/network_qos_rule.py | 8 | ||||
| -rw-r--r-- | openstackclient/network/v2/port.py | 8 | ||||
| -rw-r--r-- | openstackclient/network/v2/router.py | 4 | ||||
| -rw-r--r-- | openstackclient/network/v2/security_group.py | 43 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet.py | 18 |
9 files changed, 115 insertions, 140 deletions
diff --git a/openstackclient/network/common.py b/openstackclient/network/common.py index eca0de3c..37bf1406 100644 --- a/openstackclient/network/common.py +++ b/openstackclient/network/common.py @@ -48,7 +48,10 @@ class NetworkAndComputeCommand(command.Command): parser = super(NetworkAndComputeCommand, self).get_parser(prog_name) parser = self.update_parser_common(parser) LOG.debug('common parser: %s', parser) - if self.app.client_manager.is_network_endpoint_enabled(): + if ( + self.app is None or + self.app.client_manager.is_network_endpoint_enabled() + ): return self.update_parser_network(parser) else: return self.update_parser_compute(parser) diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index a6f03404..1bb2c069 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -13,8 +13,6 @@ """IP Floating action implementations""" -import logging - from osc_lib.command import command from osc_lib import utils @@ -22,6 +20,12 @@ from openstackclient.i18n import _ from openstackclient.identity import common as identity_common from openstackclient.network import common from openstackclient.network import sdk_utils +from openstackclient.network.v2 import _tag + + +_formatters = { + 'port_details': utils.format_dict, +} def _get_network_columns(item): @@ -139,11 +143,14 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne): help=_("Owner's project (name or ID)") ) identity_common.add_project_domain_option_to_parser(parser) + _tag.add_tag_option_to_parser_for_create(parser, _('floating IP')) return parser def take_action_network(self, client, parsed_args): attrs = _get_attrs(self.app.client_manager, parsed_args) obj = client.create_ip(**attrs) + # tags cannot be set when created, so tags need to be set later. + _tag.update_tags_for_set(client, obj, parsed_args) display_columns, columns = _get_network_columns(obj) data = utils.get_item_properties(obj, columns) return (display_columns, data) @@ -155,30 +162,6 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne): return (columns, data) -class CreateIPFloating(CreateFloatingIP): - _description = _("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): _description = _("Delete floating IP(s)") @@ -206,30 +189,6 @@ class DeleteFloatingIP(common.NetworkAndComputeDelete): client.api.floating_ip_delete(self.r) -class DeleteIPFloating(DeleteFloatingIP): - _description = _("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): # TODO(songminglong): Use SDK resource mapped attribute names once # the OSC minimum requirements include SDK 1.0 @@ -280,6 +239,7 @@ class ListFloatingIP(common.NetworkAndComputeLister): help=_("List floating IP(s) according to " "given router (name or ID)") ) + _tag.add_tag_filtering_option_to_parser(parser, _('floating IP')) return parser @@ -308,11 +268,13 @@ class ListFloatingIP(common.NetworkAndComputeLister): 'router_id', 'status', 'description', + 'tags', ) headers = headers + ( 'Router', 'Status', 'Description', + 'Tags', ) query = {} @@ -342,6 +304,8 @@ class ListFloatingIP(common.NetworkAndComputeLister): ignore_missing=False) query['router_id'] = router.id + _tag.get_tag_filtering_args(parsed_args, query) + data = client.ips(**query) return (headers, @@ -375,30 +339,6 @@ class ListFloatingIP(common.NetworkAndComputeLister): ) for s in data)) -class ListIPFloating(ListFloatingIP): - _description = _("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 SetFloatingIP(command.Command): _description = _("Set floating IP Properties") @@ -412,7 +352,7 @@ class SetFloatingIP(command.Command): '--port', metavar='<port>', required=True, - help=_("Assocaite 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>', @@ -431,6 +371,9 @@ class SetFloatingIP(command.Command): action='store_true', help=_("Remove the QoS policy attached to the floating IP") ) + + _tag.add_tag_option_to_parser_for_set(parser, _('floating IP')) + return parser def take_action(self, parsed_args): @@ -453,7 +396,11 @@ class SetFloatingIP(command.Command): if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy: attrs['qos_policy_id'] = None - client.update_ip(obj, **attrs) + if attrs: + client.update_ip(obj, **attrs) + + # tags is a subresource and it needs to be updated separately. + _tag.update_tags_for_set(client, obj, parsed_args) class ShowFloatingIP(common.NetworkAndComputeShowOne): @@ -473,7 +420,7 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne): ignore_missing=False, ) display_columns, columns = _get_network_columns(obj) - data = utils.get_item_properties(obj, columns) + data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data) def take_action_compute(self, client, parsed_args): @@ -483,30 +430,6 @@ class ShowFloatingIP(common.NetworkAndComputeShowOne): return (columns, data) -class ShowIPFloating(ShowFloatingIP): - _description = _("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) - - class UnsetFloatingIP(command.Command): _description = _("Unset floating IP Properties") @@ -528,6 +451,8 @@ class UnsetFloatingIP(command.Command): default=False, help=_("Remove the QoS policy attached to the floating IP") ) + _tag.add_tag_option_to_parser_for_unset(parser, _('floating IP')) + return parser def take_action(self, parsed_args): @@ -544,3 +469,6 @@ class UnsetFloatingIP(command.Command): if attrs: client.update_ip(obj, **attrs) + + # 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/floating_ip_pool.py b/openstackclient/network/v2/floating_ip_pool.py index ebb15da8..32852004 100644 --- a/openstackclient/network/v2/floating_ip_pool.py +++ b/openstackclient/network/v2/floating_ip_pool.py @@ -13,7 +13,6 @@ """Floating IP Pool action implementations""" -import logging from osc_lib import exceptions from osc_lib import utils @@ -40,27 +39,3 @@ class ListFloatingIPPool(common.NetworkAndComputeLister): (utils.get_dict_properties( s, columns, ) for s in data)) - - -class ListIPFloatingPool(ListFloatingIPPool): - _description = _("List pools of floating IP addresses") - - # TODO(tangchen): Remove this class and ``ip floating pool 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 pool list" instead.')) - return super(ListIPFloatingPool, 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 pool list" instead.')) - return super(ListIPFloatingPool, self).take_action_compute( - client, parsed_args) diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 4c1725c5..d1c7f005 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -107,6 +107,10 @@ def _get_attrs_network(client_manager, parsed_args): if parsed_args.description: attrs['description'] = parsed_args.description + # set mtu + if parsed_args.mtu: + attrs['mtu'] = parsed_args.mtu + # update_external_network_options if parsed_args.internal: attrs['router:external'] = False @@ -217,6 +221,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne): metavar='<description>', help=_("Set network description") ) + parser.add_argument( + '--mtu', + metavar='<mtu>', + help=_("Set network mtu") + ) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( '--availability-zone-hint', @@ -619,6 +628,11 @@ class SetNetwork(command.Command): metavar="<description", help=_("Set network description") ) + parser.add_argument( + '--mtu', + metavar="<mtu", + help=_("Set network mtu") + ) port_security_group = parser.add_mutually_exclusive_group() port_security_group.add_argument( '--enable-port-security', diff --git a/openstackclient/network/v2/network_qos_rule.py b/openstackclient/network/v2/network_qos_rule.py index f50e58b3..9c4275a8 100644 --- a/openstackclient/network/v2/network_qos_rule.py +++ b/openstackclient/network/v2/network_qos_rule.py @@ -29,11 +29,11 @@ RULE_TYPE_MINIMUM_BANDWIDTH = 'minimum-bandwidth' MANDATORY_PARAMETERS = { RULE_TYPE_MINIMUM_BANDWIDTH: {'min_kbps', 'direction'}, RULE_TYPE_DSCP_MARKING: {'dscp_mark'}, - RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps', 'max_burst_kbps'}} + RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps'}} OPTIONAL_PARAMETERS = { RULE_TYPE_MINIMUM_BANDWIDTH: set(), RULE_TYPE_DSCP_MARKING: set(), - RULE_TYPE_BANDWIDTH_LIMIT: {'direction'}} + RULE_TYPE_BANDWIDTH_LIMIT: {'direction', 'max_burst_kbps'}} DIRECTION_EGRESS = 'egress' DIRECTION_INGRESS = 'ingress' DSCP_VALID_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, @@ -62,11 +62,11 @@ def _check_type_parameters(attrs, type, is_create): 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') % + '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') + msg = (_('Rule type "%(rule_type)s" only requires arguments: %(args)s') % {'rule_type': type, 'args': ", ".join(sorted(type_params))}) raise exceptions.CommandError(msg) diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 032e1787..f13ee7b9 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -127,6 +127,8 @@ def _get_attrs(client_manager, parsed_args): if parsed_args.mac_address is not None: attrs['mac_address'] = parsed_args.mac_address + if parsed_args.dns_domain is not None: + attrs['dns_domain'] = parsed_args.dns_domain if parsed_args.dns_name is not None: attrs['dns_name'] = parsed_args.dns_name # It is possible that name is not updated during 'port set' @@ -269,6 +271,12 @@ def _add_updatable_args(parser): help=argparse.SUPPRESS, ) parser.add_argument( + '--dns-domain', + metavar='dns-domain', + 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 to this port " diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index caf3236a..f0a51967 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -86,8 +86,8 @@ 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 diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index 75af3587..ed6c8d7c 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -15,6 +15,7 @@ import argparse +from osc_lib.command import command from osc_lib import utils import six @@ -23,6 +24,7 @@ from openstackclient.identity import common as identity_common from openstackclient.network import common from openstackclient.network import sdk_utils from openstackclient.network import utils as network_utils +from openstackclient.network.v2 import _tag def _format_network_security_group_rules(sg_rules): @@ -106,6 +108,7 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne): help=_("Owner's project (name or ID)") ) identity_common.add_project_domain_option_to_parser(parser) + _tag.add_tag_option_to_parser_for_create(parser, _('security group')) return parser def _get_description(self, parsed_args): @@ -130,6 +133,8 @@ class CreateSecurityGroup(common.NetworkAndComputeShowOne): # Create the security group and display the results. obj = client.create_security_group(**attrs) + # tags cannot be set when created, so tags need to be set later. + _tag.update_tags_for_set(client, obj, parsed_args) display_columns, property_columns = _get_columns(obj) data = utils.get_item_properties( obj, @@ -198,6 +203,7 @@ class ListSecurityGroup(common.NetworkAndComputeLister): "(name or ID)") ) identity_common.add_project_domain_option_to_parser(parser) + _tag.add_tag_filtering_option_to_parser(parser, _('security group')) return parser def update_parser_compute(self, parser): @@ -220,19 +226,23 @@ class ListSecurityGroup(common.NetworkAndComputeLister): ).id filters['tenant_id'] = project_id filters['project_id'] = project_id + + _tag.get_tag_filtering_args(parsed_args, filters) data = client.security_groups(**filters) columns = ( "ID", "Name", "Description", - "Project ID" + "Project ID", + "tags" ) column_headers = ( "ID", "Name", "Description", - "Project" + "Project", + "Tags" ) return (column_headers, (utils.get_item_properties( @@ -282,6 +292,10 @@ class SetSecurityGroup(common.NetworkAndComputeCommand): ) return parser + def update_parser_network(self, parser): + _tag.add_tag_option_to_parser_for_set(parser, _('security group')) + return parser + def take_action_network(self, client, parsed_args): obj = client.find_security_group(parsed_args.group, ignore_missing=False) @@ -295,6 +309,9 @@ class SetSecurityGroup(common.NetworkAndComputeCommand): # the update. client.update_security_group(obj, **attrs) + # tags is a subresource and it needs to be updated separately. + _tag.update_tags_for_set(client, obj, parsed_args) + def take_action_compute(self, client, parsed_args): data = client.api.security_group_find(parsed_args.group) @@ -344,3 +361,25 @@ class ShowSecurityGroup(common.NetworkAndComputeShowOne): formatters=_formatters_compute ) return (display_columns, data) + + +class UnsetSecurityGroup(command.Command): + _description = _("Unset security group properties") + + def get_parser(self, prog_name): + parser = super(UnsetSecurityGroup, self).get_parser(prog_name) + parser.add_argument( + 'group', + metavar="<group>", + 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) + + # 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/subnet.py b/openstackclient/network/v2/subnet.py index 2c71e1e0..9c56186f 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -167,6 +167,7 @@ def convert_entries_to_gateway(entries): def _get_attrs(client_manager, parsed_args, is_create=True): attrs = {} + client = client_manager.network if 'name' in parsed_args and parsed_args.name is not None: attrs['name'] = str(parsed_args.name) @@ -179,7 +180,6 @@ def _get_attrs(client_manager, parsed_args, is_create=True): parsed_args.project_domain, ).id attrs['tenant_id'] = project_id - client = client_manager.network attrs['network_id'] = client.find_network(parsed_args.network, ignore_missing=False).id if parsed_args.subnet_pool is not None: @@ -200,10 +200,10 @@ def _get_attrs(client_manager, parsed_args, is_create=True): attrs['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode if parsed_args.ipv6_address_mode is not None: attrs['ipv6_address_mode'] = parsed_args.ipv6_address_mode - if parsed_args.network_segment is not None: - attrs['segment_id'] = client.find_segment( - parsed_args.network_segment, ignore_missing=False).id + if parsed_args.network_segment is not None: + attrs['segment_id'] = client.find_segment( + 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() @@ -559,6 +559,14 @@ class SetSubnet(command.Command): "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.") + ) + parser.add_argument( '--description', metavar='<description>', help=_("Set subnet description") @@ -581,7 +589,7 @@ class SetSubnet(command.Command): if not parsed_args.no_host_route: attrs['host_routes'] += obj.host_routes elif parsed_args.no_host_route: - attrs['host_routes'] = '' + attrs['host_routes'] = [] if 'allocation_pools' in attrs: if not parsed_args.no_allocation_pool: attrs['allocation_pools'] += obj.allocation_pools |
