SL ReloadOS API查询 [英] SL ReloadOS API inquiry

查看:84
本文介绍了SL ReloadOS API查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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()?

我可以使用不带"hardware.getID()"的此API来为BareMetal重新加载OS吗? com.softlayer.api.service.hardware.Server.service(客户端, hardware.getId()) 包含ID后,就会产生语法错误.

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

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

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

如您所见,设置"id"是必填参数,否则它将无法正常工作.

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

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

This is my suggestion, you ca change the code of the "com.softlayer.api.service.hardware.Server" 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());
    }

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

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

}

这篇关于SL ReloadOS API查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆