如何使用来自 slcli 的特定 flex 图像重新加载 OS

How to reload OS using a specific flex image from slcli

How to reload system with flex image using softlayer REST API 指定如何使用 REST 进行重新加载。我如何通过 "slcli" 命令执行此操作?

使用 "slcli server reload --help" 不显示任何指定 imageTemplateId 的选项。它只启用 sshKeys 和安装脚本。

使用"slcli call-api..." 我不明白是否可以传递参数。真不像啊

slcli 无法做到这一点,我建议您使用 python 脚本来调用 API。

请参阅此关于重新加载的示例: https://gist.github.com/softlayer/2789898

这是一个从图像模板重新加载的示例,您只需确保图像模板 ID 对您的 Flex 图像是正确的:

"""
Reload servers from a list of IPs

This script looks for a server with a determinate IP address and reload it from an image template.

Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/findByIpAddress
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/reloadOperatingSystem

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

import SoftLayer
import json

ipsToReload = ['184.172.45.215', '1.1.1.1']

# Call the Softlayer_Account::getPrivateBlockDeviceTemplateGroups method.
# to get the images templates in the account.
imageTemplateId = 51236

USERNAME = 'set me'
API_KEY = 'set me'

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


failedServers = []
for ipToReload in ipsToReload:
    failedServer = {}
    failedServer['ip'] = ipToReload
    try:
        server = hardwareService.findByIpAddress(ipToReload)
        if server == '':
            failedServer['error'] = "Ip does not exist."
            failedServers.append(failedServer)
            continue
    except SoftLayer.SoftLayerAPIError as e:
        failedServer['error'] = e
        failedServers.append(failedServer)
        continue
    if 'activeTransaction' in server:
        failedServer['error'] = "There is an active transaction."
        failedServers.append(failedServer)
        continue

    config = {
        'imageTemplateId': imageTemplateId
    }

    try:
        reload = hardwareService.reloadOperatingSystem('FORCE', config, id=server['id'])
    except SoftLayer.SoftLayerAPIError as e:
        failedServer['error'] = e
        failedServers.append(failedServer)
        continue

print("The reload failed for these IPs:")
print(json.dumps(failedServers, sort_keys=True, indent=2, separators=(',', ': ')))

此致