如何使用Java客户端在Softlayer中获取公共映像

时间:2016-08-05 13:00:04

标签: ibm-cloud-infrastructure

在为Auto Scale添加公共图像选项时,我使用了下面的API,但它不返回公共图像模板。你能检查一下我使用过正确的API吗?私有映像可以与privateBlockDeviceTemplateGroups()一起使用。

Account.Service service = Account.service(client);
service.withMask().blockDeviceTemplateGroups();
Account account = service.getObject();

for (com.softlayer.api.service.virtual.guest.block.device.template.Group group : account.getBlockDeviceTemplateGroups()){   
System.out.println("group name : " + group.getName() ); }

AutoScale Public images

1 个答案:

答案 0 :(得分:0)

为了检索公共图像模板,您可以使用下一个方法:

  

SoftLayer_Virtual_Guest_Block_Device_Template_Group :: getPublicImages

您可以通过以下方式使用REST请求来使用此方法:

https://$username:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages.json

而且,这将使用java客户端。

/**
* This method gets all public image templates that the user is allowed to see.
*
* Important manual pages:
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group
*
* @license <http://sldn.softlayer.com/wiki/index.php/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
package SoftLayer_Java_Scripts.Examples;

import com.softlayer.api.*;
import com.softlayer.api.service.virtual.guest.block.device.template.Group;

import java.util.List;
import com.google.gson.Gson;

public class GetPublicImages
{
  public static void main( String[] args )
  {
    String user = "set me";
    String apiKey = "set me";

    ApiClient client = new RestApiClient().withCredentials(user, apiKey);
    Group.Service service = Group.service(client);

    try
    {
      List<Group> publicImages = service.getPublicImages();
      Gson gson = new Gson();
      for(Group image : publicImages) {
        System.out.println(gson.toJson(image));
      }
    }
    catch(Exception e)
    {
      System.out.println("Script failed, review the next message for further details: " + e); 
    }
  }
}

以下链接提供了更多信息: http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages

http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group