How to reload OS using a specific flex image from slcli

回眸只為那壹抹淺笑 提交于 2019-12-11 23:35:06

问题


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?

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

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


回答1:


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

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

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

Regards



来源:https://stackoverflow.com/questions/37735767/how-to-reload-os-using-a-specific-flex-image-from-slcli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!