如何使用 Java 客户端在 Softlayer 中获取 public 图像

How to get public Images in Softlayer using Java client

在为自动缩放添加 public 图像选项时,我在下面使用了 API,但 returns 没有 Public 图像模板。你能检查一下我使用了正确的 API 吗? Private Image 与 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() ); }

要检索 public 图像模板,您可以使用下一个方法:

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