如何使用slcli或sl api更新Softlayer中Windows虚拟机的“管理员”用户密码?

时间:2017-03-01 09:02:07

标签: ibm-cloud-infrastructure

我创建了一个Windows虚拟机,后来又更改了管理员密码。有没有办法更新使用Softlayer命令行或Softlayer API

在UI中显示的密码

1 个答案:

答案 0 :(得分:0)

是的,可以使用Softlayer的Python客户端看到这段代码:

"""
Edit a password for a device.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Software_Component_Password
http://sldn.softlayer.com/reference/services/SoftLayer_Software_Component_Password/editObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Software_Component_Password/

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

import SoftLayer
import json

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

# The software component password id which contains the password.
passwordId = 8409127

username = "newUserEdit"
password = "newPassEdit"

# optional field
notes = "my optional note"

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
passwordService = client['SoftLayer_Software_Component_Password']

# Build a SoftLayer_Software_Component_Password object
templatePass = {
    "username": username,
    "password": password,
    "notes": notes,
}

try:
    result = passwordService.editObject(templatePass, id=passwordId)
    print(json.dumps(result, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to edit the password. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    exit(1)

您只需要知道要编辑的软件组件ID,此代码可以帮助您获取裸机服务器的软件组件,例如:

"""
Get the passwords for a server.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getSoftwareComponents

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

import SoftLayer
import json

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

serverId = 179996

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
serverService = client['SoftLayer_Hardware_Server']

objectMask = 'mask[passwords,softwareLicense]'

try:
    components = serverService.getSoftwareComponents(id=serverId, mask=objectMask)
    print(json.dumps(components, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get the passwords faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    exit(1)

但是,当您更改密码时,使用API​​或Softlayer的控制门户中间只保留在Softlayer数据库中的密码值,而不是机器的密码,如果您想更改机器上的密码,需要登录到机器并手动更改。

此致