如何使用slcli中的特定Flex映像重新加载OS [英] How to reload OS using a specific flex image from slcli

查看:97
本文介绍了如何使用slcli中的特定Flex映像重新加载OS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用flex image重新加载系统使用软层REST API 指定如何使用REST进行重新加载.如何通过"slcli"命令执行此操作?

How to reload system with flex image using softlayer REST API specifies how to do a reload using REST. How do I do it from the "slcli" command?

使用"slcli服务器重新加载--help"不会显示任何指定imageTemplateId的选项.它仅启用sshKeys和安装脚本.

Using "slcli server reload --help" doesn't show any option to specify the imageTemplateId. It only enables sshKeys and install scripts.

使用"slcli call-api ...",我不知道是否可以传递参数.真的看起来不像这样.

Using the "slcli call-api..." I don't understand if it's possible to pass parameters. It really doesn't look like it.

推荐答案

slcli无法做到这一点,我建议您使用python scrips来调用API.

The slcli is not able to do that, I recomend you to use python scrips to call the API.

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

see this example about reloads: https://gist.github.com/softlayer/2789898

在这里是一个从图像模板重新加载的示例,您只需要确保imagetemplate id对您的flex图像是正确的:

and here an example to reload from an image template, you just need to make sure that the imagetemplate id is the correct for your flex image:

"""
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=(',', ': ')))

致谢

这篇关于如何使用slcli中的特定Flex映像重新加载OS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆