SoftLayer API可以知道VLAN中的IP总数以及可用的IP [英] SoftLayer API to know and total and available IPs in a VLAN

查看:90
本文介绍了SoftLayer API可以知道VLAN中的IP总数以及可用的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SoftLayer API可以知道VLAN中的IP总数以及可用的IP

SoftLayer API to know and total and available IPs in a VLAN

你好

如果我知道VLAN ID,可以使用哪个API知道VLAN的总IP和已使用/可用IP.

Which API can be used to know the total IPs and the used/usable IPs of a VLAN if I know the VLAN ID.

我可以弄清楚的一种方法是,我可以获取VLAN的子网,然后在子网详细信息中,可以看到具有"totalIpAddresses,usableIpAddressCount"属性的IP总数和可用IP.但是由于VLAN具有多个子网,因此我将必须获取VLAN的总IP和可用IP.不确定这是否正确.

One way I could figure out is I can get subnets of a VLAN and then in subnet details I can see total and usable IPs with "totalIpAddresses,usableIpAddressCount" attributes . But then I will have to get sum of total and usable IPs for a VLAN since a VLAN has multiple subnets. Not sure if this is the correct way.

谢谢

推荐答案

要获取有关vlan的子网及其使用/可用IP总数的信息,请尝试以下Python脚本.

To get the information for the vlan about its subnets with the total used/usable IPs, try the following Python Script.

此脚本将有助于从VLAN内的子网中获取准确的可用插槽数.

This script will help to get the exact number of free slots from subnets inside the 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)

参考: SoftLayer_Account :: getNetworkVlans

这篇关于SoftLayer API可以知道VLAN中的IP总数以及可用的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆