本文整理汇总了Python中SoftLayer.CLI.Table.sortby方法的典型用法代码示例。如果您正苦于以下问题:Python Table.sortby方法的具体用法?Python Table.sortby怎么用?Python Table.sortby使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SoftLayer.CLI.Table
的用法示例。
在下文中一共展示了Table.sortby方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
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
示例2: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
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
示例3: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
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
示例4: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
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
示例5: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
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
示例6: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(self, args):
manager = CDNManager(self.client)
accounts = manager.list_accounts()
table = Table(['id', 'account_name', 'type', 'created', 'notes'])
for account in accounts:
table.add_row([
account['id'],
account['cdnAccountName'],
account['cdnSolutionName'],
account['createDate'],
account.get('cdnAccountNote', blank())
])
table.sortby = args['--sortby']
return table
示例7: get_rules_table
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def get_rules_table(rules):
""" Helper to format the rules into a table
:param list rules: A list containing the rules of the firewall
:returns: a formatted table of the firewall rules
"""
table = Table(['#', 'action', 'protocol', 'src_ip', 'src_mask', 'dest',
'dest_mask'])
table.sortby = '#'
for rule in rules:
table.add_row([
rule['orderValue'],
rule['action'],
rule['protocol'],
rule['sourceIpAddress'],
rule['sourceIpSubnetMask'],
'%s:%s-%s' % (rule['destinationIpAddress'],
rule['destinationPortRangeStart'],
rule['destinationPortRangeEnd']),
rule['destinationIpSubnetMask']])
return table
示例8: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(self, args):
mgr = LoadBalancerManager(self.client)
table = Table(['id', 'capacity', 'description', 'price'])
table.sortby = 'price'
table.align['price'] = 'r'
table.align['capacity'] = 'r'
table.align['id'] = 'r'
packages = mgr.get_lb_pkgs()
for package in packages:
table.add_row([
package['prices'][0]['id'],
package.get('capacity'),
package['description'],
format(float(package['prices'][0]['recurringFee']), '.2f')
])
return table
示例9: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(self, args):
cci = CCIManager(self.client)
tags = None
if args.get('--tags'):
tags = [tag.strip() for tag in args.get('--tags').split(',')]
guests = cci.list_instances(
hourly=args.get('--hourly'),
monthly=args.get('--monthly'),
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)
t = Table([
'id', 'datacenter', 'host',
'cores', 'memory', 'primary_ip',
'backend_ip', 'active_transaction',
])
t.sortby = args.get('--sortby') or 'host'
for guest in guests:
guest = NestedDict(guest)
t.add_row([
guest['id'],
guest['datacenter']['name'] or blank(),
guest['fullyQualifiedDomainName'],
guest['maxCpu'],
mb_to_gb(guest['maxMemory']),
guest['primaryIpAddress'] or blank(),
guest['primaryBackendIpAddress'] or blank(),
active_txn(guest),
])
return t
示例10: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(self, args):
mgr = NetworkManager(self.client)
datacenters = mgr.summary_by_datacenter()
t = Table([
'datacenter', 'vlans', 'subnets', 'IPs', 'networking',
'hardware', 'ccis'
])
t.sortby = args.get('--sortby') or 'datacenter'
for name, dc in datacenters.iteritems():
t.add_row([
name,
dc['vlanCount'],
dc['subnetCount'],
dc['primaryIpCount'],
dc['networkingCount'],
dc['hardwareCount'],
dc['virtualGuestCount'],
])
return t
示例11: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(self, args):
mgr = NetworkManager(self.client)
table = Table([
'id', 'ip', 'assigned', 'target'
])
table.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_address in ips:
assigned = 'No'
target = 'None'
if ip_address.get('destinationIpAddress'):
dest = ip_address['destinationIpAddress']
assigned = 'Yes'
target = dest['ipAddress']
virtual_guest = dest.get('virtualGuest')
if virtual_guest:
target += (' (%s)'
% virtual_guest['fullyQualifiedDomainName'])
elif ip_address['destinationIpAddress'].get('hardware'):
target += ' (' + \
dest['hardware']['fullyQualifiedDomainName'] + \
')'
table.add_row([ip_address['id'],
ip_address['ipAddress']['ipAddress'],
assigned,
target])
return table
示例12: execute
# 需要导入模块: from SoftLayer.CLI import Table [as 别名]
# 或者: from SoftLayer.CLI.Table import sortby [as 别名]
def execute(client, args):
cci = CCIManager(client)
results = cci.list_instances(
hourly=args.get('--hourly'), monthly=args.get('--monthly'))
t = Table([
'id', 'datacenter', 'host',
'cores', 'memory', 'primary_ip',
'backend_ip', 'active_transaction',
])
t.sortby = args.get('--sortby') or 'host'
if args.get('--tags'):
tags = [tag.strip() for tag in args.get('--tags').split(',')]
guests = []
for g in results:
guest_tags = [x['tag']['name'] for x in g['tagReferences']]
if any(_tag in tags for _tag in guest_tags):
guests.append(g)
else:
guests = results
for guest in guests:
t.add_row([
guest['id'],
guest.get('datacenter', {}).get('name', 'unknown'),
guest['fullyQualifiedDomainName'],
guest['maxCpu'],
mb_to_gb(guest['maxMemory']),
guest.get('primaryIpAddress', '-'),
guest.get('primaryBackendIpAddress', '-'),
guest.get('activeTransaction', {}).get(
'transactionStatus', {}).get('friendlyName', '<None>'),
])
return t