简体   繁体   中英

SL ReloadOS API inquiry

I am trying to implement of reloadOS() on portal site. OS will be reloaded with the same configuration. How can I set the current configuration as a parameter for reloadOperatingSystem()?

Can I use this API without "hardware.getID()" to ReloadOS for BareMetal? com.softlayer.api.service.hardware.Server.service(client, hardware.getId() ) Once ID is included, it produces Syntax Error.

This is the code I've tested. Looking for your feed back.. Thank you. Mike

    if(deviceType.equals("Virtual Server")){
        for (Guest guest :  Account.service(client).getVirtualGuests()){
            if(guest.getFullyQualifiedDomainName().equals(deviceName))
                Guest.service(client, guest.getId()).reloadOperatingSystem("FORCE", config);
        }
    }else if(deviceType.equals("Bare Metal Server")){
            for (Hardware hardware :  Account.service(client).getHardware()){
                if(hardware.getFullyQualifiedDomainName().equals(deviceName)){
                        com.softlayer.api.service.hardware.Server.service(client).reloadOperatingSystem("FORCE", config) ;
                }
            }
    }   

Oh man, I am afraid that is an issue, see https://github.com/softlayer/softlayer-java/issues/21

In order to reload the server using the same configuration you need to call this method: http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadCurrentOperatingSystemConfiguration

As you can see it is a required parameter to set the “id” otherwise it will not work.

This is my suggestion, you ca change the code of the “com.softlayer.api.service.hardware.Server” class

Look for this method into the class:

public static Service service(ApiClient client) {
        return client.createService(Service.class, null);
    }

And bellow that method add this method:

public static Service service(ApiClient client, Long id) {
        return client.createService(Service.class, id == null ? null : id.toString());
    }

In that way way you will able to set the ID in the service (I could not find any method to set the ID after creating the service and I am afraid that such method does not exit at all). You can use this code to reload the server

import com.google.gson.Gson;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Account;
import com.softlayer.api.service.Hardware;
import com.softlayer.api.service.Hardware.Service;
import com.softlayer.api.service.container.hardware.server.Configuration;
import com.softlayer.api.service.hardware.Server;
//import com.softlayer.api.service.hardware.Server.Service;

public class ReloadBareMetal {

    public static void main(String[] args) {

        String user = "set me";
        String apikey = "set me";

        String deviceName =  "example.example.com";

        // Declare the API client
        ApiClient client = new RestApiClient().withCredentials(user, apikey);
        Account.Service accountService = Account.service(client);



        try {
            for (Hardware hardware :  Account.service(client).getHardware()){
                if(hardware.getFullyQualifiedDomainName().equals(deviceName)){
                    System.out.println("yepes");
                         Configuration conf = new Configuration();
                         //Hardware.Service hardwareService =  Hardware.service(client,hardware.getId());

                         Server.Service hardwareService =  Server.service(client, hardware.getId());

                         //hardwareService.
                         hardwareService.reloadCurrentOperatingSystemConfiguration("FORCE");
                }
            }

        } catch (Exception e) {
            System.out
                    .println("Unable to reload. " + e.getMessage());
        }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM