0

我正在尝试在门户网站上实现 reloadOS()。操作系统将使用相同的配置重新加载。如何将当前配置设置为 reloadOperatingSystem() 的参数?

我可以在没有“hardware.getID()”的情况下使用这个 API 来 ReloadOS for BareMetal 吗?com.softlayer.api.service.hardware.Server.service(client, hardware.getId() ) 一旦包含 ID,就会产生语法错误。

这是我测试过的代码。寻找您的反馈.. 谢谢。麦克风

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

1 回答 1

0

哦,伙计,恐怕这是个问题,请参阅https://github.com/softlayer/softlayer-java/issues/21

为了使用相同的配置重新加载服务器,您需要调用此方法: http ://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadCurrentOperatingSystemConfiguration

如您所见,这是设置“id”的必需参数,否则它将不起作用。

这是我的建议,你可以更改“com.softlayer.api.service.hardware.Server”类的代码

在类中寻找这个方法:

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

并在该方法下方添加此方法:

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

这样,您就可以在服务中设置 ID(创建服务后我找不到任何设置 ID 的方法,恐怕这种方法根本不会退出)。您可以使用此代码重新加载服务器

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

}
于 2016-01-29T14:27:34.437 回答