SoftLayer API以了解VLAN中的总数和可用IP
您好,
如果我知道VLAN ID
,可以使用哪个API来了解VLAN的总IP和已使用/可用的IP。
我能想到的一种方法是,我可以获得VLAN的子网,然后在子网详细信息中,我可以看到具有"totalIpAddresses,usableIpAddressCount"
属性的总IP和可用IP。但是,由于VLAN具有多个子网,因此我必须获得VLAN的总IP和可用IP的总和。不确定这是否正确。
由于
答案 0 :(得分:0)
请尝试以下方法:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Vlan/[Vlan_id]/getObject?objectMask=mask[subnets[ipAddresses]]
Method: GET
或者,
如果您希望此请求通过IP关联的子网检索与IP地址关联的VLAN
:
URL:
https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Vlan/getVlanForIpAddress?objectMask=mask[id, vlanNumber,networkSpace,primaryRouter]
Method: POST
JSON:
{
"parameters": [
"10.41.160.194"
]
}
您还可以看到上述请求的“子网”部分中显示的数据的含义,即:
totalIpAddresses:此子网中包含的IP地址数。
usefulIpAddressCount:此子网内可以寻址的IP地址数。
答案 1 :(得分:0)
要使用总使用/可用IP获取有关其子网的vlan的信息,请尝试以下Python脚本。
此脚本将有助于从vlan中的子网获取确切的空闲插槽数。
"""
This script retrieves the Total Ip Addresses, Usable Ip Address Count and Free Slots for an specific Vlan Id
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getNetworkVlans
http://sldn.softlayer.com/article/object-masks
http://sldn.softlayer.com/article/object-filters
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from prettytable import PrettyTable
# Declare your SoftLayer username and apiKey
username = 'set me'
apikey = 'set me'
# Define the vlan Id
vlanId = 318734
# Contact To SoftLayer
client = SoftLayer.Client(username=username, api_key=apikey)
# Declare an Object Mask to get additional information
object_mask = 'mask[primaryRouter,primarySubnet[datacenter[name]],subnets[billingItem, subnetType,networkIdentifier, cidr, totalIpAddresses, usableIpAddressCount, ipAddresses[ipAddress, isReserved, virtualGuest, hardware]]]'
# Declare an Object Filter to get information from specific vlan
filter = {'networkVlans': {'id': {'operation': vlanId}}}
result = client['SoftLayer_Account'].getNetworkVlans(mask=object_mask, filter=filter)
x = PrettyTable(["Vlan Id", "Vlan Number", "Subnet", "Total Ip Addresses", "Usable Ip Address Count","Free Slots"])
count = 0
for vlan in result:
for subnet in vlan['subnets']:
for item in subnet['ipAddresses']:
if item['isReserved'] == True:
count = count + 1
if 'hardware' in item:
count = count + 1
if 'virtualGuest' in item:
count = count + 1
if (subnet['usableIpAddressCount'] - count) > 0:
if subnet['subnetType'] == 'PRIMARY' or subnet['subnetType'] == 'ADDITIONAL_PRIMARY':
x.add_row([vlan['id'], str('%s %s' % (vlan['primaryRouter']['hostname'], vlan['vlanNumber'])), str('%s/%s' % (subnet['networkIdentifier'], subnet['cidr'])), subnet['totalIpAddresses'], subnet['usableIpAddressCount'], (subnet['usableIpAddressCount'] - count)])
count = 0
print(x)