计算SL中自动缩放的实例信息

时间:2016-07-07 10:37:22

标签: ibm-cloud-infrastructure

我正在寻找SoftLayer的java API来获取自动缩放页面中的计算实例信息。 (请参阅附图)

我已经尝试了以下代码,但我无法获取相关信息。 如何使用Java API获取Core,speed和network信息?

Group.Service groupSrv = Group.service(client, 1046365L);
groupSrv.withMask().virtualGuestMemberTemplate().hostname().domain();
groupSrv.withMask().virtualGuestMembers();
groupSrv.withMask().virtualGuestMemberTemplate().maxCpu().maxCpuUnits();
groupSrv.withMask().virtualGuestMemberTemplate().bandwidthAllocation();
groupSrv.withMask().virtualGuestMemberTemplate().maxMemory().sshKeys();
groupSrv.withMask().virtualGuestMemberTemplate().billingItem().itemPackage().name();
groupSrv.withMask().virtualGuestMemberTemplate().networkComponents().name();
groupSrv.withMask().virtualGuestMemberTemplate().operatingSystem().softwareDescription().name();

Group group = groupSrv.getObject();

System.out.println("host name : " + group.getVirtualGuestMemberTemplate().getHostname());
System.out.println("domain name  : " + group.getVirtualGuestMemberTemplate().getDomain());

System.out.println("getMaxCpu  : " + group.getVirtualGuestMemberTemplate().getMaxCpu());
System.out.println("getMaxCpuUnits  : " + group.getVirtualGuestMemberTemplate().getMaxCpuUnits());
System.out.println("getMaxMemory  : " + group.getVirtualGuestMemberTemplate().getMaxMemory());
System.out.println("getSshKeys  : " + group.getVirtualGuestMemberTemplate().getSshKeys());

enter image description here

1 个答案:

答案 0 :(得分:0)

此代码适用于我:

package com.softlayer.api.ScaleGroups;

import com.google.gson.Gson;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.scale.Group;

/**
 * This script retrieves information about Scale Group
 *
 * Important Manual Page:
 * 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>
 * @authon SoftLayer Technologies, Inc. <sldn@softlayer.com>
 * @version 0.2.2
 */
public class GetObject {
    /**
     * This is the constructor, is used to get Scale Group
     */
    public GetObject() {
        // Declare your SoftLayer username and apiKey
        String username = "set me";
        String apiKey = "set me";

        // Create client
        ApiClient client = new RestApiClient().withCredentials(username, apiKey);
        Group.Service groupService = Group.service(client, new Long(777589));

        // Defining mask
        groupService.withMask().virtualGuestMemberTemplate();
        groupService.withMask().virtualGuestMemberTemplate().networkComponents();
        groupService.withMask().networkVlans();

        Gson gson = new Gson();

        try {
            Group result = groupService.getObject();
            System.out.println(gson.toJson(result.getVirtualGuestMemberTemplate()));
            System.out.println("Hostname: " + result.getVirtualGuestMemberTemplate().getHostname());
            System.out.println("Domain: " + result.getVirtualGuestMemberTemplate().getDomain());
            System.out.println("Cores: " + result.getVirtualGuestMemberTemplate().getStartCpus());
            System.out.println("RAM: " + result.getVirtualGuestMemberTemplate().getMaxMemory());
            System.out.println("Speed: " + result.getVirtualGuestMemberTemplate().getNetworkComponents().get(0).getMaxSpeed());
            System.out.println("Networks: " + result.getVirtualGuestMemberTemplate().getPrivateNetworkOnlyFlag());

        } catch (Exception e) {
            System.out.println("Error: " + e);
        }
    }

    /**
     * This is the main method which makes use of GetObject  method.
     *
     * @param args
     * @return Nothing
     */
    public static void main(String[] args) {
        new GetObject();
    }


}

关于网络信息,我只是在脚本中检索“网络 - 网络&gt;&gt;公共/私人”

看看这一行:

  

result.getVirtualGuestMemberTemplate()。getPrivateNetworkOnlyFlag()

响应:

  • True表示仅限私人
  • 错误表示公共/私人

我希望它有所帮助。让我知道任何疑问或评论。

<强>参考文献: