I'm trying to get all the configurations for hourly bare metal servers on SoftLayer, but failed. Is there a Java sample for it?

What I want to get is the items like in the following link (DataCenter name, OS list, CPU/GPU list, etc): https://gist.github.com/bmpotter/a0d9a386d8681bdab456/revisions

I can get the OS reference code list with following codes, but this is the only one that I can get now :)

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

I cannot get DataCenter name list and other configurations (E.g. cpu count) with following codes:

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

There should be something wrong, but I don't know why.

It will be great if there is a Java Sample codes for this.

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

I recomend you to debug your code in order to know how you need to access the properties properly, I got some values for you:

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

    }