def args2body(self, parsed_args): body = {self.resource: {'value': parsed_args.id}} if parsed_args.gateway and parsed_args.gatewayport: body[self.resource].update({'gateway': parsed_args.gateway}) gw_id = neutronV20.find_resourceid_by_name_or_id( self.get_client(), GW_RESOURCE, parsed_args.gateway) body[self.resource].update({'gateway': gw_id}) gw_port_id = get_resource_by_name_or_id(self.get_client(), GW_PORT_RESOURCE, parsed_args.gatewayport, GATEWAY, gw_id) body[self.resource].update({'gatewayport': gw_port_id}) elif parsed_args.gatewayport: match = re.match(UUID_PATTERN, parsed_args.gatewayport) if not match: message = (_('--gatewayport should be a UUID')) raise exceptions.CommandError(message=message) gw_port_id = neutronV20.find_resourceid_by_name_or_id( self.get_client(), GW_PORT_RESOURCE, parsed_args.gatewayport) body[self.resource].update({'gatewayport': gw_port_id}) else: message = (_('--gatewayport should be specified')) raise exceptions.CommandError(message=message) return body
def updatable_args2body(parsed_args, body, for_create=True, ip_version=None): if parsed_args.disable_dhcp and parsed_args.enable_dhcp: raise exceptions.CommandError( _("You cannot enable and disable DHCP at the same time.")) if parsed_args.no_gateway: body['subnet'].update({'gateway_ip': None}) elif parsed_args.gateway: body['subnet'].update({'gateway_ip': parsed_args.gateway}) if parsed_args.name: body['subnet'].update({'name': parsed_args.name}) if parsed_args.disable_dhcp: body['subnet'].update({'enable_dhcp': False}) if parsed_args.enable_dhcp: body['subnet'].update({'enable_dhcp': True}) if parsed_args.allocation_pools: body['subnet']['allocation_pools'] = parsed_args.allocation_pools if parsed_args.host_routes: body['subnet']['host_routes'] = parsed_args.host_routes if parsed_args.dns_nameservers: body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers if for_create and parsed_args.ipv6_ra_mode: if ip_version == 4: raise exceptions.CommandError( _("--ipv6-ra-mode is invalid " "when --ip-version is 4")) body['subnet']['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode if for_create and parsed_args.ipv6_address_mode: if ip_version == 4: raise exceptions.CommandError( _("--ipv6-address-mode is " "invalid when --ip-version " "is 4")) body['subnet']['ipv6_address_mode'] = parsed_args.ipv6_address_mode
def _common_args2body(client, parsed_args, is_create=True): if parsed_args.redirect_url: if parsed_args.action != 'REDIRECT_TO_URL' and \ parsed_args.action != 'REDIRECT_TO_HOST': raise exceptions.CommandError(_('Action must be REDIRECT_TO_URL')) if parsed_args.redirect_pool: if parsed_args.action != 'REDIRECT_TO_POOL': raise exceptions.CommandError(_('Action must be REDIRECT_TO_POOL')) parsed_args.redirect_pool_id = _get_pool_id(client, parsed_args.redirect_pool) if (parsed_args.action == 'REDIRECT_TO_HOST' and not parsed_args.redirect_url): raise exceptions.CommandError(_('Redirect URL must be specified')) if (parsed_args.action == 'REDIRECT_TO_URL' and not parsed_args.redirect_url): raise exceptions.CommandError(_('Redirect URL must be specified')) if (parsed_args.action == 'REDIRECT_TO_POOL' and not parsed_args.redirect_pool): raise exceptions.CommandError(_('Redirect pool must be specified')) attributes = [ 'name', 'description', 'action', 'redirect_pool_id', 'redirect_url', 'position', 'admin_state_up' ] if is_create: parsed_args.listener_id = _get_listener_id(client, parsed_args.listener) attributes.extend(['listener_id', 'tenant_id']) body = {} neutronV20.update_dict(parsed_args, body, attributes) return {'l7policy': body}
def args2body_extradhcpopt(self, parsed_args, port): ops = [] if parsed_args.extra_dhcp_opts: # the extra_dhcp_opt params (opt_name & opt_value) # must come in pairs, if there is a parm error # both must be thrown out. opt_ele = {} edo_err_msg = _("Invalid --extra-dhcp-opt option, can only be: " "opt_name=<dhcp_option_name>,opt_value=<value>. " "You can repeat this option.") for opt in parsed_args.extra_dhcp_opts: if opt.split('=')[0] in ['opt_value', 'opt_name']: opt_ele.update(utils.str2dict(opt)) if (('opt_name' in opt_ele) and ('opt_value' in opt_ele)): if opt_ele['opt_value'] == 'null': opt_ele['opt_value'] = None ops.append(opt_ele) opt_ele = {} else: raise exceptions.CommandError(edo_err_msg) else: raise exceptions.CommandError(edo_err_msg) if ops: port.update({'extra_dhcp_opts': ops})
def args2body(self, parsed_args): _vpnservice_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'vpnservice', parsed_args.vpnservice_id) _ikepolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ikepolicy', parsed_args.ikepolicy_id) _ipsecpolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ipsecpolicy', parsed_args.ipsecpolicy_id) body = { 'vpnservice_id': _vpnservice_id, 'ikepolicy_id': _ikepolicy_id, 'ipsecpolicy_id': _ipsecpolicy_id, 'admin_state_up': parsed_args.admin_state_down, } if parsed_args.tenant_id: body['tenant_id'] = parsed_args.tenant_id if (bool(parsed_args.local_ep_group) != bool( parsed_args.peer_ep_group)): message = _("You must specify both local and peer endpoint " "groups.") raise exceptions.CommandError(message) if not parsed_args.peer_cidrs and not parsed_args.local_ep_group: message = _("You must specify endpoint groups or peer CIDR(s).") raise exceptions.CommandError(message) return super(CreateIPsecSiteConnection, self).args2body(parsed_args, body)
def validate_dpd_dict(dpd_dict): for key, value in dpd_dict.items(): if key not in dpd_supported_keys: message = _("DPD Dictionary KeyError: " "Reason-Invalid DPD key : " "'%(key)s' not in %(supported_key)s") % { 'key': key, 'supported_key': dpd_supported_keys } raise exceptions.CommandError(message) if key == 'action' and value not in dpd_supported_actions: message = _("DPD Dictionary ValueError: " "Reason-Invalid DPD action : " "'%(key_value)s' not in %(supported_action)s") % { 'key_value': value, 'supported_action': dpd_supported_actions } raise exceptions.CommandError(message) if key in ('interval', 'timeout'): try: if int(value) <= 0: raise ValueError() except ValueError: message = _("DPD Dictionary ValueError: " "Reason-Invalid positive integer value: " "'%(key)s' = %(value)s") % { 'key': key, 'value': value } raise exceptions.CommandError(message) else: dpd_dict[key] = int(value) return
def args2body(self, parsed_args, body=None): """Add in conditional args and then return all conn info.""" if body is None: body = {} if parsed_args.dpd: vpn_utils.validate_dpd_dict(parsed_args.dpd) body['dpd'] = parsed_args.dpd if parsed_args.local_ep_group: _local_epg = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'endpoint_group', parsed_args.local_ep_group) body['local_ep_group_id'] = _local_epg if parsed_args.peer_ep_group: _peer_epg = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'endpoint_group', parsed_args.peer_ep_group) body['peer_ep_group_id'] = _peer_epg if hasattr(parsed_args, 'mtu') and int(parsed_args.mtu) < 68: message = _("Invalid MTU value: MTU must be " "greater than or equal to 68.") raise exceptions.CommandError(message) # ToDo (Reedip) : Remove below check when peer-cidr is removed if parsed_args.peer_cidrs and parsed_args.local_ep_group: message = _("You cannot specify both endpoint groups and peer " "CIDR(s).") raise exceptions.CommandError(message) neutronv20.update_dict(parsed_args, body, [ 'peer_id', 'mtu', 'initiator', 'psk', 'peer_address', 'name', 'description', 'peer_cidrs' ]) return {self.resource: body}
def validate_lifetime_dict(lifetime_dict): for key, value in lifetime_dict.items(): if key not in lifetime_keys: message = _("Lifetime Dictionary KeyError: " "Reason-Invalid unit key : " "'%(key)s' not in %(supported_key)s") % { 'key': key, 'supported_key': lifetime_keys } raise exceptions.CommandError(message) if key == 'units' and value not in lifetime_units: message = _("Lifetime Dictionary ValueError: " "Reason-Invalid units : " "'%(key_value)s' not in %(supported_units)s") % { 'key_value': key, 'supported_units': lifetime_units } raise exceptions.CommandError(message) if key == 'value': try: if int(value) < 60: raise ValueError() except ValueError: message = _("Lifetime Dictionary ValueError: " "Reason-Invalid value should be at least 60:" "'%(key_value)s' = %(value)s") % { 'key_value': key, 'value': value } raise exceptions.CommandError(message) else: lifetime_dict['value'] = int(value) return
def updatable_args2body(parsed_args, body, for_create=True, ip_version=None): if parsed_args.disable_dhcp and parsed_args.enable_dhcp: raise exceptions.CommandError(_( "You cannot enable and disable DHCP at the same time.")) neutronV20.update_dict(parsed_args, body, ['name', 'allocation_pools', 'host_routes', 'dns_nameservers', 'description']) if parsed_args.no_gateway: body['gateway_ip'] = None elif parsed_args.gateway: body['gateway_ip'] = parsed_args.gateway if parsed_args.disable_dhcp: body['enable_dhcp'] = False if parsed_args.enable_dhcp: body['enable_dhcp'] = True if for_create and parsed_args.ipv6_ra_mode: if ip_version == 4: raise exceptions.CommandError(_("--ipv6-ra-mode is invalid " "when --ip-version is 4")) body['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode if for_create and parsed_args.ipv6_address_mode: if ip_version == 4: raise exceptions.CommandError(_("--ipv6-address-mode is " "invalid when --ip-version " "is 4")) body['ipv6_address_mode'] = parsed_args.ipv6_address_mode
def _get_attrs(client_manager, parsed_args): attrs = {} # Validate password if 'auth_type' in parsed_args: if parsed_args.auth_type != 'none': if 'password' not in parsed_args or parsed_args.password is None: raise exceptions.CommandError( _('Must provide password if ' 'auth-type is specified.')) if (parsed_args.auth_type == 'none' and parsed_args.password is not None): raise exceptions.CommandError( _('Must provide auth-type if ' 'password is specified.')) attrs['auth_type'] = parsed_args.auth_type if parsed_args.name is not None: attrs['name'] = parsed_args.name if 'remote_as' in parsed_args: attrs['remote_as'] = parsed_args.remote_as if 'peer_ip' in parsed_args: attrs['peer_ip'] = parsed_args.peer_ip if 'password' in parsed_args: attrs['password'] = parsed_args.password if 'project' in parsed_args and parsed_args.project is not None: identity_client = client_manager.identity project_id = nc_osc_utils.find_project( identity_client, parsed_args.project, parsed_args.project_domain, ).id attrs['tenant_id'] = project_id return attrs
def updatable_args2body(parsed_args, body): if parsed_args.gateway and parsed_args.no_gateway: raise exceptions.CommandError(_("--gateway option and " "--no-gateway option can " "not be used same time")) if parsed_args.disable_dhcp and parsed_args.enable_dhcp: raise exceptions.CommandError(_("--enable-dhcp and --disable-dhcp can " "not be used in the same command.")) if parsed_args.no_gateway: body['subnet'].update({'gateway_ip': None}) if parsed_args.gateway: body['subnet'].update({'gateway_ip': parsed_args.gateway}) if parsed_args.name: body['subnet'].update({'name': parsed_args.name}) if parsed_args.disable_dhcp: body['subnet'].update({'enable_dhcp': False}) if parsed_args.enable_dhcp: body['subnet'].update({'enable_dhcp': True}) if parsed_args.allocation_pools: body['subnet']['allocation_pools'] = parsed_args.allocation_pools if parsed_args.host_routes: body['subnet']['host_routes'] = parsed_args.host_routes if parsed_args.dns_nameservers: body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers
def validate_peer_attributes(parsed_args): # Validate AS number validators.validate_int_range(parsed_args, 'remote_as', neutronv20.bgp.speaker.MIN_AS_NUM, neutronv20.bgp.speaker.MAX_AS_NUM) # Validate password if parsed_args.auth_type != 'none' and parsed_args.password is None: raise exceptions.CommandError(_('Must provide password if auth-type ' 'is specified.')) if parsed_args.auth_type == 'none' and parsed_args.password: raise exceptions.CommandError(_('Must provide auth-type if password ' 'is specified.'))
def check_vlan_value(value): try: vlan_val = int(value) except ValueError: message = (_('Vlan value should be a valid integer ' 'in 0-4094 range')) raise exceptions.CommandError(message=message) if vlan_val not in range(0, 4095): message = (_('Vlan value should be in 0-4094 range')) raise exceptions.CommandError(message=message) return vlan_val
def args2body(self, parsed_args): _network_id = neutronV20.find_resourceid_by_name_or_id( self.get_client(), 'network', parsed_args.network_id) body = { 'subnet': { 'cidr': parsed_args.cidr, 'network_id': _network_id, 'ip_version': parsed_args.ip_version, }, } if parsed_args.gateway and parsed_args.no_gateway: raise exceptions.CommandError( _("--gateway option and " "--no-gateway option can " "not be used same time")) if parsed_args.no_gateway: body['subnet'].update({'gateway_ip': None}) if parsed_args.gateway: body['subnet'].update({'gateway_ip': parsed_args.gateway}) if parsed_args.tenant_id: body['subnet'].update({'tenant_id': parsed_args.tenant_id}) if parsed_args.name: body['subnet'].update({'name': parsed_args.name}) if parsed_args.disable_dhcp: body['subnet'].update({'enable_dhcp': False}) if parsed_args.allocation_pools: body['subnet']['allocation_pools'] = parsed_args.allocation_pools if parsed_args.host_routes: body['subnet']['host_routes'] = parsed_args.host_routes if parsed_args.dns_nameservers: body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers return body
def run(self, parsed_args): self.log.debug('run(%s)', parsed_args) neutron_client = self.get_client() neutron_client.format = parsed_args.request_format _extra_values = parse_args_to_dict(self.values_specs) _merge_args(self, parsed_args, _extra_values, self.values_specs) body = self.args2body(parsed_args) if self.resource in body: body[self.resource].update(_extra_values) else: body[self.resource] = _extra_values if not body[self.resource]: raise exceptions.CommandError( _("Must specify new values to update %s") % self.resource) if self.allow_names: _id = find_resourceid_by_name_or_id(neutron_client, self.resource, parsed_args.id) else: _id = find_resourceid_by_id(neutron_client, self.resource, parsed_args.id) obj_updator = getattr(neutron_client, "update_%s" % self.resource) obj_updator(_id, body) print >> self.app.stdout, (_('Updated %(resource)s: %(id)s') % { 'id': parsed_args.id, 'resource': self.resource }) return
def args2body(self, parsed_args): _vpnservice_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'vpnservice', parsed_args.vpnservice_id) _ikepolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ikepolicy', parsed_args.ikepolicy_id) _ipsecpolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ipsecpolicy', parsed_args.ipsecpolicy_id) if int(parsed_args.mtu) < 68: message = _("Invalid MTU value: MTU must be " "greater than or equal to 68") raise exceptions.CommandError(message) body = { 'vpnservice_id': _vpnservice_id, 'ikepolicy_id': _ikepolicy_id, 'ipsecpolicy_id': _ipsecpolicy_id, 'peer_address': parsed_args.peer_address, 'peer_id': parsed_args.peer_id, 'mtu': parsed_args.mtu, 'initiator': parsed_args.initiator, 'psk': parsed_args.psk, 'admin_state_up': parsed_args.admin_state_down, } if parsed_args.name: body['name'] = parsed_args.name if parsed_args.description: body['description'] = parsed_args.description if parsed_args.tenant_id: body['tenant_id'] = parsed_args.tenant_id if parsed_args.dpd: vpn_utils.validate_dpd_dict(parsed_args.dpd) body['dpd'] = parsed_args.dpd if parsed_args.peer_cidrs: body['peer_cidrs'] = parsed_args.peer_cidrs return {'ipsec_site_connection': body}
def run(self, parsed_args): self.log.debug('run(%s)' % parsed_args) neutron_client = self.get_client() neutron_client.format = parsed_args.request_format if '=' in parsed_args.interface: resource, value = parsed_args.interface.split('=', 1) if resource not in ['subnet', 'port']: exceptions.CommandError( _('You must specify either subnet or ' 'port for INTERFACE parameter.')) else: resource = 'subnet' value = parsed_args.interface _router_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, self.resource, parsed_args.router) _interface_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, resource, value) body = {'%s_id' % resource: _interface_id} portinfo = self.call_api(neutron_client, _router_id, body) print(self.success_message(parsed_args.router, portinfo), file=self.app.stdout)
def take_action(self, parsed_args): self.set_extra_attrs(parsed_args) neutron_client = self.get_client() _extra_values = parse_args_to_dict(self.values_specs) _merge_args(self, parsed_args, _extra_values, self.values_specs) body = self.args2body(parsed_args) if self.resource in body: body[self.resource].update(_extra_values) else: body[self.resource] = _extra_values if not body[self.resource]: raise exceptions.CommandError( _("Must specify new values to update %s") % self.cmd_resource) if self.allow_names: _id = find_resourceid_by_name_or_id(neutron_client, self.resource, parsed_args.id, cmd_resource=self.cmd_resource, parent_id=self.parent_id) else: _id = find_resourceid_by_id(neutron_client, self.resource, parsed_args.id, self.cmd_resource, self.parent_id) obj_updater = getattr(neutron_client, "update_%s" % self.cmd_resource) if self.parent_id: obj_updater(_id, self.parent_id, body) else: obj_updater(_id, body) print((_('Updated %(resource)s: %(id)s') % { 'id': parsed_args.id, 'resource': self.resource }), file=self.app.stdout) return
def take_action(self, parsed_args): client = self.get_client() extra_values = v2_0.parse_args_to_dict(self.values_specs) if extra_values: raise exceptions.CommandError( _("Invalid argument(s): --%s") % ', --'.join(extra_values)) tenant_id = parsed_args.tenant_id or parsed_args.pos_tenant_id if parsed_args.dry_run: data = client.validate_auto_allocated_topology_requirements( tenant_id) else: data = client.get_auto_allocated_topology(tenant_id) if self.resource in data: for k, v in data[self.resource].items(): if isinstance(v, list): value = "" for _item in v: if value: value += "\n" if isinstance(_item, dict): value += jsonutils.dumps(_item) else: value += str(_item) data[self.resource][k] = value elif v == "dry-run=pass": return ("dry-run", ), ("pass", ) elif v is None: data[self.resource][k] = '' return zip(*sorted(data[self.resource].items())) else: return None
def take_action(self, parsed_args): client = self.get_client() if not parsed_args.tag: raise exceptions.CommandError( _('Cannot add an empty value as tag')) resource_type, resource_id = _convert_resource_args( client, parsed_args) client.add_tag(resource_type, resource_id, parsed_args.tag)
def update_bandwidth_limit_args2body(parsed_args, body): max_kbps = parsed_args.max_kbps max_burst_kbps = parsed_args.max_burst_kbps if not (max_kbps or max_burst_kbps): raise exceptions.CommandError(_("Must provide max_kbps" " or max_burst_kbps option.")) neutronv20.update_dict(parsed_args, body, ['max_kbps', 'max_burst_kbps', 'tenant_id'])
def args2body(self, parsed_args): _vpnservice_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'vpnservice', parsed_args.vpnservice_id) _ikepolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ikepolicy', parsed_args.ikepolicy_id) _ipsecpolicy_id = neutronv20.find_resourceid_by_name_or_id( self.get_client(), 'ipsecpolicy', parsed_args.ipsecpolicy_id) if int(parsed_args.mtu) < 68: message = _("Invalid MTU value: MTU must be " "greater than or equal to 68") raise exceptions.CommandError(message) if (bool(parsed_args.local_ep_group) != bool(parsed_args.peer_ep_group)): message = _("You must specify both local and peer endpoint " "groups.") raise exceptions.CommandError(message) if parsed_args.peer_cidrs and parsed_args.local_ep_group: message = _("You cannot specify both endpoint groups and peer " "CIDR(s).") raise exceptions.CommandError(message) if not parsed_args.peer_cidrs and not parsed_args.local_ep_group: message = _("You must specify endpoint groups or peer CIDR(s).") raise exceptions.CommandError(message) body = { 'vpnservice_id': _vpnservice_id, 'ikepolicy_id': _ikepolicy_id, 'ipsecpolicy_id': _ipsecpolicy_id, 'admin_state_up': parsed_args.admin_state_down, } neutronv20.update_dict(parsed_args, body, ['peer_id', 'mtu', 'initiator', 'psk', 'peer_address']) if parsed_args.name: body['name'] = parsed_args.name if parsed_args.description: body['description'] = parsed_args.description if parsed_args.tenant_id: body['tenant_id'] = parsed_args.tenant_id if parsed_args.peer_cidrs: body['peer_cidrs'] = parsed_args.peer_cidrs return super(CreateIPsecSiteConnection, self).args2body(parsed_args, body)
def authenticate_user(self): """Make sure the user has provided all of the authentication info we need. """ if self.options.os_auth_strategy == 'keystone': if self.options.os_token or self.options.os_url: # Token flow auth takes priority if not self.options.os_token: raise exc.CommandError( "You must provide a token via" " either --os-token or env[OS_TOKEN]") if not self.options.os_url: raise exc.CommandError("You must provide a service URL via" " either --os-url or env[OS_URL]") else: # Validate password flow auth if not self.options.os_username: raise exc.CommandError( "You must provide a username via" " either --os-username or env[OS_USERNAME]") if not self.options.os_password: raise exc.CommandError( "You must provide a password via" " either --os-password or env[OS_PASSWORD]") if (not self.options.os_tenant_name and not self.options.os_tenant_id): raise exc.CommandError( "You must provide a tenant_name or tenant_id via" " --os-tenant-name, env[OS_TENANT_NAME]" " --os-tenant-id, or via env[OS_TENANT_ID]") if not self.options.os_auth_url: raise exc.CommandError( "You must provide an auth url via" " either --os-auth-url or via env[OS_AUTH_URL]") else: # not keystone if not self.options.os_url: raise exc.CommandError("You must provide a service URL via" " either --os-url or env[OS_URL]") self.client_manager = clientmanager.ClientManager( token=self.options.os_token, url=self.options.os_url, auth_url=self.options.os_auth_url, tenant_name=self.options.os_tenant_name, tenant_id=self.options.os_tenant_id, username=self.options.os_username, password=self.options.os_password, region_name=self.options.os_region_name, api_version=self.api_version, auth_strategy=self.options.os_auth_strategy, endpoint_type=self.options.endpoint_type, insecure=self.options.insecure, ca_cert=self.options.os_cacert, log_credentials=True) return
def _parse_persistence(parsed_args): persistence = None if parsed_args.session_persistence: parts = parsed_args.session_persistence.split(':') if not len(parts) == 2: raise exceptions.CommandError('Incorrect --session-persistence' ' format. Format is <TYPE>:<VALUE>') persistence = {'type': parts[0], 'cookie_name': parts[1]} return persistence
def _validate_int(self, name, value): try: return_value = int(value) except Exception: message = (_('Quota limit for %(name)s must be an integer') % { 'name': name }) raise exceptions.CommandError(message=message) return return_value
def update_dscp_args2body(parsed_args, body): dscp_mark = parsed_args.dscp_mark if int(dscp_mark) not in DSCP_VALID_MARKS: raise exceptions.CommandError( _("DSCP mark: %s not supported. " "Please note value can either be 0 " "or any even number from 8-56 " "excluding 42, 44, 50, 52 and " "54.") % dscp_mark) neutronv20.update_dict(parsed_args, body, ['dscp_mark'])
def validate_ip_subnet(parsed_args, attr_name): val = getattr(parsed_args, attr_name) if not val: return try: netaddr.IPNetwork(val) except (netaddr.AddrFormatError, ValueError): raise exceptions.CommandError( (_('%(attr_name)s "%(val)s" is not a valid CIDR.') % {'attr_name': attr_name.replace('_', '-'), 'val': val}))
def take_action(self, parsed_args): if not parsed_args.all and not parsed_args.tag: raise exceptions.CommandError( _("--all or --tag must be specified")) client = self.get_client() resource_type, resource_id = _convert_resource_args( client, parsed_args) if parsed_args.all: client.remove_tag_all(resource_type, resource_id) else: client.remove_tag(resource_type, resource_id, parsed_args.tag)
def take_action(self, parsed_args): neutron_client = self.get_client() neutron_client.format = parsed_args.request_format if not parsed_args.gateway: message = (_('--gateway option should be specified')) raise exceptions.CommandError(message=message) gw_id = neutronV20.find_resourceid_by_name_or_id( neutron_client, 'nuage_gateway', parsed_args.gateway) self.values_specs.append('--gateway=%s' % gw_id) return super(ListGatewayPort, self).take_action(parsed_args)
def updatable_args2body(parsed_args, body): if parsed_args.gateway and parsed_args.no_gateway: raise exceptions.CommandError( _("--gateway option and " "--no-gateway option can " "not be used same time")) if parsed_args.disable_dhcp and parsed_args.enable_dhcp: raise exceptions.CommandError( _("--enable-dhcp and --disable-dhcp can " "not be used in the same command.")) if parsed_args.no_gateway: body['subnet'].update({'gateway_ip': None}) if parsed_args.gateway: body['subnet'].update({'gateway_ip': parsed_args.gateway}) if parsed_args.name: body['subnet'].update({'name': parsed_args.name}) if parsed_args.disable_dhcp: body['subnet'].update({'enable_dhcp': False}) if parsed_args.enable_dhcp: body['subnet'].update({'enable_dhcp': True}) if parsed_args.allocation_pools: body['subnet']['allocation_pools'] = parsed_args.allocation_pools if parsed_args.host_routes: body['subnet']['host_routes'] = parsed_args.host_routes if parsed_args.dns_nameservers: body['subnet']['dns_nameservers'] = parsed_args.dns_nameservers if parsed_args.ipv6_ra_mode: if parsed_args.ip_version == 4: raise exceptions.CommandError( _("--ipv6-ra-mode is invalid " "when --ip-version is 4")) body['subnet']['ipv6_ra_mode'] = parsed_args.ipv6_ra_mode if parsed_args.ipv6_address_mode: if parsed_args.ip_version == 4: raise exceptions.CommandError( _("--ipv6-address-mode is " "invalid when --ip-version " "is 4")) body['subnet']['ipv6_address_mode'] = parsed_args.ipv6_address_mode