def execute(client, args): f = FirewallManager(client) fwvlans = f.get_firewalls() t = Table(['vlan', 'type', 'features']) dedicatedfws = filter(lambda x: x['dedicatedFirewallFlag'], fwvlans) for vlan in dedicatedfws: features = [] if vlan['highAvailabilityFirewallFlag']: features.append('HA') if features: feature_list = listing(features, separator=',') else: feature_list = blank() t.add_row([ vlan['vlanNumber'], 'dedicated', feature_list, ]) shared_vlan = filter(lambda x: not x['dedicatedFirewallFlag'], fwvlans) for vlan in shared_vlan: t.add_row([vlan['vlanNumber'], 'standard', blank()]) return t
def execute(self, args): iscsi_mgr = ISCSIManager(self.client) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' iscsi_id = resolve_id( iscsi_mgr.resolve_ids, args.get('<identifier>'), 'iSCSI') result = iscsi_mgr.get_iscsi(iscsi_id) result = NestedDict(result) table.add_row(['id', result['id']]) table.add_row(['serviceResourceName', result['serviceResourceName']]) table.add_row(['createDate', result['createDate']]) table.add_row(['nasType', result['nasType']]) table.add_row(['capacityGb', result['capacityGb']]) if result['snapshotCapacityGb']: table.add_row(['snapshotCapacityGb', result['snapshotCapacityGb']]) table.add_row(['mountableFlag', result['mountableFlag']]) table.add_row( ['serviceResourceBackendIpAddress', result['serviceResourceBackendIpAddress']]) table.add_row(['price', result['billingItem']['recurringFee']]) table.add_row(['BillingItemId', result['billingItem']['id']]) if result.get('notes'): table.add_row(['notes', result['notes']]) if args.get('--password'): pass_table = Table(['username', 'password']) pass_table.add_row([result['username'], result['password']]) table.add_row(['users', pass_table]) return table
def execute(client, args): account = client['Account'] neither = not any([args['--private'], args['--public']]) results = [] if args['--private'] or neither: account = client['Account'] mask = 'id,accountId,name,globalIdentifier,blockDevices,parentId' r = account.getPrivateBlockDeviceTemplateGroups(mask=mask) results.append(r) if args['--public'] or neither: vgbd = client['Virtual_Guest_Block_Device_Template_Group'] r = vgbd.getPublicImages() results.append(r) t = Table(['id', 'account', 'type', 'name', 'guid', ]) t.sortby = 'name' for result in results: images = filter(lambda x: x['parentId'] == '', result) for image in images: t.add_row([ image['id'], image.get('accountId', blank()), image.get('type', blank()), image['name'].strip(), image.get('globalIdentifier', blank()), ]) return t
def execute(client, args): mgr = NetworkManager(client) version = 4 if args.get('--v6'): version = 6 if not args.get('--test') and not args['--really']: if not confirm("This action will incur charges on your account." "Continue?"): raise CLIAbort('Cancelling order.') result = mgr.add_global_ip(version=version, test_order=args.get('--test')) if not result: return 'Unable to place order: No valid price IDs found.' t = Table(['Item', 'cost']) t.align['Item'] = 'r' t.align['cost'] = 'r' total = 0.0 for price in result['orderDetails']['prices']: total += float(price.get('recurringFee', 0.0)) rate = "%.2f" % float(price['recurringFee']) t.add_row([price['item']['description'], rate]) t.add_row(['Total monthly cost', "%.2f" % total]) output = SequentialOutput() output.append(t) output.append(FormattedItem( '', ' -- ! Prices reflected here are retail and do not ' 'take account level discounts and are not guarenteed.') ) return t
def execute(client, args): mgr = NetworkManager(client) t = Table([ 'id', 'ip', 'assigned', 'target' ]) t.sortby = args.get('--sortby') or 'id' version = 0 if args.get('--v4'): version = 4 elif args.get('--v6'): version = 6 ips = mgr.list_global_ips(version=version) for ip in ips: assigned = 'No' target = 'None' if ip.get('destinationIpAddress'): dest = ip['destinationIpAddress'] assigned = 'Yes' target = dest['ipAddress'] if dest.get('virtualGuest'): vg = dest['virtualGuest'] target += ' (' + vg['fullyQualifiedDomainName'] + ')' elif ip['destinationIpAddress'].get('hardware'): target += ' (' + \ dest['hardware']['fullyQualifiedDomainName'] + \ ')' t.add_row([ip['id'], ip['ipAddress']['ipAddress'], assigned, target]) return t
def execute(self, args): ticket_mgr = TicketManager(self.client) tickets = ticket_mgr.list_tickets( open_status=not args.get('--closed'), closed_status=args.get('--closed')) table = Table(['id', 'assigned user', 'title', 'creation date', 'last edit date']) for ticket in tickets: if ticket['assignedUser']: table.add_row([ ticket['id'], "%s %s" % (ticket['assignedUser']['firstName'], ticket['assignedUser']['lastName']), wrap_string(ticket['title']), ticket['createDate'], ticket['lastEditDate'] ]) else: table.add_row([ ticket['id'], 'N/A', wrap_string(ticket['title']), ticket['createDate'], ticket['lastEditDate'] ]) return table
def list_zone(client, zone, args): manager = DNSManager(client) t = Table([ "record", "type", "ttl", "value", ]) t.align['ttl'] = 'l' t.align['record'] = 'r' t.align['value'] = 'l' zone_id = resolve_id(manager.resolve_ids, args['<zone>'], name='zone') try: records = manager.get_records( zone_id, type=args.get('--type'), host=args.get('--record'), ttl=args.get('--ttl'), data=args.get('--data'), ) except DNSZoneNotFound: raise CLIAbort("No zone found matching: %s" % args['<zone>']) for rr in records: t.add_row([ rr['host'], rr['type'].upper(), rr['ttl'], rr['data'] ]) return t
def execute(self, args): mgr = NetworkManager(self.client) t = Table([ 'id', 'identifier', 'type', 'datacenter', 'vlan id', 'IPs', 'hardware', 'ccis', ]) t.sortby = args.get('--sortby') or 'id' version = 0 if args.get('--v4'): version = 4 elif args.get('--v6'): version = 6 subnets = mgr.list_subnets( datacenter=args.get('--datacenter'), version=version, identifier=args.get('--identifier'), subnet_type=args.get('--type'), ) for subnet in subnets: t.add_row([ subnet['id'], subnet['networkIdentifier'] + '/' + str(subnet['cidr']), subnet.get('subnetType', '-'), subnet['datacenter']['name'], subnet['networkVlanId'], subnet['ipAddressCount'], len(subnet['hardware']), len(subnet['virtualGuests']), ]) return t
def execute(client, args): account = client["Account"] neither = not any([args["--private"], args["--public"]]) result = [] if args["--private"] or neither: account = client["Account"] private = "privateBlockDeviceTemplateGroups" mask = private + "[id,accountId,name,globalIdentifier,blockDevices,parentId]" result += account.getObject(mask=mask)[private] if args["--public"] or neither: vgbd = client["Virtual_Guest_Block_Device_Template_Group"] result += vgbd.getPublicImages() t = Table(["id", "account", "type", "name", "guid"]) t.sortby = "name" images = filter(lambda x: x["parentId"] == "", result) for image in images: t.add_row( [ image["id"], image.get("accountId", "-"), image.get("type", "-"), image["name"].strip(), image.get("globalIdentifier", "-"), ] ) return t
def execute(client, args): account = client['Account'] iscsi = account.getIscsiNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') iscsi = [NestedDict(n) for n in iscsi] t = Table([ 'id', 'datacenter', 'size', 'username', 'password', 'server' ]) for n in iscsi: t.add_row([ n['id'], n['serviceResource']['datacenter'].get('name', blank()), FormattedItem( n.get('capacityGb', blank()), "%dGB" % n.get('capacityGb', 0)), n.get('username', blank()), n.get('password', blank()), n.get('serviceResourceBackendIpAddress', blank())]) return t
def execute(self, args): image_mgr = ImageManager(self.client) neither = not any([args['--private'], args['--public']]) mask = 'id,accountId,name,globalIdentifier,blockDevices,parentId' images = [] if args['--private'] or neither: for image in image_mgr.list_private_images(mask=mask): image['visibility'] = 'private' images.append(image) if args['--public'] or neither: for image in image_mgr.list_public_images(mask=mask): image['visibility'] = 'public' images.append(image) t = Table(['id', 'account', 'visibility', 'name', 'global_identifier']) images = filter(lambda x: x['parentId'] == '', images) for image in images: t.add_row([ image['id'], image.get('accountId', blank()), image['visibility'], image['name'].strip(), image.get('globalIdentifier', blank()), ]) return t
def execute(self, args): table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' show_all = True for opt_name in self.options: if args.get("--" + opt_name): show_all = False break mgr = HardwareManager(self.client) bmi_options = mgr.get_bare_metal_create_options() if args['--all']: show_all = True if args['--datacenter'] or show_all: results = self.get_create_options(bmi_options, 'datacenter')[0] table.add_row([results[0], listing(sorted(results[1]))]) if args['--cpu'] or args['--memory'] or show_all: results = self.get_create_options(bmi_options, 'cpu') 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(bmi_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(bmi_options, 'disk')[0] table.add_row([results[0], listing( [item[0] for item in sorted(results[1])])]) if args['--nic'] or show_all: results = self.get_create_options(bmi_options, 'nic') for result in results: table.add_row([result[0], listing( [item[0] for item in sorted(result[1],)])]) return table
def execute(self, args): mgr = NetworkManager(self.client) version = 4 if args.get('--v6'): version = 6 if not args.get('--test') and not args['--really']: if not confirm("This action will incur charges on your account." "Continue?"): raise CLIAbort('Cancelling order.') result = mgr.add_global_ip(version=version, test_order=args.get('--test')) if not result: return 'Unable to place order: No valid price IDs found.' table = Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' total = 0.0 for price in result['orderDetails']['prices']: total += float(price.get('recurringFee', 0.0)) rate = "%.2f" % float(price['recurringFee']) table.add_row([price['item']['description'], rate]) table.add_row(['Total monthly cost', "%.2f" % total]) return table
def execute(self, args): account = self.client['Account'] iscsi_list = account.getIscsiNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') iscsi_list = [NestedDict(iscsi) for iscsi in iscsi_list] table = Table([ 'id', 'datacenter', 'size', 'username', 'password', 'server' ]) for iscsi in iscsi_list: table.add_row([ iscsi['id'], iscsi['serviceResource']['datacenter'].get('name', blank()), FormattedItem( iscsi.get('capacityGb', blank()), "%dGB" % iscsi.get('capacityGb', 0)), iscsi.get('username', blank()), iscsi.get('password', blank()), iscsi.get('serviceResourceBackendIpAddress', blank())]) return table
def execute(self, args): mgr = NetworkManager(self.client) table = Table([ 'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'ccis', 'networking', 'firewall' ]) table.sortby = args.get('--sortby') or 'id' vlans = mgr.list_vlans( datacenter=args.get('--datacenter'), vlan_number=args.get('--number'), name=args.get('--name'), ) for vlan in vlans: table.add_row([ vlan['id'], vlan['vlanNumber'], vlan['primaryRouter']['datacenter']['name'], vlan.get('name') or blank(), vlan['totalPrimaryIpAddressCount'], len(vlan['hardware']), len(vlan['virtualGuests']), len(vlan['networkComponents']), 'Yes' if vlan['firewallInterfaces'] else 'No', ]) return table
def execute(self, args): mgr = FirewallManager(self.client) fwvlans = mgr.get_firewalls() table = Table(['vlan', 'type', 'features']) dedicatedfws = [vlan['dedicatedFirewallFlag'] for vlan in fwvlans] for vlan in dedicatedfws: features = [] if vlan['highAvailabilityFirewallFlag']: features.append('HA') if features: feature_list = listing(features, separator=',') else: feature_list = blank() table.add_row([ vlan['vlanNumber'], 'dedicated', feature_list, ]) shared_vlan = [vlan['dedicatedFirewallFlag'] for vlan in fwvlans] for vlan in shared_vlan: table.add_row([vlan['vlanNumber'], 'standard', blank()]) return table
def execute(self, args): mgr = NetworkManager(self.client) vlan = mgr.get_vlan(args.get('<identifier>')) t = KeyValueTable(['Name', 'Value']) t.align['Name'] = 'r' t.align['Value'] = 'l' t.add_row(['id', vlan['id']]) t.add_row(['number', vlan['vlanNumber']]) t.add_row(['datacenter', vlan['primaryRouter']['datacenter']['longName']]) t.add_row(['primary router', vlan['primaryRouter']['fullyQualifiedDomainName']]) t.add_row(['firewall', 'Yes' if vlan['firewallInterfaces'] else 'No']) subnets = [] for subnet in vlan['subnets']: subnet_table = KeyValueTable(['Name', 'Value']) subnet_table.align['Name'] = 'r' subnet_table.align['Value'] = 'l' subnet_table.add_row(['id', subnet['id']]) subnet_table.add_row(['identifier', subnet['networkIdentifier']]) subnet_table.add_row(['netmask', subnet['netmask']]) subnet_table.add_row(['gateway', subnet.get('gateway', '-')]) subnet_table.add_row(['type', subnet['subnetType']]) subnet_table.add_row(['usable ips', subnet['usableIpAddressCount']]) subnets.append(subnet_table) t.add_row(['subnets', subnets]) if not args.get('--no-cci'): if vlan['virtualGuests']: cci_table = KeyValueTable(['Hostname', 'Domain', 'IP']) cci_table.align['Hostname'] = 'r' cci_table.align['IP'] = 'l' for cci in vlan['virtualGuests']: cci_table.add_row([cci['hostname'], cci['domain'], cci.get('primaryIpAddress')]) t.add_row(['ccis', cci_table]) else: t.add_row(['cci', 'none']) if not args.get('--no-hardware'): if vlan['hardware']: hw_table = Table(['Hostname', 'Domain', 'IP']) hw_table.align['Hostname'] = 'r' hw_table.align['IP'] = 'l' for hw in vlan['hardware']: hw_table.add_row([hw['hostname'], hw['domain'], hw.get('primaryIpAddress')]) t.add_row(['hardware', hw_table]) else: t.add_row(['hardware', 'none']) return t
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 execute(self, args): manager = MessagingManager(self.client) mq_client = manager.get_connection(args['<account_id>']) topics = mq_client.get_topics()['items'] table = Table(['name']) for topic in topics: table.add_row([topic['name']]) return table
def execute(self, args): mgr = SshKeyManager(self.client) keys = mgr.list_keys() t = Table(["id", "label", "fingerprint", "notes"]) for key in keys: t.add_row([key["id"], key["label"], key["fingerprint"], key.get("notes", "-")]) return t
def execute(self, args): ticket_mgr = TicketManager(self.client) table = Table(['id', 'subject']) for subject in ticket_mgr.list_subjects(): table.add_row([ subject['id'], subject['name'] ]) return table
def message_table(message): t = Table(['property', 'value']) t.align['property'] = 'r' t.align['value'] = 'l' t.add_row(['id', message['id']]) t.add_row(['initial_entry_time', message['initial_entry_time']]) t.add_row(['visibility_delay', message['visibility_delay']]) t.add_row(['visibility_interval', message['visibility_interval']]) t.add_row(['fields', message['fields']]) return [t, message['body']]
def execute(self, args): mgr = SshKeyManager(self.client) keys = mgr.list_keys() t = Table(['id', 'label', 'fingerprint', 'notes']) for key in keys: t.add_row([key['id'], key['label'], key['fingerprint'], key.get('notes', '-')]) return t
def message_table(message): """ Returns a table with details about a message """ table = Table(['property', 'value']) table.align['property'] = 'r' table.align['value'] = 'l' table.add_row(['id', message['id']]) table.add_row(['initial_entry_time', message['initial_entry_time']]) table.add_row(['visibility_delay', message['visibility_delay']]) table.add_row(['visibility_interval', message['visibility_interval']]) table.add_row(['fields', message['fields']]) return [table, message['body']]
def execute(self, args): manager = CDNManager(self.client) origins = manager.get_origins(args.get('<account>')) table = Table(['id', 'media_type', 'cname', 'origin_url']) for origin in origins: table.add_row([origin['id'], origin['mediaType'], origin.get('cname', blank()), origin['originUrl']]) return table
def execute(client, args): manager = DNSManager(client) results = manager.search_record( args['<domain>'], args['<record>']) t = Table(['id', 'type', 'ttl', 'data']) t.align['ttl'] = 'c' for r in results: t.add_row([r['id'], r['type'], r['ttl'], r['data']]) return t
def execute(self, args): t = KeyValueTable(["Name", "Value"]) t.align["Name"] = "r" t.align["Value"] = "l" show_all = True for opt_name in self.options: if args.get("--" + opt_name): show_all = False break mgr = HardwareManager(self.client) bmi_options = mgr.get_bare_metal_create_options() if args["--all"]: show_all = True if args["--datacenter"] or show_all: results = self.get_create_options(bmi_options, "datacenter")[0] t.add_row([results[0], listing(sorted(results[1]))]) if args["--cpu"] or args["--memory"] or show_all: results = self.get_create_options(bmi_options, "cpu") 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]))])] ) t.add_row(["memory/cpu", memory_cpu_table]) if args["--os"] or show_all: results = self.get_create_options(bmi_options, "os") for result in results: t.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(bmi_options, "disk")[0] t.add_row([results[0], listing([item[0] for item in sorted(results[1])])]) if args["--nic"] or show_all: results = self.get_create_options(bmi_options, "nic") for result in results: t.add_row([result[0], listing([item[0] for item in sorted(result[1])])]) return t
def execute(self, args): mgr = NetworkManager(self.client) subnet_id = resolve_id(mgr.resolve_subnet_ids, args.get('<identifier>'), name='subnet') subnet = mgr.get_subnet(subnet_id) table = KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' table.add_row(['id', subnet['id']]) table.add_row(['identifier', '%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr']))]) table.add_row(['subnet type', subnet['subnetType']]) table.add_row(['gateway', subnet.get('gateway', blank())]) table.add_row(['broadcast', subnet.get('broadcastAddress', blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row(['usable ips', subnet.get('usableIpAddressCount', blank())]) if not args.get('--no-cci'): if subnet['virtualGuests']: cci_table = Table(['Hostname', 'Domain', 'IP']) cci_table.align['Hostname'] = 'r' cci_table.align['IP'] = 'l' for cci in subnet['virtualGuests']: cci_table.add_row([cci['hostname'], cci['domain'], cci.get('primaryIpAddress')]) table.add_row(['ccis', cci_table]) else: table.add_row(['cci', 'none']) if not args.get('--no-hardware'): if subnet['hardware']: hw_table = Table(['Hostname', 'Domain', 'IP']) hw_table.align['Hostname'] = 'r' hw_table.align['IP'] = 'l' for hardware in subnet['hardware']: hw_table.add_row([hardware['hostname'], hardware['domain'], hardware.get('primaryIpAddress')]) table.add_row(['hardware', hw_table]) else: table.add_row(['hardware', 'none']) return table
def execute(self, args): manager = MessagingManager(self.client) regions = manager.get_endpoints() table = Table([ 'name', 'public', 'private' ]) for region, endpoints in regions.items(): table.add_row([ region, endpoints.get('public') or blank(), endpoints.get('private') or blank(), ]) return table