[英]Softlayer API: How to get OS price list?
我正在开发一个项目,以使用terraform自动部署基础架构(vm实例和其他实例)。
因此,我需要为Terraform查找“ os_reference_code”。
理想情况下,我想显示与门户网站一样的OS列表,并且可以将其用于terraform部署。 我发现另一个线程可以确切地获得列表,但是我在getItemPrices()中找不到“操作系统代码”。
以下是我尝试从flavor获取操作系统代码列表的方法:
import SoftLayer
client = SoftLayer.create_client_from_env(....)
flavors = client['Virtual_Guest'].getCreateObjectOptions()['operatingSystems']
os_list = []
for flavor in flavors:
tmp_dict = {
'description': flavor['itemPrice']['item']['description'],
'recurringFee': flavor['itemPrice']['recurringFee'],
'operatingSystemReferenceCode': flavor['template']['operatingSystemReferenceCode']
}
os_list.append(tmp_dict)
在Terrafrom中,“ operatingSystemReferenceCode”是否可以用于“ os_reference_code”,或者如何获取?
风味的操作系统列表与门户网站上的列表不同。 有没有办法获得像门户网站这样的操作系统列表,然后在Terraform中部署该操作系统?
如果不同的数据中心不一样,如何获得操作系统价格。
操作系统的价格似乎与虚拟机内核不同,如何计算价格?
BR
operatingSystemReferenceCode是需要作为操作系统传递到SoftLayer_Virtual_Guest :: createObject的字符串。 我认为这就是terraform所做的事情,但是我对此不够了解。
我不确定有什么不同。 createObjectOptions中的OS列表应具有门户中的所有操作系统。
据我所知,createObjectOptions仅显示“默认”价格。 要获取特定于位置的价格,您需要使用SoftLayer_Product_Package :: getItems ,然后将locationGroupId与要订购的locationGroup相匹配
同样,为此使用SoftLayer_Product_Package :: getItems ,但是您将需要指定对象掩码以选择价格的CapacityRestrictionMaximum和CapacityRestrictionMiminum
程序包id = 835是公共虚拟服务器
slcli --format=json call-api SoftLayer_Product_Package getItems --id=835 --mask="mask[prices[capacityRestrictionMaximum]]"
您无法通过terraform获取vm数据,因为terraform仅允许我们创建,更新和删除。
您可以查看以下文档:
https://github.com/softlayer/terraform-provider-softlayer/blob/master/docs/resources/softlayer_virtual_guest.md
这是通过terraform创建VM的模板示例。
provider "softlayer" {
username = "set me"
api_key = "set me"
}
# Create a new virtual guest
resource "softlayer_virtual_guest" "twc_terraform_sample" {
name = "my_server_1"
domain = "bar.example.com"
image = "UBUNTU_LATEST"
region = "ams01"
public_network_speed = 10
hourly_billing = true
private_network_only = false
cpu = 1
ram = 1024
disks = [25, 10, 20]
dedicated_acct_host_only = true
local_disk = false
}
“”
Get Item Prices
Retrieve a collection of SoftLayer_Product_Item_Prices that are valid for this package.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import json
USERNAME = set me'
API_KEY = 'set me'
object_mask = 'mask[item[id,softwareDescription]]'
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
result = client['SoftLayer_Product_Package'].getItemPrices(id=835, mask = object_mask)
print(json.dumps(result))
从服务“ Virtual_Guest”的方法getCreateObjectOptions()获得的“ operatingSystemReferenceCode”与在此代码示例中找到的“ referenceCode”相同,并获得操作系统价格。
例如,“ operatingSystemReferenceCode” ='WIN_2012-STD_64'
您必须根据所需的“ recurringFee”选择操作系统。 操作系统priceId将为“ id”:175797。
{
"id": 175797,
"recurringFee": "17",
"item": {
"id": 4233,
"softwareDescription": {
"controlPanel": 0,
"id": 1076,
"licenseTermValue": null,
"longDescription": "Microsoft Windows 2012 FULL STD 64 bit 2012 FULL STD x64",
"manufacturer": "Microsoft",
"name": "Windows 2012 FULL STD 64 bit",
"operatingSystem": 1,
"referenceCode": "WIN_2012-STD_64",
"upgradeSoftwareDescriptionId": null,
"upgradeSwDescId": null,
"version": "2012 FULL STD x64",
"virtualLicense": 0,
"virtualizationPlatform": 0,
"requiredUser": "Administrator"
}
}
},
在商品价格中,没有该操作系统的最新版本,因为在发送请求时,服务器将采用该操作系统的最新版本。
例如UBUNTU_ LATEST,WIN_ LATEST等。
操作系统价格取决于您选择的Flavor,并且Flavor将根据要选择的数据中心而变化。
是的,操作系统价格与虚拟机内核不同,要获得在示例代码结果中必须看到的以下属性,价格:
“ capacityRestrictionMaximum”:“ 32”,
“ capacityRestrictionMinimum”:“ 17”,
“ capacityRestrictionType”:“ CORE”,
在这种情况下,操作系统价格将取决于CORE的“ capacityRestrictionMinimum”和“ capacityRestrictionMaximum”:
例如,对于此示例,容量为17到32 CORE,对于“ referenceCode”:“ WIN_2012-STD_64” OS,操作系统价格为“ recurringFee”:“ 68”。
{
"currentPriceFlag": null,
"hourlyRecurringFee": ".098",
"id": 175801,
"itemId": 4233,
"laborFee": "0",
"locationGroupId": null,
"onSaleFlag": null,
"oneTimeFee": "0",
"quantity": null,
"recurringFee": "68",
"setupFee": "0",
"sort": 16,
"tierMinimumThreshold": null,
"capacityRestrictionMaximum": "32",
"capacityRestrictionMinimum": "17",
"capacityRestrictionType": "CORE",
"item": {
"id": 4233,
"softwareDescription": {
"controlPanel": 0,
"id": 1076,
"licenseTermValue": null,
"longDescription": "Microsoft Windows 2012 FULL STD 64 bit 2012 FULL STD x64",
"manufacturer": "Microsoft",
"name": "Windows 2012 FULL STD 64 bit",
"operatingSystem": 1,
"referenceCode": "WIN_2012-STD_64",
"upgradeSoftwareDescriptionId": null,
"upgradeSwDescId": null,
"version": "2012 FULL STD x64",
"virtualLicense": 0,
"virtualizationPlatform": 0,
"requiredUser": "Administrator"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.