SL中的密码更新

时间:2016-04-25 12:57:11

标签: ibm-cloud-infrastructure

我正在尝试使用Softlayer中的Java API更新操作系统的密码/用户名。 但执行API后,密码不会被修改。这是我测试过的代码。 如果您有任何疑问,请评论我。感谢

import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Hardware;
import com.softlayer.api.service.hardware.Server;
import com.softlayer.api.service.software.Component;
import com.softlayer.api.service.software.Description;
import com.softlayer.api.service.virtual.Guest;


        public void deviceSoftcomp_BM_reName() throws Exception {

        Server.Service bmService = Server.service(client, 8045737l);

        bmService.withMask().softwareComponents().passwords().username().password();
        bmService.withMask().softwareComponents().softwareDescription().name();

        Hardware hd = bmService.getObject();

        List<Component> compList =  hd.getSoftwareComponents();

        for (Component comp : compList) {
            Description desc = comp.getSoftwareDescription();
            System.out.println(" software name : " + desc.getName());
            Long softId = comp.getId();
            System.out.println(" software id : " + softId);


            List<com.softlayer.api.service.software.component.Password> passList = comp.getPasswords();

            for (com.softlayer.api.service.software.component.Password password : passList) {

                System.out.println(" Username : " + password.getUsername());
                System.out.println(" Password : " + password.getPassword());

                if(softId == 9824519){
                    System.out.println("--- Rename OS name " );
                    password.setUsername("newUser");
                    password.setPassword("xfdgasdf123");
                }
            }

        }
    }

2 个答案:

答案 0 :(得分:1)

请尝试以下操作:SoftLayer_Software_Component_Password::editObject

以下是REST示例:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Software_Component_Password/[comp_pass_id]/editObject

Method: POST

Json Payload:
{
  "parameters": [
    {
      "password": "myPassEdited",
      "username": "myUserEdited"
    }
  ]
}

另外,要获取服务器软件组件的密码,请参阅:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Hardware/[server_id]/getSoftwareComponents?objectMask=mask[passwords]

Method: GET

答案 1 :(得分:0)

以下是更新设备软件的java示例代码。

     com.softlayer.api.service.software.component.Password passtemplate =
     new com.softlayer.api.service.software.component.Password();
     passtemplate.setUsername("newUserName");
     passtemplate.setPassword("123456abcDF");

    com.softlayer.api.service.software.component.Password.Service passService = com.softlayer.api.service.software.component.Password
            .service(client, 10000000l); // Client and password ID
    passService.editObject(passtemplate);