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)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_router(parsed_args.router, ignore_missing=False) tmp_routes = copy.deepcopy(obj.routes) tmp_external_gateway_info = copy.deepcopy(obj.external_gateway_info) attrs = {} if parsed_args.routes: try: for route in parsed_args.routes: route['nexthop'] = route.pop('gateway') tmp_routes.remove(route) except ValueError: msg = (_("Router does not contain route %s") % route) raise exceptions.CommandError(msg) attrs['routes'] = tmp_routes if parsed_args.qos_policy: try: if (tmp_external_gateway_info['network_id'] and tmp_external_gateway_info['qos_policy_id']): pass except (KeyError, TypeError): msg = _("Router does not have external network or qos policy") raise exceptions.CommandError(msg) else: attrs['external_gateway_info'] = { 'network_id': tmp_external_gateway_info['network_id'], 'qos_policy_id': None } if parsed_args.external_gateway: attrs['external_gateway_info'] = {} if attrs: client.update_router(obj, **attrs) # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_unset(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 = {} if parsed_args.dns_nameservers: attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers) _update_arguments(attrs['dns_nameservers'], parsed_args.dns_nameservers, 'dns-nameserver') if parsed_args.host_routes: attrs['host_routes'] = copy.deepcopy(obj.host_routes) _update_arguments( attrs['host_routes'], convert_entries_to_nexthop(parsed_args.host_routes), 'host-route') if parsed_args.allocation_pools: attrs['allocation_pools'] = copy.deepcopy(obj.allocation_pools) _update_arguments(attrs['allocation_pools'], parsed_args.allocation_pools, 'allocation-pool') if parsed_args.service_types: attrs['service_types'] = copy.deepcopy(obj.service_types) _update_arguments(attrs['service_types'], parsed_args.service_types, 'service-type') if attrs: client.update_subnet(obj, **attrs) # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_unset(client, obj, parsed_args)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_port(parsed_args.port, ignore_missing=False) # SDK ignores update() if it receives a modified obj and attrs # To handle the same tmp_obj is created in all take_action of # Unset* classes tmp_fixed_ips = copy.deepcopy(obj.fixed_ips) tmp_binding_profile = copy.deepcopy(obj.binding_profile) tmp_secgroups = copy.deepcopy(obj.security_group_ids) tmp_addr_pairs = copy.deepcopy(obj.allowed_address_pairs) _prepare_fixed_ips(self.app.client_manager, parsed_args) attrs = {} if parsed_args.fixed_ip: try: for ip in parsed_args.fixed_ip: tmp_fixed_ips.remove(ip) except ValueError: msg = _("Port does not contain fixed-ip %s") % ip raise exceptions.CommandError(msg) attrs['fixed_ips'] = tmp_fixed_ips if parsed_args.binding_profile: try: for key in parsed_args.binding_profile: del tmp_binding_profile[key] except KeyError: msg = _("Port does not contain binding-profile %s") % key raise exceptions.CommandError(msg) attrs['binding:profile'] = tmp_binding_profile if parsed_args.security_group_ids: try: for sg in parsed_args.security_group_ids: sg_id = client.find_security_group(sg, ignore_missing=False).id tmp_secgroups.remove(sg_id) except ValueError: msg = _("Port does not contain security group %s") % sg raise exceptions.CommandError(msg) attrs['security_group_ids'] = tmp_secgroups if parsed_args.allowed_address_pairs: try: for addr in _convert_address_pairs(parsed_args): tmp_addr_pairs.remove(addr) except ValueError: msg = _("Port does not contain allowed-address-pair %s") % addr raise exceptions.CommandError(msg) attrs['allowed_address_pairs'] = tmp_addr_pairs if parsed_args.qos_policy: attrs['qos_policy_id'] = None if parsed_args.data_plane_status: attrs['data_plane_status'] = None if parsed_args.numa_policy: attrs['numa_affinity_policy'] = None if attrs: client.update_port(obj, **attrs) # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_unset(client, obj, parsed_args)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_network(parsed_args.network, ignore_missing=False) # NOTE: As of now, UnsetNetwork has no attributes which need # to be updated by update_network(). # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_unset(client, obj, parsed_args)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_network(parsed_args.network, ignore_missing=False) attrs = self._parse_extra_properties(parsed_args.extra_properties) if attrs: client.update_network(obj, **attrs) # tags is a subresource and it needs to be updated separately. _tag.update_tags_for_unset(client, obj, parsed_args)
def take_action(self, parsed_args): client = self.app.client_manager.network obj = client.find_ip( parsed_args.floating_ip, ignore_missing=False, ) attrs = {} if parsed_args.port: attrs['port_id'] = None if parsed_args.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_unset(client, obj, parsed_args)
def test_update_tags_for_unset(self): mock_client = mock.MagicMock() mock_obj = mock.MagicMock() mock_parsed_args = mock.MagicMock() # No new tags mock_obj.tags = ['tag1'] mock_parsed_args.all_tag = False mock_parsed_args.tags = None tags.update_tags_for_unset(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_not_called() # Clear all tags mock_obj.tags = ['tag1'] mock_parsed_args.all_tag = True mock_parsed_args.tags = None tags.update_tags_for_unset(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_called_once_with(mock_obj, []) # Remove one tag mock_client.set_tags.reset_mock() mock_obj.tags = ['tag1', 'tag2'] mock_parsed_args.all_tag = False mock_parsed_args.tags = ['tag2'] tags.update_tags_for_unset(mock_client, mock_obj, mock_parsed_args) mock_client.set_tags.assert_called_once_with(mock_obj, ['tag1'])