【问题标题】:Softlayer JAVA API sample to get all the configurations for “Hourly/Pre-set Configuration Bare Metal Servers”Softlayer JAVA API 示例,用于获取“每小时/预设配置裸机服务器”的所有配置
【发布时间】:2017-08-31 12:29:25
【问题描述】:

我正在尝试在 SoftLayer 上获取每小时裸机服务器的所有配置,但失败了。有 Java 示例吗?

我想要得到的是以下链接中的项目(数据中心名称、操作系统列表、CPU/GPU 列表等): https://gist.github.com/bmpotter/a0d9a386d8681bdab456/revisions

我可以通过以下代码获得操作系统参考代码列表,但这是我现在唯一可以获得的:)

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 ); 
}

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

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

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

如果有这方面的 Java 示例代码,那就太好了。

谢谢。

【问题讨论】:

    标签: java configuration ibm-cloud-infrastructure cloud-bare-metal


    【解决方案1】:

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

    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() );
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2019-07-01
      • 1970-01-01
      • 2013-12-08
      • 1970-01-01
      相关资源
      最近更新 更多