【问题标题】:To create VM of Softlayer by image通过镜像创建 Softlayer 的 VM
【发布时间】:2019-04-18 14:52:54
【问题描述】:

我想通过 Python api 按图像创建 VM。但是,我收到错误:

"SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_InvalidValue): 
Invalid value provided for 'blockDeviceTemplateGroup.globalIdentifier'.
A valid global identifier is required for a template."

我的代码如下:

import SoftLayer
from SoftLayer import VSManager
from pprint import pprint as pp

USERNAME = 'SLXXXXX'
API_KEY = 'bdf4f3124810a9e685a57xxxxxxxxxxxxxxxxxxxxxxx'

client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)

mgr = SoftLayer.VSManager(client)
vsi = mgr.create_instance( hourly=True,  image_id=2221859, hostname='p01', domain='esm.com',  cpus=1 , memory=1, datacenter='hkg02')
print vsi

如果我使用 Python 客户端,并运行以下命令

slcli vs create --billing=hourly --image=2221859 --hostname=p01 --domain=esm.com --cpu=1 --memory=1 --datacenter=hkg02

我可以创建虚拟机。

但是通过使用python程序,我无法创建它。

图片的细节是:

:....................:......................................:
:               name : value                                :
:....................:......................................:
:                 id : 2221859                              :
:  global_identifier : 59570b71-0a3e-4327-a89a-3dfc479ba997 :
:               name : tinyproxy                            :
:             status : Active                               :
: active_transaction : -                                    :
:            account : 792321                               :
:         visibility : Private                              :
:               type : System                               :
:               flex : False                                :
:               note : None                                 :
:            created : 2019-04-18T03:04:59-05:00            :
:         disk_space : 1.50G                                :
:        datacenters : hkg02                                :
:....................:......................................:

【问题讨论】:

    标签: python-3.x ibm-cloud-infrastructure


    【解决方案1】:

    您得到的错误是因为您在 python 程序请求中使用了图像 ID 而不是“globalIdentifier”。

    尝试发送“globalIdentifier”,如下例所示:

    vsi = mgr.create_instance( hourly=True, image_id='59570b71-0a3e-4327-a89a-3dfc479ba997', hostname='p01', domain='esm.com', cpus=1 , memory=1, datacenter='hkg02')
    

    【讨论】:

    • vsi = mgr.create_instance( hourly=True, image_id=59570b71-0a3e-4327-a89a-3dfc479ba997, hostname='p01', domain='esm.com', cpus=1 , memory= 1、datacenter='hkg02') ^ SyntaxError: invalid syntax
    • 请参考本页softlayer-python.readthedocs.io/en/latest/api/managers/vs.html。 image_id 应该是 int
    • 您必须将 globalIdentifier 放在引号中,例如:'59570b71-0a3e-4327-a89a-3dfc479ba997'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 2019-10-18
    • 2020-04-05
    • 1970-01-01
    相关资源
    最近更新 更多