是否可以使用Services API take or apply Softlayer OS image templates?
我打算使用python库来执行这两个操作。
答案 0 :(得分:1)
您可以使用此脚本拍摄操作系统图像模板:
"""
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 = 13925819
# 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.
Make sure the SoftLayer_Virtual_Guest_Block_Device is not SWAP.
"""
blockDevices = [
{
"id": 18116783,
"complexType": "SoftLayer_Virtual_Guest_Block_Device"
},
{
"id": 18116845,
"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))
您可以使用此脚本使用操作系统映像模板创建虚拟访客:
"""
Create Virtual Guest using an OS Template.
Important manual pages:
https://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from pprint import pprint as pp
USERNAME = 'set me'
API_KEY = 'set me'
templateId = 1348881
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
order = {
'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest',
'quantity': 1,
'virtualGuests': [
{'hostname': 'test-template', 'domain': 'example.com'}
],
'location': 168642, # San Jose 1
'packageId': 46, # CCI Package
'prices': [
{'id': 1640}, # 1 x 2.0 GHz Core
{'id': 1644}, # 1 GB RAM
{'id': 905}, # Reboot / Remote Console
{'id': 272}, # 10 Mbps Public & Private Networks
{'id':50231}, # 1000 GB Bandwidth
{'id': 21}, # 1 IP Address
{'id': 2202}, # 25 GB (SAN)
{'id': 1685}, # CentOS 5.x - Minimal Install (64 bit)
{'id': 55}, # Host Ping Monitoring
{'id': 57}, # Email and Ticket Notifications
{'id': 58}, # Automated Notification Response
{'id': 420}, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
{'id': 418}, # Nessus Vulnerability Assessment & Reporting
],
'imageTemplateId': templateId
}
try:
# Use verifyOrder to make sure your order is correct.
# Use placeOrder to make an order directly.
result = client['SoftLayer_Product_Order'].verifyOrder(order)
pp(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 verify order. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
更新
验证虚拟服务器是否可以通过操作系统重新加载过程:
"""
Verify that a virtual server can go through the operating system reload process.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/verifyReloadOperatingSystem
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Hardware_Server_Configuration
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 reload.
virtualGuestId = 15535983
# The image id used in the reloading process.
imageTemplateId = 1349311
"""
Build a skeleton SoftLayer_Container_Hardware_Server_Configuration object
containing image id you want to use.
"""
hardwareServerConfig = [
{
"imageTemplateId": imageTemplateId
}
]
# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
response = client['SoftLayer_Virtual_Guest'].verifyReloadOperatingSystem(hardwareServerConfig, 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 verify reload OS. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
重新加载操作系统配置:
"""
Reloads current operating system configuration.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/reloadOperatingSystem
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Hardware_Server_Configuration
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 reload.
virtualGuestId = 15535983
# The image id used in the reloading process.
imageTemplateId = 1349311
"""
Build a skeleton SoftLayer_Container_Hardware_Server_Configuration object
containing image id you want to use.
"""
hardwareServerConfig = [
{
"imageTemplateId": imageTemplateId
}
]
# To proceed with the reload without confirmation, simply pass in 'FORCE' as the token parameter
token = 'FORCE'
# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
response = client['SoftLayer_Virtual_Guest'].reloadOperatingSystem(token, hardwareServerConfig, 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 reload OS. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
此方法也可以为您提供帮助: SoftLayer_Virtual_Guest :: reloadCurrentOperatingSystemConfiguration
进一步阅读的链接: http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/verifyReloadOperatingSystem
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/reloadOperatingSystem