Search code examples
ibm-cloud-infrastructure

Detail information for Auto Scale in SL


I am implementing the detail information for auto scaling using Java API. How can I get a detailed information of member configuration. Please refer to the fields in red box in the attached picture. I could get a detailed information. For example, I could get the operation reference code, which is CENTOS_6_64, but how can I get the long type of description like CentOS 6.x - Minimal Install (64bit). member config group config


Solution

  • try using this object 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]
    

    here an example using 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))
    

    But if you try to copy the same information as the portal, you really will have fun :).

    Regarding the OS that information cannot be get via the SoftLayer_Scale_Group service, you need to use the SoftLayer_Virtual_Guest::getCreateObjectOptions method. If you see the result of the method you will see this:

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

    As you can see the result contains the "operatingSystemReferenceCode" and the description that you want to, so only need to look up the record which match with the "operatingSystemReferenceCode" value that you got using the SoftLayer_Scale_Group::getObject method.

    Regarding the network private or public, here you only can have the scenarios: 1.- public and private has been set. 2.- only private has been set.

    to determinate that you have to check the "privateNetworkOnlyFlag" property: 1.- if the property is true, the network is private 2.- if the property has not been set (the default value is false) so the network is public and private.

    In order to get the same description as the portal you need to use the SoftLayer_Virtual_Guest::getCreateObjectOptions method, this is the result that you got:

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

    As you can see the idea is the same as with the operating system.

    And regard the datacenter "First Available", I guess that when you call the SoftLayer_Scale_Group::getObject I guess that the virtualGuestMemberTemplate.datacenter property is empty or does not exist, if you see that you can display the value as "First Available".

    Regards