def _list_devices(self, cmd): """ This (all lines starting with ">") is how it is supposed to work. As of now, it's not yet implemented: > :returns: Either JSON: > [ > { > "name": "sda", > "host": "foo", > ... lots of stuff from ceph-volume ... > "stamp": when this state was refreshed > }, > ] > > or human readable: > > HOST DEV SIZE DEVID(vendor\\_model\\_serial) IN-USE TIMESTAMP > > Note: needs ceph-volume on the host. Note: this does not have to be completely synchronous. Slightly out of date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ host = cmd.get('host', None) if host: nf = orchestrator.InventoryFilter() nf.nodes = [host] else: nf = None completion = self.get_inventory(node_filter=nf) self._orchestrator_wait([completion]) if cmd.get('format', 'plain') == 'json': data = [n.to_json() for n in completion.result] return HandleCommandResult(stdout=json.dumps(data)) else: # Return a human readable version result = "" for inventory_node in completion.result: result += "{0}:\n".format(inventory_node.name) for d in inventory_node.devices: result += " {0} ({1}, {2}b)\n".format( d.id, d.type, d.size) result += "\n" return HandleCommandResult(stdout=result)
def _list_devices(self, cmd): """ This (all lines starting with ">") is how it is supposed to work. As of now, it's not yet implemented: > :returns: Either JSON: > [ > { > "name": "sda", > "host": "foo", > ... lots of stuff from ceph-volume ... > "stamp": when this state was refreshed > }, > ] > > or human readable: > > HOST DEV SIZE DEVID(vendor\_model\_serial) IN-USE TIMESTAMP > > Note: needs ceph-volume on the host. Note: this does not have to be completely synchronous. Slightly out of date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ node = cmd.get('node', None) if node: nf = orchestrator.InventoryFilter() nf.nodes = [node] else: nf = None completion = self._oremote("get_inventory", node_filter=nf) self._wait([completion]) # Spit out a human readable version result = "" for inventory_node in completion.result: result += "{0}:\n".format(inventory_node.name) for d in inventory_node.devices: result += " {0} ({1}, {2}b)\n".format(d.id, d.type, d.size) result += "\n" return 0, result, ""
def _list_devices(self, host=None, format='plain', refresh=False): # type: (Optional[List[str]], str, bool) -> HandleCommandResult """ Provide information about storage devices present in cluster hosts Note: this does not have to be completely synchronous. Slightly out of date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ nf = orchestrator.InventoryFilter(nodes=host) if host else None completion = self.get_inventory(node_filter=nf, refresh=refresh) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) if format == 'json': data = [n.to_json() for n in completion.result] return HandleCommandResult(stdout=json.dumps(data)) else: out = [] table = PrettyTable( ['HOST', 'PATH', 'TYPE', 'SIZE', 'DEVICE', 'AVAIL', 'REJECT REASONS'], border=False) table.align = 'l' table._align['SIZE'] = 'r' table.left_padding_width = 0 table.right_padding_width = 1 for host_ in completion.result: # type: orchestrator.InventoryNode for d in host_.devices.devices: # type: Device table.add_row( ( host_.name, d.path, d.human_readable_type, format_bytes(d.sys_api.get('size', 0), 5), d.device_id, d.available, ', '.join(d.rejected_reasons) ) ) out.append(table.get_string()) return HandleCommandResult(stdout='\n'.join(out))
def _list_devices(self, host=None, format='plain', refresh=False): # type: (List[str], str, bool) -> HandleCommandResult """ Provide information about storage devices present in cluster hosts Note: this does not have to be completely synchronous. Slightly out of date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ nf = orchestrator.InventoryFilter(nodes=host) if host else None completion = self.get_inventory(node_filter=nf, refresh=refresh) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) if format == 'json': data = [n.to_json() for n in completion.result] return HandleCommandResult(stdout=json.dumps(data)) else: out = [] for host in completion.result: # type: orchestrator.InventoryNode out.append('Host {}:'.format(host.name)) table = PrettyTable( ['Path', 'Type', 'Size', 'Available', 'Ceph Device ID', 'Reject Reasons'], border=False) table._align['Path'] = 'l' for d in host.devices.devices: # type: Device table.add_row( ( d.path, d.human_readable_type, format_bytes(d.sys_api.get('size', 0), 5, colored=False), d.available, d.device_id, ', '.join(d.rejected_reasons) ) ) out.append(table.get_string()) return HandleCommandResult(stdout='\n'.join(out))
def _list_devices(self, cmd): node = cmd.get('node', None) if node: nf = orchestrator.InventoryFilter() nf.nodes = [node] else: nf = None completion = self._oremote("get_inventory", node_filter=nf) self._wait([completion]) # Spit out a human readable version result = "" for inventory_node in completion.result: result += "{0}:\n".format(inventory_node.name) for d in inventory_node.devices: result += " {0} ({1}, {2}b)\n".format(d.id, d.type, d.size) result += "\n" return 0, result, ""
def _list_devices(self, host=None, format='plain', refresh=False): # type: (List[str], str, bool) -> HandleCommandResult """ Provide information about storage devices present in cluster hosts Note: this does not have to be completely synchronous. Slightly out of date hardware inventory is fine as long as hardware ultimately appears in the output of this command. """ nf = orchestrator.InventoryFilter(nodes=host) if host else None completion = self.get_inventory(node_filter=nf, refresh=refresh) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) if format == 'json': data = [n.to_json() for n in completion.result] return HandleCommandResult(stdout=json.dumps(data)) else: # Return a human readable version result = "" for inventory_node in completion.result: result += "Host {0}:\n".format(inventory_node.name) if inventory_node.devices: result += inventory_node.devices[0].pretty_print( only_header=True) else: result += "No storage devices found" for d in inventory_node.devices: result += d.pretty_print() result += "\n" return HandleCommandResult(stdout=result)