简体   繁体   English

Softlayer API:如何获取VSI的ipv6信息?

[英]Softlayer API: How to get a VSI's ipv6 info?

I have create a virtual server withing ipv6 address. 我已经创建了一个具有ipv6地址的虚拟服务器。 How can I get the IPv6 information by sl api? 如何通过sl api获取IPv6信息? I want the information likes: 我希望信息喜欢: 在此处输入图片说明

take a look to this code to get the details of the bare metal servers: 查看以下代码以获取裸机服务器的详细信息:

here an example for VM 这是VM的一个例子

"""
Get Virtual Guest details. It retrieves virtual guest information.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getObject
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Set your SoftLayer API username and key.

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

# Set the server id that you wish to get details.
# Call the getVirtualGuests method from SoftLayer_Account
serverId = 5464742

# Retrieve the wanted server information using a mask
mask = 'operatingSystem.passwords, networkComponents, datacenter, notes'

# Make a connection to the Virtual_Guest service.
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # Make the call to retrieve the server details.
    virtualGuestDetails = client['Virtual_Guest'].getObject(id=serverId,
                                                    mask=mask)
    pp(virtualGuestDetails)

except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to get the Virtual Guest infomrmation faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

this one is for bare metal 这个是裸机的

"""
Get Bare Metal details.

Retrieve a list of bare metal servers in the account and print
a report with server hostname, domain, login info, network, CPU,
and RAM details.
This script makes a single call to the getHardware() method in the
SoftLayer_Account API service  and uses an object mask to retrieve
related information.
See below for more details.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server/

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

"""
Your SoftLayer API username and key.

Generate an API key at the SoftLayer Customer Portal:
https://manage.softlayer.com/Administrative/apiKeychain
"""
USERNAME = 'set me'
API_KEY = 'set me'

"""
Add an object mask to retrieve our hardwares' related items such as its
operating system, hardware components, and network components. Object masks
can retrieve any information related to your object. See
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
# for a list of the relational properties you can retrieve along with hardware.
"""
objectMask = 'processors, processorCount, memory, memoryCount, networkComponents, primaryIpAddress, operatingSystem.passwords'


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

try:
    # Make the call to retrieve our bare metal servers.
    hardwareList = accountService.getHardware(mask=objectMask)
except SoftLayer.SoftLayerAPIError as e:
    """
    If there was an error returned from the SoftLayer API then bomb out with the
    error message.
    """
    print("Unable to retrieve the bare metal list. "
          % (e.faultCode, e.faultString))

for hardware in hardwareList:
    passwords = {}
    passwords['username'] = "no username"
    passwords['password'] = "no password"
    if len(hardware['operatingSystem']['passwords']) >= 1:
        passwords = hardware['operatingSystem']['passwords'][0]
    networks = hardware['networkComponents']
    """
    Go through the hardware's network components to get it's public and
    private network ports. Save MAC addresses.
    """
    publicMacAddress = 'not found'
    privateMacAddress = 'not found'
    for network in networks:
        """
        SoftLayer uses eth0 on the private network and eth1 on the public
        network.
        """
        if network['name'] == 'eth' and network['port'] == 0:
            privateMacAddress = network['macAddress']
        elif network['name'] == 'eth' and network['port'] == 1:
            publicMacAddress = network['macAddress']

    """
    Hardware can only have like processors in them, so use the first item in
    the processors array to get the type of processor in the server.
    """
    processorType = hardware['processors'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['capacity'] +\
                    hardware['processors'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['units'] + " " +\
                    hardware['processors'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['description']

    # Treat memory the same way we did processors.
    memoryType = hardware['memory'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['capacity'] +\
                 hardware['memory'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['units'] + " " +\
                 hardware['memory'][0]['hardwareComponentModel']['hardwareGenericComponentModel']['description']

    # All done! Print hardware info.
    print("Hostname: " + hardware['hostname'])
    print("Domain: " + hardware['domain'])
    print("Login: " + passwords['username'] + "/" + passwords['password'])
    print("Public IP Address: " + hardware['primaryIpAddress'])
    print("Public MAC Address: " + publicMacAddress)
    print("Private IP Address: " + hardware['privateIpAddress'])
    print("Private MAC Address: " + privateMacAddress)
    print("CPUs: " + str(hardware['processorCount']) + "x " + processorType)
    print("RAM: " + str(hardware['memoryCount']) + "x " + memoryType)
    print(" ")

Basically you need to use an object mask to get the properties of the server, you can see all the properties in documentation http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server 基本上,您需要使用对象掩码来获取服务器的属性,您可以在文档http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server中查看所有属性。

Let me know if you have more questions 如果您还有其他问题,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM