def topic_table(topic): t = Table(['property', 'value']) t.align['property'] = 'r' t.align['value'] = 'l' t.add_row(['name', topic['name']]) t.add_row(['tags', listing(topic['tags'] or [])]) return t
def topic_table(topic): """ Returns a table with details about a topic """ table = Table(['property', 'value']) table.align['property'] = 'r' table.align['value'] = 'l' table.add_row(['name', topic['name']]) table.add_row(['tags', listing(topic['tags'] or [])]) return table
def queue_table(queue): t = Table(['property', 'value']) t.align['property'] = 'r' t.align['value'] = 'l' t.add_row(['name', queue['name']]) t.add_row(['message_count', queue['message_count']]) t.add_row(['visible_message_count', queue['visible_message_count']]) t.add_row(['tags', listing(queue['tags'] or [])]) t.add_row(['expiration', queue['expiration']]) t.add_row(['visibility_interval', queue['visibility_interval']]) return t
def queue_table(queue): """ Returns a table with details about a queue """ table = Table(['property', 'value']) table.align['property'] = 'r' table.align['value'] = 'l' table.add_row(['name', queue['name']]) table.add_row(['message_count', queue['message_count']]) table.add_row(['visible_message_count', queue['visible_message_count']]) table.add_row(['tags', listing(queue['tags'] or [])]) table.add_row(['expiration', queue['expiration']]) table.add_row(['visibility_interval', queue['visibility_interval']]) return table
def format_output(data, fmt='table'): if isinstance(data, basestring): return data if isinstance(data, Table): if fmt == 'table': return str(format_prettytable(data)) elif fmt == 'raw': return str(format_no_tty(data)) if fmt != 'raw' and isinstance(data, FormattedItem): return str(data.formatted) if isinstance(data, SequentialOutput): output = [format_output(d, fmt=fmt) for d in data] if not data.blanks: output = [x for x in output if len(x)] return format_output(output, fmt=fmt) if isinstance(data, list) or isinstance(data, tuple): output = [format_output(d, fmt=fmt) for d in data] return format_output(listing(output, separator=os.linesep)) return str(data)
def execute(self, args): mgr = HardwareManager(self.client) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' chassis_id = args.get('<chassis_id>') ds_options = mgr.get_dedicated_server_create_options(chassis_id) show_all = True for opt_name in self.options: if args.get("--" + opt_name): show_all = False break if args['--all']: show_all = True if args['--datacenter'] or show_all: results = self.get_create_options(ds_options, 'datacenter')[0] table.add_row([results[0], listing(sorted(results[1]))]) if args['--cpu'] or show_all: results = self.get_create_options(ds_options, 'cpu') cpu_table = Table(['id', 'description']) for result in sorted(results): cpu_table.add_row([result[1], result[0]]) table.add_row(['cpu', cpu_table]) if args['--memory'] or show_all: results = self.get_create_options(ds_options, 'memory')[0] table.add_row([results[0], listing( item[0] for item in sorted(results[1]))]) if args['--os'] or show_all: results = self.get_create_options(ds_options, 'os') for result in results: table.add_row([ result[0], listing( [item[0] for item in sorted(result[1])], separator=linesep )]) if args['--disk'] or show_all: results = self.get_create_options(ds_options, 'disk')[0] table.add_row([ results[0], listing( [item[0] for item in sorted(results[1])], separator=linesep )]) if args['--nic'] or show_all: results = self.get_create_options(ds_options, 'nic') for result in results: table.add_row([result[0], listing( item[0] for item in sorted(result[1],))]) if args['--controller'] or show_all: results = self.get_create_options(ds_options, 'disk_controller')[0] table.add_row([results[0], listing( item[0] for item in sorted(results[1],))]) return table
def execute(self, args): hardware = HardwareManager(self.client) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' hardware_id = resolve_id( hardware.resolve_ids, args.get('<identifier>'), 'hardware') result = hardware.get_hardware(hardware_id) result = 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 blank()]) table.add_row(['cores', result['processorPhysicalCoreAmount']]) table.add_row(['memory', gb(result['memoryCapacity'])]) table.add_row(['public_ip', result['primaryIpAddress'] or blank()]) table.add_row( ['private_ip', result['primaryBackendIpAddress'] or blank()]) table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or blank()]) table.add_row([ 'os', FormattedItem( result['operatingSystem']['softwareLicense'] ['softwareDescription']['referenceCode'] or blank(), result['operatingSystem']['softwareLicense'] ['softwareDescription']['name'] or blank() )]) table.add_row(['created', result['provisionDate'] or blank()]) vlan_table = 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', listing(user_strs)]) tag_row = [] for tag in result['tagReferences']: tag_row.append(tag['tag']['name']) if tag_row: table.add_row(['tags', listing(tag_row, separator=',')]) 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']]) return table
def execute(self, args): mgr = HardwareManager(self.client) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' chassis_id = args.get('<chassis_id>') found = False for chassis in mgr.get_available_dedicated_server_packages(): if chassis_id == str(chassis[0]): found = True break if not found: raise CLIAbort('Invalid chassis specified.') ds_options = mgr.get_dedicated_server_create_options(chassis_id) show_all = True for opt_name in self.options: if args.get("--" + opt_name): show_all = False break if args['--all']: show_all = True # Determine if this is a "Bare Metal Instance" or regular server bmc = False if chassis_id == str(mgr.get_bare_metal_package_id()): bmc = True if args['--datacenter'] or show_all: results = self.get_create_options(ds_options, 'datacenter')[0] table.add_row([results[0], listing(sorted(results[1]))]) if (args['--cpu'] or show_all) and not bmc: results = self.get_create_options(ds_options, 'cpu') cpu_table = Table(['ID', 'Description']) cpu_table.align['ID'] = 'r' cpu_table.align['Description'] = 'l' for result in sorted(results, key=lambda x: x[1]): cpu_table.add_row([result[1], result[0]]) table.add_row(['cpu', cpu_table]) if (args['--memory'] or show_all) and not bmc: results = self.get_create_options(ds_options, 'memory')[0] table.add_row([results[0], listing( item[0] for item in sorted(results[1]))]) if bmc and (show_all or args['--memory'] or args['--cpu']): results = self.get_create_options(ds_options, 'server_core') memory_cpu_table = Table(['memory', 'cpu']) for result in results: memory_cpu_table.add_row([ result[0], listing( [item[0] for item in sorted( result[1], key=lambda x: int(x[0]) )])]) table.add_row(['memory/cpu', memory_cpu_table]) if args['--os'] or show_all: results = self.get_create_options(ds_options, 'os') for result in results: table.add_row([ result[0], listing( [item[0] for item in sorted(result[1])], separator=linesep )]) if args['--disk'] or show_all: results = self.get_create_options(ds_options, 'disk')[0] table.add_row([ results[0], listing( [item[0] for item in sorted(results[1])], separator=linesep )]) if args['--nic'] or show_all: results = self.get_create_options(ds_options, 'nic') for result in results: table.add_row([result[0], listing( item[0] for item in sorted(result[1],))]) if (args['--controller'] or show_all) and not bmc: results = self.get_create_options(ds_options, 'disk_controller')[0] table.add_row([results[0], listing( item[0] for item in sorted(results[1],))]) return table