简体   繁体   English

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

[英]How to update “Administrator” user password of a Windows Virtual Machine in Softlayer using slcli or sl api?

I created a windows virtual machine and later on changed the Administrator password. 我创建了Windows虚拟机,后来又更改了管理员密码。 Is there a way to update the password which shows in UI using Softlayer command line or Softlayer API's 有没有一种方法可以使用Softlayer命令行或Softlayer API来更新显示在UI中的密码

yep it is possible see this code using the Softlayer's Python client: 是的,可以使用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)

you only need to know the software component id to edit, this code can help you to get the software components for a bare metal server for example: 您只需要知道要编辑的软件组件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)

But keep in mid that using the API or the Softlayer's control portal when you change the password you only are changing the password value in the Softlayer's database and not the password for the machine, if you want change the passwrd on the machine you need to log on to the machine and change it manually. 但是要记住,当您更改密码时,使用API​​或Softlayer的控制门户网站只是在更改Softlayer数据库中的密码值,而不是机器的密码,如果要更改机器上的密码,则需要登录安装到机器上并手动进行更改。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM