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 _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_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_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 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.qos_policy: attrs['qos_policy_id'] = client.find_qos_policy( parsed_args.qos_policy, ignore_missing=False).id with common.check_missing_extension_if_error( self.app.client_manager.network, attrs): obj = client.create_port(**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)