def take_action_network(self, client, parsed_args): # Build the create attributes. attrs = {} attrs['name'] = parsed_args.name attrs['description'] = self._get_description(parsed_args) if parsed_args.stateful: attrs['stateful'] = True if parsed_args.stateless: attrs['stateful'] = False if parsed_args.project is not None: identity_client = self.app.client_manager.identity project_id = identity_common.find_project( identity_client, parsed_args.project, parsed_args.project_domain, ).id attrs['project_id'] = project_id attrs.update(self._parse_extra_properties( parsed_args.extra_properties)) # 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, property_columns, formatters=_formatters_network) return (display_columns, data)
def take_action(self, parsed_args): client = self.app.client_manager.network attrs = {} obj = client.find_ip( parsed_args.floating_ip, ignore_missing=False, ) if parsed_args.port: port = client.find_port(parsed_args.port, ignore_missing=False) attrs['port_id'] = port.id if parsed_args.fixed_ip_address: attrs['fixed_ip_address'] = parsed_args.fixed_ip_address if parsed_args.description: attrs['description'] = parsed_args.description if parsed_args.qos_policy: attrs['qos_policy_id'] = client.find_qos_policy( 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 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)
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) if 'dns_nameservers' in attrs: if not parsed_args.no_dns_nameservers: attrs['dns_nameservers'] += obj.dns_nameservers elif parsed_args.no_dns_nameservers: attrs['dns_nameservers'] = [] if 'host_routes' in attrs: if not parsed_args.no_host_route: attrs['host_routes'] += obj.host_routes elif parsed_args.no_host_route: attrs['host_routes'] = [] if 'allocation_pools' in attrs: if not parsed_args.no_allocation_pool: attrs['allocation_pools'] += obj.allocation_pools elif parsed_args.no_allocation_pool: attrs['allocation_pools'] = [] if 'service_types' in attrs: attrs['service_types'] += obj.service_types if attrs: client.update_subnet(obj, **attrs) # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_set(client, obj, parsed_args) return
def take_action(self, parsed_args): client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) if parsed_args.ha: attrs['ha'] = True if parsed_args.no_ha: attrs['ha'] = False attrs.update(self._parse_extra_properties( parsed_args.extra_properties)) obj = client.create_router(**attrs) # 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")) raise exceptions.CommandError(msg) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def take_action(self, parsed_args): client = self.app.client_manager.network _prepare_fixed_ips(self.app.client_manager, parsed_args) obj = client.find_port(parsed_args.port, ignore_missing=False) attrs = _get_attrs(self.app.client_manager, parsed_args) if parsed_args.no_binding_profile: attrs['binding:profile'] = {} if parsed_args.binding_profile: if 'binding:profile' not in attrs: attrs['binding:profile'] = copy.deepcopy(obj.binding_profile) attrs['binding:profile'].update(parsed_args.binding_profile) if parsed_args.no_fixed_ip: attrs['fixed_ips'] = [] if parsed_args.fixed_ip: if 'fixed_ips' not in attrs: # obj.fixed_ips = [{}] if no fixed IPs are set. # Only append this to attrs['fixed_ips'] if actual fixed # IPs are present to avoid adding an empty dict. attrs['fixed_ips'] = [ip for ip in obj.fixed_ips if ip] attrs['fixed_ips'].extend(parsed_args.fixed_ip) if parsed_args.no_security_group: attrs['security_group_ids'] = [] if parsed_args.security_group: if 'security_group_ids' not in attrs: # NOTE(dtroyer): Get existing security groups, iterate the # list to force a new list object to be # created and make sure the SDK Resource # marks the attribute 'dirty'. attrs['security_group_ids'] = [ id for id in obj.security_group_ids ] attrs['security_group_ids'].extend( client.find_security_group(sg, ignore_missing=False).id for sg in parsed_args.security_group) if parsed_args.no_allowed_address_pair: 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'].extend( _convert_address_pairs(parsed_args)) if parsed_args.data_plane_status: attrs['data_plane_status'] = parsed_args.data_plane_status if attrs: with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): client.update_port(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(self, parsed_args): client = self.app.client_manager.network _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) if parsed_args.binding_profile is not None: attrs['binding:profile'] = parsed_args.binding_profile if parsed_args.fixed_ip: attrs['fixed_ips'] = parsed_args.fixed_ip elif parsed_args.no_fixed_ip: 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 ] 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)) 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 set_tags_in_post = bool( client.find_extension('tag-ports-during-bulk-creation')) if set_tags_in_post: if parsed_args.no_tag: attrs['tags'] = [] if parsed_args.tags: attrs['tags'] = list(set(parsed_args.tags)) attrs.update(self._parse_extra_properties( parsed_args.extra_properties)) with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): obj = client.create_port(**attrs) if not set_tags_in_post: # 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_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def take_action(self, parsed_args): client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) 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) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_router(parsed_args.router, ignore_missing=False) # Get the common attributes. attrs = _get_attrs(self.app.client_manager, parsed_args) # Get the route attributes. if parsed_args.ha: attrs['ha'] = True elif parsed_args.no_ha: attrs['ha'] = False if parsed_args.routes is not None: for route in parsed_args.routes: route['nexthop'] = route.pop('gateway') attrs['routes'] = parsed_args.routes if not parsed_args.no_route: # Map the route keys and append to the current routes. # The REST API will handle route validation and duplicates. 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")) raise exceptions.CommandError(msg) 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")) raise exceptions.CommandError(msg) else: if not attrs.get('external_gateway_info'): attrs['external_gateway_info'] = {} 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 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)) if attrs: client.update_router(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(self, parsed_args): client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) # NeutronServer expects prefixes to be a List if "prefixes" not in attrs: attrs['prefixes'] = [] 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) display_columns, columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def take_action_network(self, client, parsed_args): attrs = _get_attrs(self.app.client_manager, parsed_args) with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): 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)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_network(parsed_args.network, ignore_missing=False) attrs = _get_attrs_network(self.app.client_manager, parsed_args) if attrs: with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): client.update_network(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(self, parsed_args): client = self.app.client_manager.network obj = client.find_subnet_pool(parsed_args.subnet_pool, ignore_missing=False) attrs = _get_attrs(self.app.client_manager, parsed_args) # Existing prefixes must be a subset of the new prefixes. if 'prefixes' in attrs: attrs['prefixes'].extend(obj.prefixes) if attrs: client.update_subnet_pool(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_network(self, client, parsed_args): obj = client.find_security_group(parsed_args.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 # NOTE(rtheis): Previous behavior did not raise a CommandError # if there were no updates. Maintain this behavior and issue # 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_network(self, client, parsed_args): attrs = _get_attrs_network(self.app.client_manager, parsed_args) if parsed_args.transparent_vlan: attrs['vlan_transparent'] = True if parsed_args.no_transparent_vlan: attrs['vlan_transparent'] = False with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): obj = client.create_network(**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_columns_network(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (display_columns, data)
def test_update_tags_for_set(self): mock_client = mock.MagicMock() mock_obj = mock.MagicMock() mock_parsed_args = mock.MagicMock() # no-tag True path mock_parsed_args.no_tag = True mock_parsed_args.tags = ['tag1'] mock_obj.tags = None tags.update_tags_for_set(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_called_once_with( mock_obj, list(mock_parsed_args.tags)) # no-tag False path mock_client.set_tags.reset_mock() mock_parsed_args.no_tag = False mock_parsed_args.tags = ['tag1'] mock_obj.tags = ['tag2'] expected_list = ['tag1', 'tag2'] tags.update_tags_for_set(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_called_once_with(mock_obj, expected_list) # no new tags path mock_client.set_tags.reset_mock() mock_parsed_args.no_tag = False mock_parsed_args.tags = None mock_obj.tags = ['tag2'] tags.update_tags_for_set(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_not_called()