def cli(env): """List iSCSI targets.""" iscsi_mgr = SoftLayer.ISCSIManager(env.client) iscsi_list = iscsi_mgr.list_iscsi() iscsi_list = [utils.NestedDict(n) for n in iscsi_list] table = formatting.Table([ 'id', 'datacenter', 'size', 'username', 'password', 'server' ]) for iscsi in iscsi_list: table.add_row([ iscsi['id'], utils.lookup(iscsi, 'serviceResource', 'datacenter', 'name') or formatting.blank(), formatting.FormattedItem(iscsi.get('capacityGb', formatting.blank()), "%dGB" % iscsi.get('capacityGb', 0)), iscsi.get('username', formatting.blank()), iscsi.get('password', formatting.blank()), iscsi.get('serviceResourceBackendIpAddress', formatting.blank())]) env.fout(table)
def cli(env, identifier, no_vs, no_hardware): """Get subnet details.""" mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.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( ['network space', utils.lookup(subnet, 'networkVlan', 'networkSpace')]) table.add_row(['gateway', subnet.get('gateway', formatting.blank())]) table.add_row( ['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row( ['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table( ['hostname', 'domain', 'public_ip', 'private_ip']) for vsi in subnet['virtualGuests']: vs_table.add_row([ vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress'), vsi.get('primaryBackendIpAddress') ]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if subnet['hardware']: hw_table = formatting.Table( ['hostname', 'domain', 'public_ip', 'private_ip']) for hardware in subnet['hardware']: hw_table.add_row([ hardware['hostname'], hardware['domain'], hardware.get('primaryIpAddress'), hardware.get('primaryBackendIpAddress') ]) table.add_row(['hardware', hw_table]) else: table.add_row(['hardware', 'none']) env.fout(table)
def cli(env): """List NAS accounts.""" account = env.client['Account'] nas_accounts = account.getNasNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') table = formatting.Table( ['id', 'datacenter', 'size', 'username', 'password', 'server']) for nas_account in nas_accounts: table.add_row([ nas_account['id'], utils.lookup(nas_account, 'serviceResource', 'datacenter', 'name') or formatting.blank(), formatting.FormattedItem( nas_account.get('capacityGb', formatting.blank()), "%dGB" % nas_account.get('capacityGb', 0)), nas_account.get('username', formatting.blank()), nas_account.get('password', formatting.blank()), nas_account.get('serviceResourceBackendIpAddress', formatting.blank()) ]) return table
def cli(env): """List NAS accounts.""" account = env.client['Account'] nas_accounts = account.getNasNetworkStorage( mask='eventCount,serviceResource[datacenter.name]') table = formatting.Table(['id', 'datacenter', 'size', 'username', 'password', 'server']) for nas_account in nas_accounts: table.add_row([ nas_account['id'], utils.lookup(nas_account, 'serviceResource', 'datacenter', 'name') or formatting.blank(), formatting.FormattedItem( nas_account.get('capacityGb', formatting.blank()), "%dGB" % nas_account.get('capacityGb', 0)), nas_account.get('username', formatting.blank()), nas_account.get('password', formatting.blank()), nas_account.get('serviceResourceBackendIpAddress', 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", "hostname", "primary_ip", "backend_ip", "datacenter", "action"]) table.sortby = sortby or "hostname" for server in servers: table.add_row( [ utils.lookup(server, "id"), utils.lookup(server, "hostname") or formatting.blank(), utils.lookup(server, "primaryIpAddress") or formatting.blank(), utils.lookup(server, "primaryBackendIpAddress") or formatting.blank(), utils.lookup(server, "datacenter", "name") or formatting.blank(), formatting.active_txn(server), ] ) 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', 'hostname', 'primary_ip', 'backend_ip', 'datacenter', 'action', ]) table.sortby = sortby or 'hostname' for server in servers: table.add_row([ utils.lookup(server, 'id'), utils.lookup(server, 'hostname') or formatting.blank(), utils.lookup(server, 'primaryIpAddress') or formatting.blank(), utils.lookup(server, 'primaryBackendIpAddress') or formatting.blank(), utils.lookup(server, 'datacenter', 'name') or formatting.blank(), formatting.active_txn(server), ]) return table
def execute(self, args): iscsi_mgr = SoftLayer.ISCSIManager(self.client) iscsi_list = iscsi_mgr.list_iscsi() iscsi_list = [utils.NestedDict(n) for n in iscsi_list] table = formatting.Table([ 'id', 'datacenter', 'size', 'username', 'password', 'server' ]) for iscsi in iscsi_list: table.add_row([ iscsi['id'], iscsi['serviceResource']['datacenter'].get('name', formatting.blank()), formatting.FormattedItem( iscsi.get('capacityGb', formatting.blank()), "%dGB" % iscsi.get('capacityGb', 0)), iscsi.get('username', formatting.blank()), iscsi.get('password', formatting.blank()), iscsi.get('serviceResourceBackendIpAddress', formatting.blank())]) return table
def execute(self, args): image_mgr = SoftLayer.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) table = formatting.Table( ['id', 'account', 'visibility', 'name', 'global_identifier']) images = [image for image in images if image['parentId'] == ''] for image in images: table.add_row([ image['id'], image.get('accountId', formatting.blank()), image['visibility'], image['name'].strip(), image.get('globalIdentifier', formatting.blank()), ]) return table
def cli(env): """List iSCSI targets.""" iscsi_mgr = SoftLayer.ISCSIManager(env.client) iscsi_list = iscsi_mgr.list_iscsi() iscsi_list = [utils.NestedDict(n) for n in iscsi_list] table = formatting.Table([ 'id', 'datacenter', 'size', 'username', 'password', 'server' ]) for iscsi in iscsi_list: table.add_row([ iscsi['id'], iscsi['serviceResource']['datacenter'].get('name', formatting.blank()), formatting.FormattedItem(iscsi.get('capacityGb', formatting.blank()), "%dGB" % iscsi.get('capacityGb', 0)), iscsi.get('username', formatting.blank()), iscsi.get('password', formatting.blank()), iscsi.get('serviceResourceBackendIpAddress', formatting.blank())]) env.fout(table)
def cli(env, public): """List images.""" image_mgr = SoftLayer.ImageManager(env.client) images = [] if public in [False, None]: for image in image_mgr.list_private_images(mask=image_mod.MASK): images.append(image) if public in [True, None]: for image in image_mgr.list_public_images(mask=image_mod.MASK): images.append(image) table = formatting.Table(['guid', 'name', 'type', 'visibility', 'account']) images = [image for image in images if image['parentId'] == ''] for image in images: visibility = (image_mod.PUBLIC_TYPE if image['publicFlag'] else image_mod.PRIVATE_TYPE) table.add_row([ image.get('globalIdentifier', formatting.blank()), formatting.FormattedItem(image['name'], click.wrap_text(image['name'], width=50)), formatting.FormattedItem( utils.lookup(image, 'imageType', 'keyName'), utils.lookup(image, 'imageType', 'name')), visibility, image.get('accountId', formatting.blank()), ]) env.fout(table)
def execute(self, args): image_mgr = SoftLayer.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) table = formatting.Table(['id', 'account', 'visibility', 'name', 'global_identifier']) images = [image for image in images if image['parentId'] == ''] for image in images: table.add_row([ image['id'], image.get('accountId', formatting.blank()), image['visibility'], image['name'].strip(), image.get('globalIdentifier', formatting.blank()), ]) return table
def cli(env, volume_id): """Lists snapshot schedules for a given volume""" file_manager = SoftLayer.FileStorageManager(env.client) snapshot_schedules = file_manager.list_volume_schedules(volume_id) table = formatting.Table(['id', 'active', 'type', 'replication', 'date_created', 'minute', 'hour', 'day', 'week', 'day_of_week', 'date_of_month', 'month_of_year', 'maximum_snapshots']) for schedule in snapshot_schedules: if 'REPLICATION' in schedule['type']['keyname']: replication = '*' else: replication = formatting.blank() file_schedule_type = schedule['type']['keyname'].replace('REPLICATION_', '') file_schedule_type = file_schedule_type.replace('SNAPSHOT_', '') property_list = ['MINUTE', 'HOUR', 'DAY', 'WEEK', 'DAY_OF_WEEK', 'DAY_OF_MONTH', 'MONTH_OF_YEAR', 'SNAPSHOT_LIMIT'] schedule_properties = [] for prop_key in property_list: item = formatting.blank() for schedule_property in schedule.get('properties', []): if schedule_property['type']['keyname'] == prop_key: if schedule_property['value'] == '-1': item = '*' else: item = schedule_property['value'] break schedule_properties.append(item) table_row = [ schedule['id'], '*' if schedule.get('active', '') else '', file_schedule_type, replication, schedule.get('createDate', '') ] table_row.extend(schedule_properties) table.add_row(table_row) env.fout(table)
def cli(env, volume_id): """Lists snapshot schedules for a given volume""" block_manager = SoftLayer.BlockStorageManager(env.client) snapshot_schedules = block_manager.list_volume_schedules(volume_id) table = formatting.Table(['id', 'active', 'type', 'replication', 'date_created', 'minute', 'hour', 'day', 'week', 'day_of_week', 'date_of_month', 'month_of_year', 'maximum_snapshots']) for schedule in snapshot_schedules: if 'REPLICATION' in schedule['type']['keyname']: replication = '*' else: replication = formatting.blank() block_schedule_type = schedule['type']['keyname'].replace('REPLICATION_', '') block_schedule_type = block_schedule_type.replace('SNAPSHOT_', '') property_list = ['MINUTE', 'HOUR', 'DAY', 'WEEK', 'DAY_OF_WEEK', 'DAY_OF_MONTH', 'MONTH_OF_YEAR', 'SNAPSHOT_LIMIT'] schedule_properties = [] for prop_key in property_list: item = formatting.blank() for schedule_property in schedule.get('properties', []): if schedule_property['type']['keyname'] == prop_key: if schedule_property['value'] == '-1': item = '*' else: item = schedule_property['value'] break schedule_properties.append(item) table_row = [ schedule['id'], '*' if schedule.get('active', '') else '', block_schedule_type, replication, schedule.get('createDate', '')] table_row.extend(schedule_properties) table.add_row(table_row) env.fout(table)
def cli(env, identifier): """Get details for an image.""" image_mgr = SoftLayer.ImageManager(env.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK) disk_space = 0 datacenters = [] for child in image.get('children'): disk_space = int(child.get('blockDevicesDiskSpaceTotal', 0)) if child.get('datacenter'): datacenters.append(utils.lookup(child, 'datacenter', 'name')) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', image['id']]) table.add_row([ 'global_identifier', image.get('globalIdentifier', formatting.blank()) ]) table.add_row(['name', image['name'].strip()]) table.add_row([ 'status', formatting.FormattedItem( utils.lookup(image, 'status', 'keyname'), utils.lookup(image, 'status', 'name'), ) ]) table.add_row([ 'active_transaction', formatting.transaction_status(image.get('transaction')), ]) table.add_row(['account', image.get('accountId', formatting.blank())]) table.add_row([ 'visibility', image_mod.PUBLIC_TYPE if image['publicFlag'] else image_mod.PRIVATE_TYPE ]) table.add_row([ 'type', formatting.FormattedItem( utils.lookup(image, 'imageType', 'keyName'), utils.lookup(image, 'imageType', 'name'), ) ]) table.add_row(['flex', image.get('flexImageFlag')]) table.add_row(['note', image.get('note')]) table.add_row(['created', image.get('createDate')]) table.add_row(['disk_space', formatting.b_to_gb(disk_space)]) table.add_row([ 'datacenters', formatting.listing(sorted(datacenters), separator=',') ]) env.fout(table)
def cli(env, identifier, no_vs, no_hardware): """Cancel a subnet.""" mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.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', formatting.blank())]) table.add_row( ['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row( ['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table(['Hostname', 'Domain', 'IP']) vs_table.align['Hostname'] = 'r' vs_table.align['IP'] = 'l' for vsi in subnet['virtualGuests']: vs_table.add_row([ vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress') ]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if subnet['hardware']: hw_table = formatting.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 cli(env, identifier, no_vs, no_hardware): """Get subnet details.""" mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.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(['network space', utils.lookup(subnet, 'networkVlan', 'networkSpace')]) table.add_row(['gateway', subnet.get('gateway', formatting.blank())]) table.add_row(['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table(['Hostname', 'Domain', 'IP']) vs_table.align['Hostname'] = 'r' vs_table.align['IP'] = 'l' for vsi in subnet['virtualGuests']: vs_table.add_row([vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress')]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if subnet['hardware']: hw_table = formatting.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']) env.fout(table)
def cli(env, identifier): """Get details for an image.""" image_mgr = SoftLayer.ImageManager(env.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK) children_images = image.get('children') total_size = utils.lookup(image, 'firstChild', 'blockDevicesDiskSpaceTotal') or 0 table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', image['id']]) table.add_row([ 'global_identifier', image.get('globalIdentifier', formatting.blank()) ]) table.add_row(['name', image['name'].strip()]) table.add_row([ 'status', formatting.FormattedItem( utils.lookup(image, 'status', 'keyname'), utils.lookup(image, 'status', 'name'), ) ]) table.add_row([ 'active_transaction', formatting.listing(_get_transaction_groups(children_images), separator=','), ]) table.add_row(['account', image.get('accountId', formatting.blank())]) table.add_row([ 'visibility', image_mod.PUBLIC_TYPE if image['publicFlag'] else image_mod.PRIVATE_TYPE ]) table.add_row([ 'type', formatting.FormattedItem( utils.lookup(image, 'imageType', 'keyName'), utils.lookup(image, 'imageType', 'name'), ) ]) table.add_row(['flex', image.get('flexImageFlag')]) table.add_row(['note', image.get('note')]) table.add_row(['created', image.get('createDate')]) table.add_row(['total_size', formatting.b_to_gb(total_size)]) table.add_row(['datacenters', _get_datacenter_table(children_images)]) env.fout(table)
def cli(env, sortby, datacenter, identifier, subnet_type, network_space, ipv4, ipv6): """List subnets.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table([ 'id', 'identifier', 'type', 'network_space', 'datacenter', 'vlan_id', 'IPs', 'hardware', 'vs', ]) table.sortby = sortby version = 0 if ipv4: version = 4 elif ipv6: version = 6 subnets = mgr.list_subnets( datacenter=datacenter, version=version, identifier=identifier, subnet_type=subnet_type, network_space=network_space, ) for subnet in subnets: table.add_row([ subnet['id'], '%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr'])), subnet.get('subnetType', formatting.blank()), utils.lookup(subnet, 'networkVlan', 'networkSpace') or formatting.blank(), utils.lookup( subnet, 'datacenter', 'name', ) or formatting.blank(), subnet['networkVlanId'], subnet['ipAddressCount'], len(subnet['hardware']), len(subnet['virtualGuests']), ]) env.fout(table)
def execute(self, args): manager = SoftLayer.MessagingManager(self.client) regions = manager.get_endpoints() table = formatting.Table(['name', 'public', 'private']) for region, endpoints in regions.items(): table.add_row([ region, endpoints.get('public') or formatting.blank(), endpoints.get('private') or formatting.blank(), ]) return table
def cli(env, identifier): """Get details about a security group.""" mgr = SoftLayer.NetworkManager(env.client) secgroup = mgr.get_securitygroup(identifier) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', secgroup['id']]) table.add_row(['name', secgroup.get('name') or formatting.blank()]) table.add_row(['description', secgroup.get('description') or formatting.blank()]) rule_table = formatting.Table(['id', 'remoteIp', 'remoteGroupId', 'direction', 'ethertype', 'portRangeMin', 'portRangeMax', 'protocol']) for rule in secgroup.get('rules', []): rg_id = rule.get('remoteGroup', {}).get('id') or formatting.blank() port_min = rule.get('portRangeMin') port_max = rule.get('portRangeMax') if port_min is None: port_min = formatting.blank() if port_max is None: port_max = formatting.blank() rule_table.add_row([rule['id'], rule.get('remoteIp') or formatting.blank(), rule.get('remoteGroupId', rg_id), rule['direction'], rule.get('ethertype') or formatting.blank(), port_min, port_max, rule.get('protocol') or formatting.blank()]) table.add_row(['rules', rule_table]) vsi_table = formatting.Table(['id', 'hostname', 'interface', 'ipAddress']) for binding in secgroup.get('networkComponentBindings', []): try: vsi = binding['networkComponent']['guest'] vsi_id = vsi['id'] hostname = vsi['hostname'] interface = ('PRIVATE' if binding['networkComponent']['port'] == 0 else 'PUBLIC') ip_address = (vsi['primaryBackendIpAddress'] if binding['networkComponent']['port'] == 0 else vsi['primaryIpAddress']) except KeyError: vsi_id = "N/A" hostname = "Not enough permission to view" interface = "N/A" ip_address = "N/A" vsi_table.add_row([vsi_id, hostname, interface, ip_address]) table.add_row(['servers', vsi_table]) env.fout(table)
def rule_list(env, securitygroup_id, sortby): """List security group rules.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(COLUMNS) table.sortby = sortby rules = mgr.list_securitygroup_rules(securitygroup_id) for rule in rules: port_min = rule.get('portRangeMin') port_max = rule.get('portRangeMax') if port_min is None: port_min = formatting.blank() if port_max is None: port_max = formatting.blank() table.add_row([ rule['id'], rule.get('remoteIp') or formatting.blank(), rule.get('remoteGroupId') or formatting.blank(), rule['direction'], rule.get('ethertype') or formatting.blank(), port_min, port_max, rule.get('protocol') or formatting.blank(), rule.get('createDate') or formatting.blank(), rule.get('modifyDate') or formatting.blank() ]) env.fout(table)
def execute(self, args): mgr = SoftLayer.NetworkManager(self.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, args.get('<identifier>'), name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.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', formatting.blank())]) table.add_row(['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not args.get('--no-vs'): if subnet['virtualGuests']: vs_table = formatting.Table(['Hostname', 'Domain', 'IP']) vs_table.align['Hostname'] = 'r' vs_table.align['IP'] = 'l' for vsi in subnet['virtualGuests']: vs_table.add_row([vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress')]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not args.get('--no-hardware'): if subnet['hardware']: hw_table = formatting.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 = 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): """List SoftLayer Message Queue Endpoints.""" manager = SoftLayer.MessagingManager(env.client) regions = manager.get_endpoints() table = formatting.Table(['name', 'public', 'private']) for region, endpoints in regions.items(): table.add_row([ region, endpoints.get('public') or formatting.blank(), endpoints.get('private') or formatting.blank(), ]) return table
def execute(self, args): manager = SoftLayer.MessagingManager(self.client) regions = manager.get_endpoints() table = formatting.Table([ 'name', 'public', 'private' ]) for region, endpoints in regions.items(): table.add_row([ region, endpoints.get('public') or formatting.blank(), endpoints.get('private') or formatting.blank(), ]) return table
def cli(env, sortby, datacenter, number, name, limit): """List VLANs.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(COLUMNS) table.sortby = sortby vlans = mgr.list_vlans(datacenter=datacenter, vlan_number=number, name=name, limit=limit) for vlan in vlans: billing = 'Yes' if vlan.get('billingItem') else 'No' table.add_row([ vlan.get('id'), vlan.get('vlanNumber'), vlan.get('name') or formatting.blank(), get_gateway_firewall(vlan), utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'), vlan.get('hardwareCount'), vlan.get('virtualGuestCount'), vlan.get('totalPrimaryIpAddressCount'), billing, formatting.tags(vlan['tagReferences']) ]) env.fout(table)
def cli(env, name, description): """Create a security group.""" mgr = SoftLayer.NetworkManager(env.client) result = mgr.create_securitygroup(name, description) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', result['id']]) table.add_row(['name', result.get('name') or formatting.blank()]) table.add_row(['description', result.get('description') or formatting.blank()]) table.add_row(['created', result['createDate']]) env.fout(table)
def cli(env): """List firewalls.""" mgr = SoftLayer.FirewallManager(env.client) table = formatting.Table(['firewall id', 'type', 'features', 'server/vlan id']) fwvlans = mgr.get_firewalls() dedicated_firewalls = [firewall for firewall in fwvlans if firewall['dedicatedFirewallFlag']] for vlan in dedicated_firewalls: features = [] if vlan['highAvailabilityFirewallFlag']: features.append('HA') if features: feature_list = formatting.listing(features, separator=',') else: feature_list = formatting.blank() table.add_row([ 'vlan:%s' % vlan['networkVlanFirewall']['id'], 'VLAN - dedicated', feature_list, vlan['id'] ]) shared_vlan = [firewall for firewall in fwvlans if not firewall['dedicatedFirewallFlag']] for vlan in shared_vlan: vs_firewalls = [guest for guest in vlan['firewallGuestNetworkComponents'] if has_firewall_component(guest)] for firewall in vs_firewalls: table.add_row([ 'vs:%s' % firewall['id'], 'Virtual Server - standard', '-', firewall['guestNetworkComponent']['guest']['id'] ]) server_firewalls = [server for server in vlan['firewallNetworkComponents'] if has_firewall_component(server)] for firewall in server_firewalls: table.add_row([ 'server:%s' % firewall['id'], 'Server - standard', '-', utils.lookup(firewall, 'networkComponent', 'downlinkComponent', 'hardwareId') ]) env.fout(table)
def execute(self, args): mgr = SoftLayer.NetworkManager(self.client) table = formatting.Table([ 'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'vs', '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 formatting.blank(), vlan['totalPrimaryIpAddressCount'], len(vlan['hardware']), len(vlan['virtualGuests']), len(vlan['networkComponents']), 'Yes' if vlan['firewallInterfaces'] else 'No', ]) return table
def cli(env, sortby, datacenter, number, name): """List VLANs.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table([ 'id', 'number', 'datacenter', 'name', 'IPs', 'hardware', 'vs', 'networking', 'firewall' ]) table.sortby = sortby vlans = mgr.list_vlans(datacenter=datacenter, vlan_number=number, name=name) for vlan in vlans: table.add_row([ vlan['id'], vlan['vlanNumber'], vlan['primaryRouter']['datacenter']['name'], vlan.get('name') or formatting.blank(), vlan['totalPrimaryIpAddressCount'], len(vlan['hardware']), len(vlan['virtualGuests']), len(vlan['networkComponents']), 'Yes' if vlan['firewallInterfaces'] else 'No', ]) return table
def cli(env, is_open): """List tickets.""" ticket_mgr = SoftLayer.TicketManager(env.client) tickets = ticket_mgr.list_tickets(open_status=is_open, closed_status=not is_open) table = formatting.Table(['id', 'assigned_user', 'title', 'last_edited', 'status']) for ticket in tickets: user = formatting.blank() if ticket.get('assignedUser'): user = "******" % (ticket['assignedUser']['firstName'], ticket['assignedUser']['lastName']) table.add_row([ ticket['id'], user, click.wrap_text(ticket['title']), ticket['lastEditDate'], ticket['status']['name'], ]) env.fout(table)
def cli(env, sortby, datacenter, number, name, limit): """List VLANs.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(COLUMNS) table.sortby = sortby vlans = mgr.list_vlans(datacenter=datacenter, vlan_number=number, name=name, limit=limit) for vlan in vlans: table.add_row([ vlan['id'], vlan['vlanNumber'], vlan.get('name') or formatting.blank(), 'Yes' if vlan['firewallInterfaces'] else 'No', utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name'), vlan['hardwareCount'], vlan['virtualGuestCount'], vlan['totalPrimaryIpAddressCount'], ]) env.fout(table)
def cli(env, name, description): """Create a security group.""" mgr = SoftLayer.NetworkManager(env.client) result = mgr.create_securitygroup(name, description) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', result['id']]) table.add_row(['name', result.get('name') or formatting.blank()]) table.add_row( ['description', result.get('description') or formatting.blank()]) table.add_row(['created', result['createDate']]) env.fout(table)
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, hourly, monthly, tag, columns, limit, transient): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) guests = vsi.list_instances(hourly=hourly, monthly=monthly, hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, transient=transient, tags=tag, mask=columns.mask(), limit=limit) table = formatting.Table(columns.columns) table.sortby = sortby for guest in guests: table.add_row( [value or formatting.blank() for value in columns.row(guest)]) env.fout(table)
def cli(env, sortby, datacenter, number, name): """List VLANs.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(["id", "number", "datacenter", "name", "IPs", "hardware", "vs", "networking", "firewall"]) table.sortby = sortby vlans = mgr.list_vlans(datacenter=datacenter, vlan_number=number, name=name) for vlan in vlans: table.add_row( [ vlan["id"], vlan["vlanNumber"], utils.lookup(vlan, "primaryRouter", "datacenter", "name"), vlan.get("name") or formatting.blank(), vlan["totalPrimaryIpAddressCount"], len(vlan["hardware"]), len(vlan["virtualGuests"]), len(vlan["networkComponents"]), "Yes" if vlan["firewallInterfaces"] else "No", ] ) env.fout(table)
def cli(env, identifier): """Get details for an image.""" image_mgr = SoftLayer.ImageManager(env.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') image = image_mgr.get_image(image_id, mask=image_mod.DETAIL_MASK) disk_space = 0 datacenters = [] for child in image.get('children'): disk_space = int(child.get('blockDevicesDiskSpaceTotal', 0)) if child.get('datacenter'): datacenters.append(utils.lookup(child, 'datacenter', 'name')) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', image['id']]) table.add_row(['global_identifier', image.get('globalIdentifier', formatting.blank())]) table.add_row(['name', image['name'].strip()]) table.add_row(['status', formatting.FormattedItem( utils.lookup(image, 'status', 'keyname'), utils.lookup(image, 'status', 'name'), )]) table.add_row([ 'active_transaction', formatting.transaction_status(image.get('transaction')), ]) table.add_row(['account', image.get('accountId', formatting.blank())]) table.add_row(['visibility', image_mod.PUBLIC_TYPE if image['publicFlag'] else image_mod.PRIVATE_TYPE]) table.add_row(['type', formatting.FormattedItem( utils.lookup(image, 'imageType', 'keyName'), utils.lookup(image, 'imageType', 'name'), )]) table.add_row(['flex', image.get('flexImageFlag')]) table.add_row(['note', image.get('note')]) table.add_row(['created', image.get('createDate')]) table.add_row(['disk_space', formatting.b_to_gb(disk_space)]) table.add_row(['datacenters', formatting.listing(sorted(datacenters), separator=',')]) env.fout(table)
def _get_owner_row(result): """Formats and resturns the Owner row""" if utils.lookup(result, 'billingItem') != []: owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') else: owner = formatting.blank() return (['owner', owner])
def test_transaction_status_missing(self): b = formatting.blank() result = formatting.transaction_status({ 'transactionStatus': {} }) self.assertIsInstance(result, formatting.FormattedItem) self.assertEqual(result.original, b.original)
def test_format_output_json_keyvaluetable(self): t = formatting.KeyValueTable(['key', 'value']) t.add_row(['nothing', formatting.blank()]) t.sortby = 'nothing' ret = formatting.format_output(t, 'json') self.assertEqual('''{ "nothing": null }''', ret)
def cli(env, sortby): """List security groups.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(COLUMNS) table.sortby = sortby sgs = mgr.list_securitygroups() for secgroup in sgs: table.add_row([ secgroup['id'], secgroup.get('name') or formatting.blank(), secgroup.get('description') or formatting.blank(), ]) env.fout(table)
def cli(env, sortby, limit): """List security groups.""" mgr = SoftLayer.NetworkManager(env.client) table = formatting.Table(COLUMNS) table.sortby = sortby sgs = mgr.list_securitygroups(limit=limit) for secgroup in sgs: table.add_row([ secgroup['id'], secgroup.get('name') or formatting.blank(), secgroup.get('description') or formatting.blank(), ]) env.fout(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 test_active_txn_missing(self): """ a dict with activeTransaction but not transactionStatus should return blank() instead of raising an exception """ b = formatting.blank() result = formatting.active_txn({"activeTransaction": {}}) self.assertIsInstance(result, formatting.FormattedItem) self.assertEqual(result.original, b.original)
def test_active_txn_missing(self): # A dict with activeTransaction but not transactionStatus # should return blank() instead of raising an exception b = formatting.blank() result = formatting.active_txn({'activeTransaction': {}}) self.assertIsInstance(result, formatting.FormattedItem) self.assertEqual(result.original, b.original)
def execute(self, args): image_mgr = SoftLayer.ImageManager(self.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, args.get('<identifier>'), 'image') image = image_mgr.get_image(image_id) table = formatting.KeyValueTable(['Name', 'Value']) table.align['Name'] = 'r' table.align['Value'] = 'l' table.add_row(['id', image['id']]) table.add_row(['account', image.get('accountId', formatting.blank())]) table.add_row(['name', image['name'].strip()]) table.add_row(['global_identifier', image.get('globalIdentifier', formatting.blank())]) return table
def execute(self, args): iscsi_mgr = SoftLayer.ISCSIManager(self.client) iscsi_list = iscsi_mgr.list_iscsi() iscsi_list = [utils.NestedDict(n) for n in iscsi_list] table = formatting.Table(["id", "datacenter", "size", "username", "password", "server"]) for iscsi in iscsi_list: table.add_row( [ iscsi["id"], iscsi["serviceResource"]["datacenter"].get("name", formatting.blank()), formatting.FormattedItem( iscsi.get("capacityGb", formatting.blank()), "%dGB" % iscsi.get("capacityGb", 0) ), iscsi.get("username", formatting.blank()), iscsi.get("password", formatting.blank()), iscsi.get("serviceResourceBackendIpAddress", formatting.blank()), ] ) return table
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, hourly, monthly, tags): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) tag_list = None if tags: tag_list = [tag.strip() for tag in tags.split(',')] guests = vsi.list_instances(hourly=hourly, monthly=monthly, hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, tags=tag_list) table = formatting.Table([ 'id', 'datacenter', 'host', 'cores', 'memory', 'primary_ip', 'backend_ip', 'active_transaction', 'owner' ]) table.sortby = sortby or 'host' for guest in guests: guest = utils.NestedDict(guest) table.add_row([ guest['id'], guest['datacenter']['name'] or formatting.blank(), guest['fullyQualifiedDomainName'], guest['maxCpu'], formatting.mb_to_gb(guest['maxMemory']), guest['primaryIpAddress'] or formatting.blank(), guest['primaryBackendIpAddress'] or formatting.blank(), formatting.active_txn(guest), utils.lookup(guest, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(), ]) return table
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, hourly, monthly, tags): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) tag_list = None if tags: tag_list = [tag.strip() for tag in tags.split(',')] guests = vsi.list_instances(hourly=hourly, monthly=monthly, hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, tags=tag_list) table = formatting.Table([ 'guid', 'hostname', 'primary_ip', 'backend_ip', 'datacenter', 'action', ]) table.sortby = sortby or 'hostname' for guest in guests: guest = utils.NestedDict(guest) table.add_row([ guest['globalIdentifier'] or guest['id'], guest['hostname'], guest['primaryIpAddress'] or formatting.blank(), guest['primaryBackendIpAddress'] or formatting.blank(), guest['datacenter']['name'] or formatting.blank(), formatting.active_txn(guest), ]) return table
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, hourly, monthly, tags): """List virtual servers.""" vsi = SoftLayer.VSManager(env.client) tag_list = None if tags: tag_list = [tag.strip() for tag in tags.split(',')] guests = vsi.list_instances(hourly=hourly, monthly=monthly, hostname=hostname, domain=domain, cpus=cpu, memory=memory, datacenter=datacenter, nic_speed=network, tags=tag_list) table = formatting.Table([ 'id', 'hostname', 'primary_ip', 'backend_ip', 'datacenter', 'action', ]) table.sortby = sortby or 'hostname' for guest in guests: table.add_row([ utils.lookup(guest, 'id'), utils.lookup(guest, 'hostname') or formatting.blank(), utils.lookup(guest, 'primaryIpAddress') or formatting.blank(), utils.lookup(guest, 'primaryBackendIpAddress') or formatting.blank(), utils.lookup(guest, 'datacenter', 'name') or formatting.blank(), formatting.active_txn(guest), ]) return table
def get_gateway_firewall(vlan): """Gets the name of a gateway/firewall from a VLAN. """ firewall = utils.lookup(vlan, 'networkVlanFirewall', 'fullyQualifiedDomainName') if firewall: return firewall gateway = utils.lookup(vlan, 'attachedNetworkGateway', 'name') if gateway: return gateway return formatting.blank()