def convert_with_links(rpc_portgroup, fields=None, sanitize=True): """Add links to the portgroup.""" portgroup = api_utils.object_to_dict( rpc_portgroup, link_resource='portgroups', fields=('address', 'extra', 'internal_info', 'mode', 'name', 'properties', 'standalone_ports_supported')) api_utils.populate_node_uuid(rpc_portgroup, portgroup) url = api.request.public_url portgroup['ports'] = [ link.make_link('self', url, 'portgroups', rpc_portgroup.uuid + "/ports"), link.make_link('bookmark', url, 'portgroups', rpc_portgroup.uuid + "/ports", bookmark=True) ] if fields is not None: api_utils.check_for_invalid_fields(fields, portgroup) if not sanitize: return portgroup api_utils.sanitize_dict(portgroup, fields) return portgroup
def convert_with_links(rpc_allocation, fields=None, sanitize=True): allocation = api_utils.object_to_dict( rpc_allocation, link_resource='allocations', fields=( 'candidate_nodes', 'extra', 'last_error', 'name', 'owner', 'resource_class', 'state', 'traits' ) ) try: api_utils.populate_node_uuid(rpc_allocation, allocation) except exception.NodeNotFound: allocation['node_uuid'] = None if fields is not None: api_utils.check_for_invalid_fields(fields, set(allocation)) if sanitize: allocation_sanitize(allocation, fields) return allocation
def convert_with_links(rpc_port, fields=None, sanitize=True): port = api_utils.object_to_dict( rpc_port, link_resource='ports', fields=( 'address', 'extra', 'internal_info', 'is_smartnic', 'local_link_connection', 'physical_network', 'pxe_enabled', ) ) api_utils.populate_node_uuid(rpc_port, port) if rpc_port.portgroup_id: pg = objects.Portgroup.get(api.request.context, rpc_port.portgroup_id) port['portgroup_uuid'] = pg.uuid else: port['portgroup_uuid'] = None _validate_fields(port, fields) if not sanitize: return port port_sanitize(port, fields=fields) return port
def convert_with_links(rpc_connector, fields=None, sanitize=True): connector = api_utils.object_to_dict(rpc_connector, link_resource='volume/connectors', fields=('connector_id', 'extra', 'type')) api_utils.populate_node_uuid(rpc_connector, connector) if fields is not None: api_utils.check_for_invalid_fields(fields, connector) if not sanitize: return connector api_utils.sanitize_dict(connector, fields) return connector
def convert_with_links(rpc_target, fields=None, sanitize=True): target = api_utils.object_to_dict(rpc_target, link_resource='volume/targets', fields=('boot_index', 'extra', 'properties', 'volume_id', 'volume_type')) api_utils.populate_node_uuid(rpc_target, target) if fields is not None: api_utils.check_for_invalid_fields(fields, target) if not sanitize: return target api_utils.sanitize_dict(target, fields) return target