如何使用 slcli 或 sl api 更新 Softlayer 中 Windows 虚拟机的 "Administrator" 用户密码?

How to update "Administrator" user password of a Windows Virtual Machine in Softlayer using slcli or sl api?

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

更新 UI 中显示的密码

是的,可以使用 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 数据库中的密码值,而不是机器的密码,如果您想要更改机器上的密码需要登录机器手动修改。

此致