November 23, 2017
List global IP address

Example to list the global IP address from an account
and see if a specific IP is assigned to a specific host

Important manual pages:
import SoftLayer

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

# The global Ip address you want to verify if it is assigned
globalIpId = 11222

# The hostname of the virtual guest that you want to verify if it is assigned
hostnameAssigned = "danone-fw1"

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']

# Declaring a mask to get more details for the global IP adreesess
objectMask = "mask[destinationIpAddress[hardware, virtualGuest]]"

    # Getting the global IP list for the account
    globalIps = accountService.getGlobalIpRecords(mask=objectMask)
except SoftLayer.SoftLayerAPIError as e:
    # In case there was an error, we print the following
    print("Unable to retrieve the global IP address faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))

globalIpFound = False
for globalIp in globalIps:
    if globalIpId == globalIp['id']:
        globalIpFound = True
        targetIp = globalIp['destinationIpAddress']['ipAddress']
        associatedHostname = ""
        if 'hardware' in globalIp['destinationIpAddress'].keys():
            associatedHostname = globalIp['destinationIpAddress']['hardware']['hostname']
        elif 'virtualGuest' in globalIp['destinationIpAddress'].keys():
            associatedHostname = globalIp['destinationIpAddress']['virtualGuest']['hostname']
        if associatedHostname == hostnameAssigned:
            print("the global IP is assigned.")
            print("the global IP is not assigned.")

if not globalIpFound:
    print("The global IP address does not exist.")


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue