2016-03-04 55 views
0

SoftLayer的API中的VLAN的SoftLayer API知道,總以及可用IP一個VLAN

您好知道,總與可用IP,

哪些API可用於瞭解總的IP地址和使用/ VLAN的可用IP,如果我知道VLAN ID

我可以弄清楚的一個方法是我可以獲得VLAN的子網,然後在子網詳細信息中,我可以看到具有"totalIpAddresses,usableIpAddressCount"屬性的總可用IP。但是,由於VLAN具有多個子網,因此我必須獲取VLAN的總IP和可用IP的總和。不知道這是否是正確的方法。

感謝

回答

0

要獲取有關其子網的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. <[email protected]> 
""" 
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) 

參考文獻: SoftLayer_Account::getNetworkVlans

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" 
    ] 
} 

參考: getVlanForIpAddress

還可以看到在上述要求的 '子網' 部分上顯示的數據的含義,即:

totalIpAddresses:的此子網中包含的IP地址數。

usableIpAddressCount:可在此子網內尋址的IP地址數。

+0

你好,我找別的東西。這涉及VLAN /子網中可用的總IP數量以及已經分配給設備或免費分配的Ips數量。 – aaj

+1

您給予的API給了我一個IP所屬的VLAN。 – aaj

+0

請。讓我回顧一下這個:)。我會給你發送其他更新 – mcruz

相關問題