我正在尝试找出一种方法,将现有的私有导出标准图像模板闪存到另一台服务器/实例。透过API,我找不到任何东西,我只找到查找私有图像的方法。 (通过python / custom module ansible执行此操作)
答案 0 :(得分:0)
您需要确保此处列出了图片模板:https://control.softlayer.com/devices/images
如果您可以看到imagetemplate以便可以使用重新加载方法,请参阅代码示例here,确保使用正确的图像模板ID
此代码可以帮助您列出图像模板:
"""
Get private image template
the script calls the SoftLayer_Account::getPrivateBlockDeviceTemplateGroups method
to list the private templates in the account and uses an object mask
to display more related information of the images templates
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getPrivateBlockDeviceTemplateGroups
http://sldn.softlayer.com/reference/dataypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']
# declaring an object mask to get more information about the images templates
objectMask = "mask[summary,note,status[name],storageRepository[datacenter],transaction[transactionGroup,transactionStatus],children[storageRepository[datacenter],blockDevices[diskImage[type]]]]"
try:
result = accountService.getPrivateBlockDeviceTemplateGroups(mask=objectMask)
print(result)
except SoftLayer.SoftLayerAPIError as e:
"""
# If there was an error returned from the SoftLayer API then bomb out with the
# error message.
"""
print("Unable to retrieve the list of image templates. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
此代码也可以帮助您创建图像模板,如果您无法在门户中看到它,请确保图像模板位于您的一个对象存储集群中。
"""
Create Image Template from external source
This script creates a transaction to import a disk image from an external source and create
a standard image template
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest_Block_Device_Template_Group/createFromExternalSource
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer username and apiKey
USERNAME = 'set me'
API_KEY = 'set me'
# Declare the group name to be applied to the imported template
name = 'imageTemplateTest'
# Declare the note to be applied to the imported template
note = 'This is for test Rcv'
'''
Declare referenceCode of the operating system software description for the imported VHD
available options: CENTOS_6_32, CENTOS_6_64, CENTOS_7_64, REDHAT_6_32, REDHAT_6_64, REDHAT_7_64,
UBUNTU_12_32, UBUNTU_12_64, UBUNTU_14_32, UBUNTU_14_64, WIN_2003-STD-SP2-5_32, WIN_2003-STD-SP2-5_64,
WIN_2008-STD-R2-SP1_64, WIN_2012-STD_64.
'''
operatingSystemReferenceCode = 'CENTOS_6_64'
'''
Define the parameters below, which refers to object storage where the image template is stored.
It will help to build the uri.
'''
# Declare the object storage account name
objectStorageAccountName = 'SLOS307608-10'
# Declare the cluster name where the image is stored
clusterName = 'dal05'
# Declare the container name where the image is stored
containerName = 'OS'
# Declare the file name of the image stored in the object storage, it should be .vhd or
fileName = 'testImage2.vhd-0.vhd'
"""
Creating an SoftLayer_Container_Virtual_Guest_block_Device_Template_Configuration Skeleton
which contains the information from external source
"""
configuration = {
'name': name,
'note': note,
'operatingSystemReferenceCode': operatingSystemReferenceCode,
'uri': 'swift://'+ objectStorageAccountName + '@' + clusterName + '/' + containerName + '/' + fileName
}
# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
groupService = client['SoftLayer_Virtual_Guest_Block_Device_Template_Group']
try:
result = groupService.createFromExternalSource(configuration)
print(result)
except SoftLayer.SoftLayerAPIError as e:
print("Unable to create the image template from external source. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
exit(1)