def _get_ports_collection(self, uuid, node_uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) if self._from_node and not uuid: raise exception.InvalidParameterValue(_("node id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.EthernetPort.get_by_uuid( pecan.request.context, marker) if self._from_hosts: ports = objects.EthernetPort.get_by_host(pecan.request.context, uuid, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif self._from_node: ports = objects.EthernetPort.get_by_numa_node( pecan.request.context, uuid, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: if uuid: ports = objects.EthernetPort.get_by_host(pecan.request.context, uuid, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: ports = objects.EthernetPort.list(pecan.request.context, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) return EthernetPortCollection.convert_with_links(ports, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_system_collection(self, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): limit = api_utils.validate_limit(limit) sort_dir = api_utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.System.get_by_uuid(pecan.request.context, marker) system = pecan.request.dbapi.system_get_list(limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) for i in system: i.capabilities['bm_region'] = self._bm_region_get() return SystemCollection.convert_with_links(system, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_lldp_tlvs_collection(self, uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_lldp_agents and not uuid: raise exception.InvalidParameterValue( _("LLDP agent id not specified.")) if self._from_lldp_neighbours and not uuid: raise exception.InvalidParameterValue( _("LLDP neighbour id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.LLDPTLV.get_by_id(pecan.request.context, marker) if self._from_lldp_agents: tlvs = objects.LLDPTLV.get_by_agent(pecan.request.context, uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif self._from_lldp_neighbours: tlvs = objects.LLDPTLV.get_by_neighbour(pecan.request.context, uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: tlvs = objects.LLDPTLV.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return LLDPTLVCollection.convert_with_links(tlvs, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_lldp_agents_collection(self, uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) if self._from_ports and not uuid: raise exception.InvalidParameterValue(_("Port id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.LLDPAgent.get_by_uuid(pecan.request.context, marker) if self._from_hosts: agents = objects.LLDPAgent.get_by_host(pecan.request.context, uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif self._from_ports: agents = [] agent = objects.LLDPAgent.get_by_port(pecan.request.context, uuid) agents.append(agent) else: agents = objects.LLDPAgent.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return LLDPAgentCollection.convert_with_links(agents, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_pci_devices_collection(self, uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.PCIDevice.get_by_uuid(pecan.request.context, marker) if self._from_hosts: # devices = pecan.request.dbapi.pci_device_get_by_host( devices = objects.PCIDevice.get_by_host(pecan.request.context, uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: if uuid: # devices = pecan.request.dbapi.pci_device_get_by_host( devices = objects.PCIDevice.get_by_host(pecan.request.context, uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: # devices = pecan.request.dbapi.pci_device_get_list( devices = objects.PCIDevice.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return PCIDeviceCollection.convert_with_links(devices, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_sensorgroups_collection(self, uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.SensorGroup.get_by_uuid( pecan.request.context, marker) if self._from_hosts: sensorgroups = pecan.request.dbapi.sensorgroup_get_by_host( uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: if uuid: sensorgroups = pecan.request.dbapi.sensorgroup_get_by_host( uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: sensorgroups = pecan.request.dbapi.sensorgroup_get_list( limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return SensorGroupCollection.convert_with_links(sensorgroups, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_lldp_neighbours_collection(self, uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) if self._from_ports and not uuid: raise exception.InvalidParameterValue(_("Port id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.LLDPNeighbour.get_by_uuid( pecan.request.context, marker) if self._from_hosts: neighbours = pecan.request.dbapi.lldp_neighbour_get_by_host( uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif self._from_ports: neighbours = pecan.request.dbapi.lldp_neighbour_get_by_port( uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: neighbours = pecan.request.dbapi.lldp_neighbour_get_list( limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return LLDPNeighbourCollection.convert_with_links(neighbours, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_nodes_collection(self, host_uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not host_uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.Node.get_by_uuid(pecan.request.context, marker) if host_uuid: nodes = objects.Node.get_by_host(pecan.request.context, host_uuid, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: nodes = objects.Node.list(pecan.request.context, limit, marker=marker_obj, sort_key=sort_key, sort_dir=sort_dir) return NodeCollection.convert_with_links(nodes, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_cpus_collection(self, i_uuid, node_uuid, marker, limit, sort_key, sort_dir, expand=False, resource_url=None): if self._from_hosts and not i_uuid: raise exception.InvalidParameterValue(_("Host id not specified.")) if self._from_node and not i_uuid: raise exception.InvalidParameterValue(_("Node id not specified.")) limit = utils.validate_limit(limit) sort_dir = utils.validate_sort_dir(sort_dir) marker_obj = None if marker: marker_obj = objects.CPU.get_by_uuid(pecan.request.context, marker) if self._from_hosts: # cpus = pecan.request.dbapi.cpu_get_by_host( cpus = objects.CPU.get_by_host(pecan.request.context, i_uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif self._from_node: # cpus = pecan.request.dbapi.cpu_get_by_node( cpus = objects.CPU.get_by_node(pecan.request.context, i_uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: if i_uuid and not node_uuid: # cpus = pecan.request.dbapi.cpu_get_by_host( cpus = objects.CPU.get_by_host(pecan.request.context, i_uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif i_uuid and node_uuid: # cpus = pecan.request.dbapi.cpu_get_by_host_node( cpus = objects.CPU.get_by_host_node(pecan.request.context, i_uuid, node_uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) elif node_uuid: # cpus = pecan.request.dbapi.cpu_get_by_host_node( cpus = objects.CPU.get_by_node(pecan.request.context, i_uuid, node_uuid, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) else: # cpus = pecan.request.dbapi.icpu_get_list( cpus = objects.CPU.list(pecan.request.context, limit, marker_obj, sort_key=sort_key, sort_dir=sort_dir) return CPUCollection.convert_with_links(cpus, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)