要獲取有關其子網的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
你好,我找別的東西。這涉及VLAN /子網中可用的總IP數量以及已經分配給設備或免費分配的Ips數量。 – aaj
您給予的API給了我一個IP所屬的VLAN。 – aaj
請。讓我回顧一下這個:)。我會給你發送其他更新 – mcruz