Softlayer JAVA API 示例以获取“Hourly/Pre-set 配置裸机服务器”的所有配置

Softlayer JAVA API sample to get all the configurations for “Hourly/Pre-set Configuration Bare Metal Servers”

我正在尝试获取 SoftLayer 上按小时计费的裸机服务器的所有配置,但失败了。有 Java 样本吗?

我要获取的是如下link中的项目(数据中心名称、OS列表、CPU/GPU列表等): https://gist.github.com/bmpotter/a0d9a386d8681bdab456/revisions

我可以用下面的代码得到OS参考代码列表,但这是我现在唯一能得到的:)

Hardware.Service hardwareService = Hardware.service(client);
Configuration configuration = hardwareService.getCreateObjectOptions();

List<Option> options = configuration.getOperatingSystems();
for (Option option : options) {
    Hardware hardware = option.getTemplate();
    String osRefCode = hardware.getOperatingSystemReferenceCode();
    System.out.println("osRefCode : " + osRefCode ); 
}

我无法使用以下代码获取 DataCenter 名称列表和其他配置(例如 cpu 计数):

List<Option> options = configuration.getDatacenters();
for (Option option : options) {   
    Hardware hardware = option.getTemplate();
    String dcName = hardware.getDatacenterName();
    System.out.println("dcName : " + dcName );
}

应该是有问题,但不知道为什么。

如果有Java示例代码就好了。

谢谢。

我建议您调试代码以了解您需要如何正确访问属性,我为您提供了一些值:

List<Option> options2 = configuration.getDatacenters();
        for (Option option : options2) {   

            Hardware hardware = option.getTemplate();
            String dcName = hardware.getDatacenter().getName();

            System.out.println("dcName : " + dcName );
        }


        List<Option> options3 = configuration.getProcessors();
        for (Option option : options3) {  
            System.out.println("processors");
            System.out.println("item prices");
            System.out.println("hourly recurring fee" + option.getItemPrice().getHourlyRecurringFee());
            System.out.println("item");
            System.out.println("desciption" + option.getItemPrice().getItem().getDescription());
            Hardware hardware = option.getTemplate();
            System.out.println("Template");
            System.out.println("processorCoreAmount : " + hardware.getProcessorCoreAmount() );
            System.out.println("memoryCapacity : " + hardware.getMemoryCapacity() );
        }

    }