Softlayer-已打开电源的服务器列表

时间:2019-03-07 15:59:44

标签: java service hardware ibm-cloud-infrastructure

以下Java代码列出了特定SL帐户在softlayer中的所有裸机服务器,以及为已打开电源的服务器(例如powerState ='on'。)过滤器。

    public void listServers(Account.Service service, ApiClient client) throws Exception {

    service.withMask().hardware().fullyQualifiedDomainName().primaryIpAddress();
    service.withMask().hardware().hardwareStatus();
    service.withMask().hardware().id();

    Account account = service.getObject();

    //
    //  list of softlayer servers for the client account
    //
    for (Hardware hardware : account.getHardware()) {
        String hostname = hardware.getFullyQualifiedDomainName();

        String hardwareStatus = (hardware.getHardwareStatus() == null) ? null : hardware.getHardwareStatus().getStatus();
        Long serverId = hardware.getId();
        String powerState = null;

        if (serverId != null) {
            Hardware.Service hardwareService = Hardware.service(client, serverId);
            hardwareService.setMask("mask[serverPowerState");
            try {
                powerState = hardwareService.getServerPowerState();
            } catch (Exception ex) {
                System.out.println("Error, cannot get powerState, hostname=" + hostname + ", msg=" + ex.getMessage());
            }
        }
        System.out.println("Hostname=" + hostname + ", hwStatus=" + hardwareStatus + ", powerState=" + powerState);
    }
}

代码似乎可以正常工作,但是对于至少一台服务器而言,它在对hardwareService.getServerPowerState()的调用上失败了

“无法建立IPMI v2 / RMCP +会话”。

有什么想法为什么会失败?

0 个答案:

没有答案