def get_inventory(self, node_filter=None, refresh=False): node_list = None if node_filter and node_filter.nodes: # Explicit node list node_list = node_filter.nodes elif node_filter and node_filter.labels: # TODO: query k8s API to resolve to node list, and pass # it into RookCluster.get_discovered_devices raise NotImplementedError() devs = self.rook_cluster.get_discovered_devices(node_list) result = [] for node_name, node_devs in devs.items(): devs = [] for d in node_devs: dev = inventory.Device( path=d['name'], sys_api=dict(rotational='1' if d['rotational'] else '0', size=d['size']), available=d['empty'], rejected_reasons=[] if d['empty'] else ['not empty'], ) devs.append(dev) result.append( orchestrator.InventoryNode(node_name, inventory.Devices(devs))) return result
def get_inventory(self, host_filter=None, refresh=False): host_list = None if host_filter and host_filter.hosts: # Explicit host list host_list = host_filter.hosts elif host_filter and host_filter.labels: # TODO: query k8s API to resolve to host list, and pass # it into RookCluster.get_discovered_devices raise NotImplementedError() devs = self.rook_cluster.get_discovered_devices(host_list) result = [] for host_name, host_devs in devs.items(): devs = [] for d in host_devs: if 'cephVolumeData' in d and d['cephVolumeData']: devs.append(inventory.Device.from_json(json.loads(d['cephVolumeData']))) else: devs.append(inventory.Device( path = '/dev/' + d['name'], sys_api = dict( rotational = '1' if d['rotational'] else '0', size = d['size'] ), available = False, rejected_reasons=['device data coming from ceph-volume not provided'], )) result.append(orchestrator.InventoryHost(host_name, inventory.Devices(devs))) return result
def get_inventory( self, host_filter: Optional[orchestrator.InventoryFilter] = None, refresh: bool = False) -> List[orchestrator.InventoryHost]: host_list = None if host_filter and host_filter.hosts: # Explicit host list host_list = host_filter.hosts elif host_filter and host_filter.labels: # TODO: query k8s API to resolve to host list, and pass # it into RookCluster.get_discovered_devices raise NotImplementedError() discovered_devs = self.rook_cluster.get_discovered_devices(host_list) result = [] for host_name, host_devs in discovered_devs.items(): devs = [] for d in host_devs: devs.append(d) result.append( orchestrator.InventoryHost(host_name, inventory.Devices(devs))) return result
def __init__(self, name, devices=None): # type: (str, inventory.Devices) -> None if devices is None: devices = inventory.Devices([]) assert isinstance(devices, inventory.Devices) self.name = name # unique within cluster. For example a hostname. self.devices = devices
def __init__(self, name: str, devices: Optional[inventory.Devices] = None, labels: Optional[List[str]] = None, addr: Optional[str] = None) -> None: if devices is None: devices = inventory.Devices([]) if labels is None: labels = [] assert isinstance(devices, inventory.Devices) self.name = name # unique within cluster. For example a hostname. self.addr = addr or name self.devices = devices self.labels = labels
def get_hosts(self): """ Return a list of hosts managed by the orchestrator. Notes: - skip async: manager reads from cache. TODO: - InventoryNode probably needs to be able to report labels """ nodes = [ orchestrator.InventoryNode(host_name, inventory.Devices([])) for host_name in self.inventory_cache ] return orchestrator.TrivialReadCompletion(nodes)
def process(self, operation_id, raw_result): """ Format the output of host ls call :param operation_id: Not used in this output wizard :param raw_result: In this case is like the following json: { "status": "OK", "msg": "", "data": { "hosts": [ "host_a", "host_b", ... "host_x", ] } } :return: list of InventoryNodes """ # Just making more readable the method host_ls_json = raw_result inventory_nodes = [] try: json_resp = json.loads(host_ls_json) for host in json_resp["data"]["hosts"]: inventory_nodes.append( InventoryNode(host, inventory.Devices([]))) except ValueError: logger.exception("Malformed json response") except KeyError: logger.exception("Unexpected content in Ansible Runner Service" " response") except TypeError: logger.exception("Hosts data must be iterable in Ansible Runner " "Service response") return inventory_nodes
def get_hosts(self): # type: () -> List[orchestrator.InventoryNode] return [ orchestrator.InventoryNode(n, inventory.Devices([])) for n in self.rook_cluster.get_node_names() ]
def get_hosts(self): if self._inventory: return self._inventory return [orchestrator.InventoryNode('localhost', inventory.Devices([]))]