SL中自动缩放的详细信息

时间:2016-07-11 10:58:39

标签: ibm-cloud-infrastructure

我正在使用Java API实现自动缩放的详细信息。 如何获取成员配置的详细信息。请参阅附图中红色框中的字段。我可以得到详细的信息。例如,我可以获得操作参考代码,即CENTOS_6_64,但是如何获得像CentOS 6.x这样的长类型描述 - 最小安装(64位)。 member config group config

2 个答案:

答案 0 :(得分:0)

尝试使用此对象Mask

mask[id, name, status[name, keyName], regionalGroup[id, name, description], suspendedFlag, terminationPolicy, cooldown, regionalGroupId, minimumMemberCount, maximumMemberCount, balancedTerminationFlag, networkVlans[ id, networkVlan[ id, name, vlanNumber, networkSpace, primaryRouter[id,hostname,datacenter[name,longName]],localDiskStorageCapabilityFlag,sanStorageCapabilityFlag]],virtualGuestMemberTemplate[hostname,domain,fullyQualifiedDomainName,startCpus,maxMemory,hourlyBillingFlag,localDiskFlag,operatingSystem,datacenter,privateNetworkOnlyFlag,networkComponents.maxSpeed,sshKeys,operatingSystemReferenceCode,blockDevices[device,diskImage.capacity],blockDeviceTemplateGroup.globalIdentifier,postInstallScriptUri],policies[id,cooldown,name,scaleActions[id,type[id,keyName,name],amount,scaleType],triggers[id,type],triggers(SoftLayer_Scale_Policy_Trigger_OneTime)[date],triggers(SoftLayer_Scale_Policy_Trigger_Repeating)[schedule],triggers(SoftLayer_Scale_Policy_Trigger_ResourceUse)[watches[id,algorithm,metric,operator,period,value]]],loadBalancers[id,port,healthCheck[id,attributes[value,type.keyname],type[id,keyname,name]],virtualServer[id,port,virtualIpAddress.ipAddress.ipAddress,virtualIpAddress.id,serviceGroups.routingType.name]],virtualGuestMemberCount]

这里有一个使用python的例子:

"""
Get the scale group details (configuration).

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Group
http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Group/getObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Group

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

import SoftLayer
import json

USERNAME = 'set me'
API_KEY = 'set me'

scaleGroupId = 595465

# Create a SoftLayer API client object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
scaleGroupService = client['SoftLayer_Scale_Group']

objectMask = "mask[id, name, status[name, keyName], regionalGroup[id, name, description], suspendedFlag, terminationPolicy, cooldown, regionalGroupId, minimumMemberCount, maximumMemberCount, balancedTerminationFlag, networkVlans[ id, networkVlan[ id, name, vlanNumber, networkSpace, primaryRouter[id,hostname,datacenter[name,longName]],localDiskStorageCapabilityFlag,sanStorageCapabilityFlag]],virtualGuestMemberTemplate[hostname,domain,fullyQualifiedDomainName,startCpus,maxMemory,hourlyBillingFlag,localDiskFlag,operatingSystem,datacenter,privateNetworkOnlyFlag,networkComponents.maxSpeed,sshKeys,operatingSystemReferenceCode,blockDevices[device,diskImage.capacity],blockDeviceTemplateGroup.globalIdentifier,postInstallScriptUri],policies[id,cooldown,name,scaleActions[id,type[id,keyName,name],amount,scaleType],triggers[id,type],triggers(SoftLayer_Scale_Policy_Trigger_OneTime)[date],triggers(SoftLayer_Scale_Policy_Trigger_Repeating)[schedule],triggers(SoftLayer_Scale_Policy_Trigger_ResourceUse)[watches[id,algorithm,metric,operator,period,value]]],loadBalancers[id,port,healthCheck[id,attributes[value,type.keyname],type[id,keyname,name]],virtualServer[id,port,virtualIpAddress.ipAddress.ipAddress,virtualIpAddress.id,serviceGroups.routingType.name]],virtualGuestMemberCount]"

try:
    scaleGroup = scaleGroupService.getObject(id=scaleGroupId, mask=objectMask)
    config = {}
    config['groupDetails'] = {}
    config['groupDetails']['groupName'] = scaleGroup['name']
    config['groupDetails']['region'] = scaleGroup['regionalGroup']['name']
    config['groupDetails']['datacenter'] = scaleGroup['regionalGroup']['name']
    config['groupDetails']['terminationPolicy'] = scaleGroup['terminationPolicy']['name']
    config['groupSettings'] = {}
    config['groupSettings']['minimumMemberCount'] = scaleGroup['minimumMemberCount']
    config['groupSettings']['maximumMemberCount'] = scaleGroup['maximumMemberCount']
    config['groupSettings']['cooldown'] = str(scaleGroup['cooldown'] / 60) + " Minutes"
    config['memberDetails'] = {}
    config['memberDetails']['hostname'] = scaleGroup['virtualGuestMemberTemplate']['hostname']
    config['memberDetails']['domain'] = scaleGroup['virtualGuestMemberTemplate']['domain']
    config['computingInstance'] = {}
    config['computingInstance']['cores'] = str(scaleGroup['virtualGuestMemberTemplate']['startCpus']) + "x 2.0 GHz Core"
    config['computingInstance']['ram'] = str(scaleGroup['virtualGuestMemberTemplate']['maxMemory'] / 1024) + "GB"
    if 'networkComponents' in scaleGroup['virtualGuestMemberTemplate']:
        config['computingInstance']['speed'] = scaleGroup['virtualGuestMemberTemplate']['networkComponents'][0]['maxSpeed']
    else:
        config['computingInstance']['speed'] = "Default"
    if 'sshKeys' in scaleGroup['virtualGuestMemberTemplate']:
        config['computingInstance']['sshKeys'] = scaleGroup['virtualGuestMemberTemplate']['sshKeys']
    else:
        config['computingInstance']['sshKeys'] = 'None'
    config['storage'] = {}
    if scaleGroup['virtualGuestMemberTemplate']['localDiskFlag']:
        config['storage']['selectedStorage'] = 'Local Storage'
    else:
        config['storage']['selectedStorage'] = 'SAN Storage'
    config['operatingSystem'] = {}
    config['operatingSystem']['selectedOperatingSystem'] = scaleGroup['virtualGuestMemberTemplate']['operatingSystemReferenceCode']
    config['postInstallScript'] = {}
    config['postInstallScript']['url'] = scaleGroup['virtualGuestMemberTemplate']['postInstallScriptUri']
    config['policies'] = scaleGroup['policies']
    print(json.dumps(config, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get the scale group details. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))

但是如果你试图复制与门户网站相同的信息,你真的会很开心:)。

关于无法通过SoftLayer_Scale_Group服务获取信息的操作系统,您需要使用SoftLayer_Virtual_Guest :: getCreateObjectOptions方法。如果您看到方法的结果,您将看到:

{
            "itemPrice": {
                "hourlyRecurringFee": "0",
                "recurringFee": "0",
                "item": {
                    "description": "CentOS 6.x - Minimal Install (64 bit)"
                }
            },
            "template": {
                "id": null,
                "operatingSystemReferenceCode": "CENTOS_6_64"
            }
        }

正如您所看到的,结果包含&#34; operatingSystemReferenceCode&#34;和你想要的描述,所以只需要查找与&#34; operatingSystemReferenceCode&#34;匹配的记录。使用SoftLayer_Scale_Group :: getObject方法获得的值。

关于网络私有或公共,这里你只能有这些场景: 1.-公共和私人已经确定。 2.-只设置私人。

确定你必须检查&#34; privateNetworkOnlyFlag&#34;属性: 1.-如果属性为真,则网络是私有的 2.-如果尚未设置属性(默认值为false),则网络是公共和私有的。

为了获得与门户网站相同的描述,您需要使用SoftLayer_Virtual_Guest :: getCreateObjectOptions方法,这是您得到的结果:

"networkComponents": [
        {
            "itemPrice": {
                "hourlyRecurringFee": "0",
                "recurringFee": "0",
                "item": {
                    "description": "10 Mbps Public & Private Network Uplinks"
                }
            },
            "template": {
                "id": null,
                "networkComponents": [
                    {
                        "maxSpeed": 10
                    }
                ],
                "privateNetworkOnlyFlag": false
            }
        }

正如您所看到的,这个想法与操作系统相同。

并且考虑数据中心&#34; First Available&#34;,我想当你调用SoftLayer_Scale_Group :: getObject时我猜想virtualGuestMemberTemplate.datacenter属性为空或不存在,如果你看到你可以显示价值为&#34; First Available&#34;。

此致

答案 1 :(得分:0)

这是获取网络标志的测试代码。 该标志返回“true”,但Portal表示“公共和私人网络”。

private void getPrivateNetwork() {

    Group.Service groupSrv = Group.service(client, 1046365L);
    groupSrv.withMask().virtualGuestMemberTemplate().privateNetworkOnlyFlag();

    Group result = groupSrv.getObject();
    System.out.println(
            "private Network flag : " + result.getVirtualGuestMemberTemplate().getPrivateNetworkOnlyFlag());

}