Softlayer API: 如何使用指定的数据盘进行图像抓取?

Softlayer API: How to do image capture with specify certain data disk?

我有一个磁盘为 1,2,3,4 的虚拟机,我想做一些图像操作:

现在要创建图像模板,您可以在图像模板中指定您想要的块设备,您可以使用 API 和门户来执行此操作。

这是使用 API

的示例
"""
Create image template.

The script creates a standard image template, it makes
a call to the SoftLayer_Virtual_Guest::createArchiveTransaction method
sending the IDs of the disks in the request.
For more information please see below.

Important manual pages:
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/createArchiveTransaction
https://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device

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'

# The virtual guest ID you want to create a template
virtualGuestId = 4058502
# The name of the image template
groupName = 'my image name'
# An optional note for the image template
note = 'an optional note'

"""
Build a skeleton SoftLayer_Virtual_Guest_Block_Device object
containing the disks you want to the image.
In this case we are going take an image template of 2 disks
from the virtual machine.
"""
blockDevices = [
    {
        "id": 4667098,
        "complexType": "SoftLayer_Virtual_Guest_Block_Device"
    },
    {
        "id": 4667094,
        "complexType": "SoftLayer_Virtual_Guest_Block_Device"
    }
]

# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)

try:
    # Creating the transaction for the image template
    response = client['SoftLayer_Virtual_Guest'].createArchiveTransaction(groupName, blockDevices, note, id=virtualGuestId)
    print(response)
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 create the image template. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))

你只需要得到块设备ID(或磁盘),为此你可以调用这个方法:

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/getBlockDevices

块设备有一些规则:

  1. 只能捕获磁盘类型的块设备。
  2. 交换类型的块设备不能不包含在要捕获的块设备列表中。(这是磁盘号1)。
  3. 必须包含包含OS的块设备(这是磁盘编号0)。
  4. 映像中不能包含包含元数据的块设备。

当您使用此图像模板订购新设备时,您需要牢记这一点:

  1. 如果您使用 placeOrder 方法,您需要确保添加额外磁盘的价格。
  2. 如果您使用的是createObject方法,磁盘数量将从镜像模板中获取,因此不需要指定额外的磁盘。

您也可以在重新加载中使用图像模板,但重新加载只影响包含 OS 的磁盘。所以如果你有一台包含 3 个磁盘的 Vitrual 机器并执行重新加载,即使图像模板有 3 个磁盘,也只有包含 OS 的磁盘受到影响。

如果您的订单由于磁盘容量不足或其他问题而出现错误,在配置时会出现错误并且不会配置 VSI,可能会开票,一些 softlayer 员工会通知你关于那个。

此致