def test_gb(self): item = formatting.gb(2) self.assertEqual(2048, item.original) self.assertEqual("2G", item.formatted) item = formatting.gb("2") self.assertEqual(2048, item.original) self.assertEqual("2G", item.formatted) item = formatting.gb("2.0") self.assertEqual(2048, item.original) self.assertEqual("2G", item.formatted)
def test_gb(self): item = formatting.gb(2) self.assertEqual(2048, item.original) self.assertEqual('2G', item.formatted) item = formatting.gb('2') self.assertEqual(2048, item.original) self.assertEqual('2G', item.formatted) item = formatting.gb('2.0') self.assertEqual(2048, item.original) self.assertEqual('2G', item.formatted)
def execute(self, args): manager = SoftLayer.HardwareManager(self.client) tags = None if args.get('--tags'): tags = [tag.strip() for tag in args.get('--tags').split(',')] servers = manager.list_hardware( hostname=args.get('--hostname'), domain=args.get('--domain'), cpus=args.get('--cpu'), memory=args.get('--memory'), datacenter=args.get('--datacenter'), nic_speed=args.get('--network'), tags=tags) table = formatting.Table([ 'id', 'datacenter', 'host', 'cores', 'memory', 'primary_ip', 'backend_ip', 'active_transaction', 'owner' ]) table.sortby = args.get('--sortby') or 'host' for server in servers: server = utils.NestedDict(server) user = None if 'billingItem' in server: if 'orderItem' in server['billingItem']: user = (server['billingItem']['orderItem']['order'] ['userRecord']['username']) table.add_row([ server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], server['processorPhysicalCoreAmount'], formatting.gb(server['memoryCapacity'] or 0), server['primaryIpAddress'] or formatting.blank(), server['primaryBackendIpAddress'] or formatting.blank(), formatting.active_txn(server), user or formatting.blank(), ]) return table
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, tag): """List hardware servers.""" manager = SoftLayer.HardwareManager(env.client) servers = manager.list_hardware( hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, tags=tag) table = formatting.Table([ 'id', 'datacenter', 'host', 'cores', 'memory', 'primary_ip', 'backend_ip', 'active_transaction', 'owner' ]) table.sortby = sortby for server in servers: server = utils.NestedDict(server) table.add_row([ server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], server['processorPhysicalCoreAmount'], formatting.gb(server['memoryCapacity'] or 0), server['primaryIpAddress'] or formatting.blank(), server['primaryBackendIpAddress'] or formatting.blank(), formatting.active_txn(server), utils.lookup( server, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(), ]) return table
def execute(self, args): manager = SoftLayer.HardwareManager(self.client) tags = None if args.get('--tags'): tags = [tag.strip() for tag in args.get('--tags').split(',')] servers = manager.list_hardware(hostname=args.get('--hostname'), domain=args.get('--domain'), cpus=args.get('--cpu'), memory=args.get('--memory'), datacenter=args.get('--datacenter'), nic_speed=args.get('--network'), tags=tags) table = formatting.Table([ 'id', 'datacenter', 'host', 'cores', 'memory', 'primary_ip', 'backend_ip', 'active_transaction', 'owner' ]) table.sortby = args.get('--sortby') or 'host' for server in servers: server = utils.NestedDict(server) table.add_row([ server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], server['processorPhysicalCoreAmount'], formatting.gb(server['memoryCapacity'] or 0), server['primaryIpAddress'] or formatting.blank(), server['primaryBackendIpAddress'] or formatting.blank(), formatting.active_txn(server), utils.lookup(server, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(), ]) return table
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, tag): """List hardware servers.""" manager = SoftLayer.HardwareManager(env.client) servers = manager.list_hardware(hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, tags=tag) table = formatting.Table([ 'id', 'datacenter', 'host', 'cores', 'memory', 'primary_ip', 'backend_ip', 'active_transaction', 'owner' ]) table.sortby = sortby for server in servers: server = utils.NestedDict(server) table.add_row([ server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], server['processorPhysicalCoreAmount'], formatting.gb(server['memoryCapacity'] or 0), server['primaryIpAddress'] or formatting.blank(), server['primaryBackendIpAddress'] or formatting.blank(), formatting.active_txn(server), utils.lookup(server, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(), ]) return table
def cli(env, identifier, passwords, price, components): """Get details for a hardware device.""" hardware = SoftLayer.HardwareManager(env.client) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) hard_drives = hardware.get_hard_drives(hardware_id) operating_system = utils.lookup(result, 'operatingSystem', 'softwareLicense', 'softwareDescription') or {} memory = formatting.gb(result.get('memoryCapacity', 0)) owner = None if utils.lookup(result, 'billingItem') != []: owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') table_hard_drives = formatting.Table(['Name', 'Capacity', 'Serial #']) for drives in hard_drives: name = drives['hardwareComponentModel']['manufacturer'] + " " + drives[ 'hardwareComponentModel']['name'] capacity = str( drives['hardwareComponentModel']['hardwareGenericComponentModel'] ['capacity']) + " " + str( drives['hardwareComponentModel'] ['hardwareGenericComponentModel']['units']) serial = drives['serialNumber'] table_hard_drives.add_row([name, capacity, serial]) table.add_row(['id', result['id']]) table.add_row(['guid', result['globalIdentifier'] or formatting.blank()]) table.add_row(['hostname', result['hostname']]) table.add_row(['domain', result['domain']]) table.add_row(['fqdn', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row( ['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', memory]) table.add_row(['drives', table_hard_drives]) table.add_row( ['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row([ 'private_ip', result['primaryBackendIpAddress'] or formatting.blank() ]) table.add_row([ 'ipmi_ip', result['networkManagementIpAddress'] or formatting.blank() ]) table.add_row(['os', operating_system.get('name') or formatting.blank()]) table.add_row( ['os_version', operating_system.get('version') or formatting.blank()]) table.add_row(['created', result['provisionDate'] or formatting.blank()]) table.add_row(['owner', owner or formatting.blank()]) last_transaction = "{} ({})".format( utils.lookup(result, 'lastTransaction', 'transactionGroup', 'name'), utils.clean_time(utils.lookup(result, 'lastTransaction', 'modifyDate'))) table.add_row(['last_transaction', last_transaction]) table.add_row( ['billing', 'Hourly' if result['hourlyBillingFlag'] else 'Monthly']) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row( [vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) bandwidth = hardware.get_bandwidth_allocation(hardware_id) bw_table = _bw_table(bandwidth) table.add_row(['Bandwidth', bw_table]) system_table = _system_table(result['activeComponents']) table.add_row(['System_data', system_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if price: total_price = utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount') or 0 price_table = formatting.Table( ['Item', 'CategoryCode', 'Recurring Price']) price_table.align['Item'] = 'l' price_table.add_row(['Total', '-', total_price]) for item in utils.lookup(result, 'billingItem', 'nextInvoiceChildren') or []: price_table.add_row([ item['description'], item['categoryCode'], item['nextInvoiceTotalRecurringAmount'] ]) table.add_row(['prices', price_table]) if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) pass_table = formatting.Table(['ipmi_username', 'password']) for item in result['remoteManagementAccounts']: pass_table.add_row([item['username'], item['password']]) table.add_row(['remote users', pass_table]) if components: components = hardware.get_components(identifier) components_table = formatting.Table( ['name', 'Firmware version', 'Firmware build date', 'Type']) components_table.align['date'] = 'l' component_ids = [] for hw_component in components: if hw_component['id'] not in component_ids: firmware = hw_component['hardwareComponentModel']['firmwares'][ 0] components_table.add_row([ utils.lookup(hw_component, 'hardwareComponentModel', 'longDescription'), utils.lookup(firmware, 'version'), utils.clean_time(utils.lookup(firmware, 'createDate')), utils.lookup(hw_component, 'hardwareComponentModel', 'hardwareGenericComponentModel', 'hardwareComponentType', 'keyName') ]) component_ids.append(hw_component['id']) table.add_row(['components', components_table]) table.add_row(['tags', formatting.tags(result['tagReferences'])]) env.fout(table)
def cli(env, identifier, passwords, price): """Get details for a hardware device.""" hardware = SoftLayer.HardwareManager(env.client) table = formatting.KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) table.add_row(['id', result['id']]) table.add_row(['guid', result['globalIdentifier']] or formatting.blank()) table.add_row(['hostname', result['hostname']]) table.add_row(['domain', result['domain']]) table.add_row(['fqdn', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row(['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', formatting.gb(result['memoryCapacity'])]) table.add_row(['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row(['private_ip', result['primaryBackendIpAddress'] or formatting.blank()]) table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or formatting.blank()]) table.add_row([ 'os', formatting.FormattedItem( result['operatingSystem']['softwareLicense'] ['softwareDescription']['referenceCode'] or formatting.blank(), result['operatingSystem']['softwareLicense'] ['softwareDescription']['name'] or formatting.blank() )]) table.add_row( ['created', result['provisionDate'] or formatting.blank()]) table.add_row(['owner', formatting.FormattedItem( utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank() )]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row([ vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if price: table.add_row(['price rate', utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount')]) if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) pass_table = formatting.Table(['ipmi_username', 'password']) for item in result['remoteManagementAccounts']: pass_table.add_row([item['username'], item['password']]) table.add_row(['remote users', pass_table]) tag_row = [] for tag in result['tagReferences']: tag_row.append(tag['tag']['name']) if tag_row: table.add_row(['tags', formatting.listing(tag_row, separator=',')]) # Test to see if this actually has a primary (public) ip address try: if not result['privateNetworkOnlyFlag']: ptr_domains = (env.client['Hardware_Server'] .getReverseDomainRecords(id=hardware_id)) for ptr_domain in ptr_domains: for ptr in ptr_domain['resourceRecords']: table.add_row(['ptr', ptr['data']]) except SoftLayer.SoftLayerAPIError: pass return table
def execute(self, args): hardware = SoftLayer.HardwareManager(self.client) table = formatting.KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' hardware_id = helpers.resolve_id( hardware.resolve_ids, args.get('<identifier>'), 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) table.add_row(['id', result['id']]) table.add_row(['hostname', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row(['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', formatting.gb(result['memoryCapacity'])]) table.add_row(['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row(['private_ip', result['primaryBackendIpAddress'] or formatting.blank()]) table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or formatting.blank()]) table.add_row([ 'os', formatting.FormattedItem( result['operatingSystem']['softwareLicense'] ['softwareDescription']['referenceCode'] or formatting.blank(), result['operatingSystem']['softwareLicense'] ['softwareDescription']['name'] or formatting.blank() )]) table.add_row(['created', result['provisionDate'] or formatting.blank()]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row([ vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if args.get('--price'): table.add_row(['price rate', result['billingItem']['recurringFee']]) if args.get('--passwords'): user_strs = [] for item in result['operatingSystem']['passwords']: user_strs.append( "%s %s" % (item['username'], item['password'])) table.add_row(['users', formatting.listing(user_strs)]) tag_row = [] for tag in result['tagReferences']: tag_row.append(tag['tag']['name']) if tag_row: table.add_row(['tags', formatting.listing(tag_row, separator=',')]) # Test to see if this actually has a primary (public) ip address if result['primaryIpAddress']: ptr_domains = (self.client['Hardware_Server'] .getReverseDomainRecords(id=hardware_id)) for ptr_domain in ptr_domains: for ptr in ptr_domain['resourceRecords']: table.add_row(['ptr', ptr['data']]) return table
def execute(self, args): hardware = SoftLayer.HardwareManager(self.client) table = formatting.KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, args.get('<identifier>'), 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) table.add_row(['id', result['id']]) table.add_row(['hostname', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row( ['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', formatting.gb(result['memoryCapacity'])]) table.add_row( ['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row([ 'private_ip', result['primaryBackendIpAddress'] or formatting.blank() ]) table.add_row([ 'ipmi_ip', result['networkManagementIpAddress'] or formatting.blank() ]) table.add_row([ 'os', formatting.FormattedItem( result['operatingSystem']['softwareLicense'] ['softwareDescription']['referenceCode'] or formatting.blank(), result['operatingSystem']['softwareLicense'] ['softwareDescription']['name'] or formatting.blank()) ]) table.add_row( ['created', result['provisionDate'] or formatting.blank()]) table.add_row([ 'owner', formatting.FormattedItem( utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank()) ]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row( [vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if args.get('--price'): table.add_row( ['price rate', result['billingItem']['recurringFee']]) if args.get('--passwords'): user_strs = [] for item in result['operatingSystem']['passwords']: user_strs.append("%s %s" % (item['username'], item['password'])) table.add_row(['users', formatting.listing(user_strs)]) tag_row = [] for tag in result['tagReferences']: tag_row.append(tag['tag']['name']) if tag_row: table.add_row(['tags', formatting.listing(tag_row, separator=',')]) # Test to see if this actually has a primary (public) ip address try: if not result['privateNetworkOnlyFlag']: ptr_domains = ( self.client['Hardware_Server'].getReverseDomainRecords( id=hardware_id)) for ptr_domain in ptr_domains: for ptr in ptr_domain['resourceRecords']: table.add_row(['ptr', ptr['data']]) except SoftLayer.SoftLayerAPIError: pass return table
def cli(env, identifier, passwords, price): """Get details for a hardware device.""" hardware = SoftLayer.HardwareManager(env.client) table = formatting.KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) table.add_row(['id', result['id']]) table.add_row(['guid', result['globalIdentifier'] or formatting.blank()]) table.add_row(['hostname', result['hostname']]) table.add_row(['domain', result['domain']]) table.add_row(['fqdn', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row( ['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', formatting.gb(result['memoryCapacity'])]) table.add_row( ['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row([ 'private_ip', result['primaryBackendIpAddress'] or formatting.blank() ]) table.add_row([ 'ipmi_ip', result['networkManagementIpAddress'] or formatting.blank() ]) table.add_row([ 'os', formatting.FormattedItem( result['operatingSystem']['softwareLicense']['softwareDescription'] ['referenceCode'] or formatting.blank(), result['operatingSystem'] ['softwareLicense']['softwareDescription']['name'] or formatting.blank()) ]) table.add_row(['created', result['provisionDate'] or formatting.blank()]) if utils.lookup(result, 'billingItem') != []: table.add_row([ 'owner', formatting.FormattedItem( utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(), ) ]) else: table.add_row(['owner', formatting.blank()]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row( [vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if price: table.add_row([ 'price rate', utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount') ]) if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) pass_table = formatting.Table(['ipmi_username', 'password']) for item in result['remoteManagementAccounts']: pass_table.add_row([item['username'], item['password']]) table.add_row(['remote users', pass_table]) tag_row = [] for tag_detail in result['tagReferences']: tag = utils.lookup(tag_detail, 'tag', 'name') if tag is not None: tag_row.append(tag) if tag_row: table.add_row(['tags', formatting.listing(tag_row, separator=',')]) # Test to see if this actually has a primary (public) ip address try: if not result['privateNetworkOnlyFlag']: ptr_domains = ( env.client['Hardware_Server'].getReverseDomainRecords( id=hardware_id)) for ptr_domain in ptr_domains: for ptr in ptr_domain['resourceRecords']: table.add_row(['ptr', ptr['data']]) except SoftLayer.SoftLayerAPIError: pass env.fout(table)
def cli(env, identifier, passwords, price): """Get details for a hardware device.""" hardware = SoftLayer.HardwareManager(env.client) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) operating_system = utils.lookup(result, 'operatingSystem', 'softwareLicense', 'softwareDescription') or {} memory = formatting.gb(result.get('memoryCapacity', 0)) owner = None if utils.lookup(result, 'billingItem') != []: owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') table.add_row(['id', result['id']]) table.add_row(['guid', result['globalIdentifier'] or formatting.blank()]) table.add_row(['hostname', result['hostname']]) table.add_row(['domain', result['domain']]) table.add_row(['fqdn', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row(['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', memory]) table.add_row(['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row(['private_ip', result['primaryBackendIpAddress'] or formatting.blank()]) table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or formatting.blank()]) table.add_row(['os', operating_system.get('name') or formatting.blank()]) table.add_row(['os_version', operating_system.get('version') or formatting.blank()]) table.add_row(['created', result['provisionDate'] or formatting.blank()]) table.add_row(['owner', owner or formatting.blank()]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row([vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if price: total_price = utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount') or 0 price_table = formatting.Table(['Item', 'Recurring Price']) price_table.add_row(['Total', total_price]) for item in utils.lookup(result, 'billingItem', 'children') or []: price_table.add_row([item['description'], item['nextInvoiceTotalRecurringAmount']]) table.add_row(['prices', price_table]) if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) pass_table = formatting.Table(['ipmi_username', 'password']) for item in result['remoteManagementAccounts']: pass_table.add_row([item['username'], item['password']]) table.add_row(['remote users', pass_table]) table.add_row(['tags', formatting.tags(result['tagReferences'])]) env.fout(table)
def cli(env, identifier, passwords, price): """Get details for a hardware device.""" hardware = SoftLayer.HardwareManager(env.client) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') result = hardware.get_hardware(hardware_id) result = utils.NestedDict(result) operating_system = utils.lookup(result, 'operatingSystem', 'softwareLicense', 'softwareDescription') or {} memory = formatting.gb(result.get('memoryCapacity', 0)) owner = None if utils.lookup(result, 'billingItem') != []: owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') table.add_row(['id', result['id']]) table.add_row(['guid', result['globalIdentifier'] or formatting.blank()]) table.add_row(['hostname', result['hostname']]) table.add_row(['domain', result['domain']]) table.add_row(['fqdn', result['fullyQualifiedDomainName']]) table.add_row(['status', result['hardwareStatus']['status']]) table.add_row( ['datacenter', result['datacenter']['name'] or formatting.blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', memory]) table.add_row( ['public_ip', result['primaryIpAddress'] or formatting.blank()]) table.add_row([ 'private_ip', result['primaryBackendIpAddress'] or formatting.blank() ]) table.add_row([ 'ipmi_ip', result['networkManagementIpAddress'] or formatting.blank() ]) table.add_row(['os', operating_system.get('name') or formatting.blank()]) table.add_row( ['os_version', operating_system.get('version') or formatting.blank()]) table.add_row(['created', result['provisionDate'] or formatting.blank()]) table.add_row(['owner', owner or formatting.blank()]) vlan_table = formatting.Table(['type', 'number', 'id']) for vlan in result['networkVlans']: vlan_table.add_row( [vlan['networkSpace'], vlan['vlanNumber'], vlan['id']]) table.add_row(['vlans', vlan_table]) if result.get('notes'): table.add_row(['notes', result['notes']]) if price: total_price = utils.lookup(result, 'billingItem', 'nextInvoiceTotalRecurringAmount') or 0 price_table = formatting.Table(['Item', 'Recurring Price']) price_table.add_row(['Total', total_price]) for item in utils.lookup(result, 'billingItem', 'children') or []: price_table.add_row( [item['description'], item['nextInvoiceTotalRecurringAmount']]) table.add_row(['prices', price_table]) if passwords: pass_table = formatting.Table(['username', 'password']) for item in result['operatingSystem']['passwords']: pass_table.add_row([item['username'], item['password']]) table.add_row(['users', pass_table]) pass_table = formatting.Table(['ipmi_username', 'password']) for item in result['remoteManagementAccounts']: pass_table.add_row([item['username'], item['password']]) table.add_row(['remote users', pass_table]) table.add_row(['tags', formatting.tags(result['tagReferences'])]) env.fout(table)