本文整理汇总了Python中SoftLayer.NetworkManager类的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager类的具体用法?Python NetworkManager怎么用?Python NetworkManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, args):
mgr = NetworkManager(self.client)
update = {
'abuse_email': args.get('--abuse'),
'address1': args.get('--address1'),
'address2': args.get('--address2'),
'city': args.get('--city'),
'country': args.get('--country'),
'first_name': args.get('--firstname'),
'last_name': args.get('--lastname'),
'postal_code': args.get('--postal'),
'state': args.get('--state')
}
if args.get('--private'):
update['private_residence'] = False
elif args.get('--public'):
update['private_residence'] = True
check = [x for x in update.values() if x is not None]
if not check:
raise CLIAbort("You must specify at least one field to update.")
mgr.edit_rwhois(**update) # pylint: disable=W0142
示例2: execute
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
示例3: execute
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
示例4: execute
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
示例5: execute
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
示例6: execute
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
示例7: execute
def execute(self, args):
mgr = NetworkManager(self.client)
global_ip_id = mgr.resolve_global_ip_ids(args.get('<identifier>'))
if not global_ip_id:
raise CLIAbort("Unable to find global IP record for " +
args['<identifier>'])
mgr.unassign_global_ip(global_ip_id)
示例8: execute
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
示例9: execute
def execute(client, args):
mgr = NetworkManager(client)
ip = mgr.ip_lookup(args['<ip>'])
if not ip:
return 'Not found'
t = KeyValueTable(['Name', 'Value'])
t.align['Name'] = 'r'
t.align['Value'] = 'l'
t.add_row(['id', ip['id']])
t.add_row(['ip', ip['ipAddress']])
subnet_table = KeyValueTable(['Name', 'Value'])
subnet_table.align['Name'] = 'r'
subnet_table.align['Value'] = 'l'
subnet_table.add_row(['id', ip['subnet']['id']])
subnet_table.add_row(['identifier', ip['subnet']['networkIdentifier']])
subnet_table.add_row(['netmask', ip['subnet']['netmask']])
if ip['subnet'].get('gateway'):
subnet_table.add_row(['gateway', ip['subnet']['gateway']])
subnet_table.add_row(['type', ip['subnet'].get('subnetType')])
t.add_row(['subnet', subnet_table])
if ip.get('virtualGuest') or ip.get('hardware'):
device_table = KeyValueTable(['Name', 'Value'])
device_table.align['Name'] = 'r'
device_table.align['Value'] = 'l'
if ip.get('virtualGuest'):
device = ip['virtualGuest']
device_type = 'cci'
else:
device = ip['hardware']
device_type = 'server'
device_table.add_row(['id', device['id']])
device_table.add_row(['name', device['fullyQualifiedDomainName']])
device_table.add_row(['type', device_type])
t.add_row(['device', device_table])
return t
示例10: execute
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: setUp
def setUp(self):
self.client = MagicMock()
self.network = NetworkManager(self.client)
示例12: NetworkTests
class NetworkTests(unittest.TestCase):
def setUp(self):
self.client = FixtureClient()
self.network = NetworkManager(self.client)
def test_ip_lookup(self):
service = self.client['Network_Subnet_IpAddress']
self.network.ip_lookup('10.0.1.37')
service.getByIpAddress.assert_called_with('10.0.1.37', mask=ANY)
def test_add_subnet_raises_exception_on_failure(self):
self.assertRaises(TypeError, self.network.add_subnet, ('bad'))
def test_add_global_ip(self):
# Test a global IPv4 order
result = self.network.add_global_ip(test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv4(self):
# Test a four public address IPv4 order
result = self.network.add_subnet('public',
quantity=4,
vlan_id=1234,
version=4,
test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
result = self.network.add_subnet('public',
quantity=4,
vlan_id=1234,
version=4,
test_order=False)
self.assertEqual(Product_Order.verifyOrder, result)
result = self.network.add_subnet('global',
test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv6(self):
# Test a public IPv6 order
result = self.network.add_subnet('public',
quantity=64,
vlan_id=45678,
version=6,
test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
# Test a global IPv6 order
result = self.network.add_subnet('global',
version=6,
test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_assign_global_ip(self):
self.network.assign_global_ip(9876, '172.16.24.76')
service = self.client['Network_Subnet_IpAddress_Global']
service.route.assert_called_with('172.16.24.76', id=9876)
def test_cancel_global_ip(self):
self.network.cancel_global_ip(1234)
service = self.client['Billing_Item']
service.cancelService.assert_called_with(id=1234)
def test_cancel_subnet(self):
self.network.cancel_subnet(1234)
service = self.client['Billing_Item']
service.cancelService.assert_called_with(id=1056)
def test_edit_rwhois(self):
self.network.edit_rwhois(
abuse_email='[email protected]',
address1='123 Test Street',
address2='Apt. #31',
city='Anywhere',
company_name='TestLayer',
country='US',
first_name='Bob',
last_name='Bobinson',
postal_code='9ba62',
private_residence=False,
state='TX')
expected = {
'abuseEmail': '[email protected]',
'address1': '123 Test Street',
'address2': 'Apt. #31',
'city': 'Anywhere',
'companyName': 'TestLayer',
'country': 'US',
#.........这里部分代码省略.........
示例13: NetworkTests
class NetworkTests(unittest.TestCase):
def setUp(self):
self.client = FixtureClient()
self.network = NetworkManager(self.client)
def test_ip_lookup(self):
service = self.client["Network_Subnet_IpAddress"]
self.network.ip_lookup("10.0.1.37")
service.getByIpAddress.assert_called_with("10.0.1.37", mask=ANY)
def test_add_subnet_raises_exception_on_failure(self):
self.assertRaises(TypeError, self.network.add_subnet, ("bad"))
def test_add_global_ip(self):
# Test a global IPv4 order
result = self.network.add_global_ip(test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv4(self):
# Test a four public address IPv4 order
result = self.network.add_subnet("public", quantity=4, vlan_id=1234, version=4, test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
result = self.network.add_subnet("public", quantity=4, vlan_id=1234, version=4, test_order=False)
self.assertEqual(Product_Order.verifyOrder, result)
result = self.network.add_subnet("global", test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv6(self):
# Test a public IPv6 order
result = self.network.add_subnet("public", quantity=64, vlan_id=45678, version=6, test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
# Test a global IPv6 order
result = self.network.add_subnet("global", version=6, test_order=True)
self.assertEqual(Product_Order.verifyOrder, result)
def test_assign_global_ip(self):
id = 9876
target = "172.16.24.76"
self.network.assign_global_ip(id, target)
service = self.client["Network_Subnet_IpAddress_Global"]
service.route.assert_called_with(target, id=id)
def test_cancel_global_ip(self):
service = self.client["Billing_Item"]
self.network.cancel_global_ip(1234)
service.cancelService.assert_called_with(id=1234)
def test_cancel_subnet(self):
service = self.client["Billing_Item"]
self.network.cancel_subnet(1234)
service.cancelService.assert_called_with(id=1056)
def test_edit_rwhois(self):
self.client["Account"].getRwhoisData.return_value = {"id": 954}
expected = {
"abuseEmail": "[email protected]",
"address1": "123 Test Street",
"address2": "Apt. #31",
"city": "Anywhere",
"companyName": "TestLayer",
"country": "US",
"firstName": "Bob",
"lastName": "Bobinson",
"postalCode": "9ba62",
"privateResidenceFlag": False,
"state": "TX",
}
self.network.edit_rwhois(
abuse_email="[email protected]",
address1="123 Test Street",
address2="Apt. #31",
city="Anywhere",
company_name="TestLayer",
country="US",
first_name="Bob",
last_name="Bobinson",
postal_code="9ba62",
private_residence=False,
state="TX",
)
f = self.client["Network_Subnet_Rwhois_Data"].editObject
f.assert_called_with(expected, id=954)
#.........这里部分代码省略.........
示例14: render
def render(self):
mgr = NetworkManager(get_client())
return render_template('network_widget_summary.html',
stats=mgr.summary_by_datacenter())
示例15: setUp
def setUp(self):
self.client = FixtureClient()
self.network = NetworkManager(self.client)