如何在softlayer API中查找子网中的IP是否用于HSRP

时间:2017-03-16 21:16:46

标签: ibm-cloud-infrastructure

我们在私有VLAN上订购了一个子网,当我们尝试使用其中一个IP时。我们意识到IP被用于Softlayer基础设施的路由器/交换机上的HSRP。是否有任何SL API来确定IP是否用于此目的?我们通常使用基于softlayer python的客户端代码提取IP,如下所示

ipinfo = network.ip_lookup()

并确定它是否用于任何保留目的

ipinfo ['isGateway']为True或ipinfo ['isBroadcast']为True或ipinfo ['isReserved']为True

非常感谢您对此的投入。

由于

1 个答案:

答案 0 :(得分:0)

为HSRP保留的IP地址的属性 isReserved 为True,在 note 属性中为“为HSRP保留。”

您可以使用方法SoftLayer_Network_Subnet::getIpAddresses和以下过滤器来获取这些IP地址:

            objectFilter={'ipAddresses':{'note':{'operation':'Reserved for HSRP.'}}}

下面你可以看到python中的一个例子。

"""
Get Ip Addresses of a subnet which are reserved for HSRP protocol.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/getIpAddresses
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Subnet_IpAddress
https://sldn.softlayer.com/article/object-Masks
https://sldn.softlayer.com/article/object-filters

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set-me'
API_KEY = 'set-me'

# The id of subnet you wish to get information.
subnetId = 135840

# Object mask helps to get more and specific information
mask = 'id,ipAddress,isReserved,note'

# Use object-filter to get Ip Addresses reserved for HSRP
filter = {
            'ipAddresses': {
                'note': {'operation': 'Reserved for HSRP.'}
            }
        }

# Call SoftLayer API client
client = SoftLayer.create_client_from_env(username=API_USERNAME, api_key=API_KEY)

try:
    result = client['SoftLayer_Network_Subnet'].getIpAddresses(id=subnetId,
                                                               mask=mask,
                                                               filter=filter)
    pp(result)

except SoftLayer.SoftLayerAPIError as e:
    pp('Unable to get the Ip Addresses %s, %s' % (e.faultCode, e.faultString))

链接:

https://knowledgelayer.softlayer.com/articles/static-and-portable-ip-blocks http://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/getIpAddresses http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Subnet

我希望这对你有所帮助。

此致