简体   繁体   English

Softlayer API:如何获取操作系统价格表?

[英]Softlayer API: How to get OS price list?

I'm develop an project to auto deploy infrastructure (vm instance and others) using terraform. 我正在开发一个项目,以使用terraform自动部署基础架构(vm实例和其他实例)。

So, i need to find "os_reference_code" for Terraform. 因此,我需要为Terraform查找“ os_reference_code”。

Ideally i want to show os list just as same as portal site and it could be able to be used for deploying in terraform. 理想情况下,我想显示与门户网站一样的OS列表,并且可以将其用于terraform部署。 I found another thread could get exactly the list, but i does not found "os code" in getItemPrices(). 我发现另一个线程可以确切地获得列表,但是我在getItemPrices()中找不到“操作系统代码”。

Following is my try to get os code list from flavor: 以下是我尝试从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)
  1. Is "operatingSystemReferenceCode" could be used for "os_reference_code" in Terrafrom, or how to get it? 在Terrafrom中,“ operatingSystemReferenceCode”是否可以用于“ os_reference_code”,或者如何获取?

  2. The os list from flavor is different from those at portal site. 风味的操作系统列表与门户网站上的列表不同。 Is there an way to get os list like portal site and then deploy that os in terraform? 有没有办法获得像门户网站这样的操作系统列表,然后在Terraform中部署该操作系统?

  3. How to get the os price for different datacenter if they are not the same. 如果不同的数据中心不一样,如何获得操作系统价格。

  4. The price for os seems differ from vm cores, how to calculate the price? 操作系统的价格似乎与虚拟机内核不同,如何计算价格?

BR BR

  1. operatingSystemReferenceCode is the string needed to be passed into SoftLayer_Virtual_Guest::createObject as the operating system. operatingSystemReferenceCode是需要作为操作系统传递到SoftLayer_Virtual_Guest :: createObject的字符串。 I assume this is what terraform does, but I don't know enough to say for sure there. 我认为这就是terraform所做的事情,但是我对此不够了解。

  2. I'm not sure what is different. 我不确定有什么不同。 The OS list from createObjectOptions should have all the operating systems that are in the portal. createObjectOptions中的OS列表应具有门户中的所有操作系统。

  3. createObjectOptions only displays the "Default" price as far as I can tell. 据我所知,createObjectOptions仅显示“默认”价格。 To get location specific pricing, you need to use SoftLayer_Product_Package::getItems And then match the locationGroupId with the locationGroup you want to order in 要获取特定于位置的价格,您需要使用SoftLayer_Product_Package :: getItems ,然后将locationGroupId与要订购的locationGroup相匹配

  4. Again, use SoftLayer_Product_Package::getItems for this, but you will need to specify an object mask to select the price's capacityRestrictionMaximum and capacityRestrictionMiminum 同样,为此使用SoftLayer_Product_Package :: getItems ,但是您将需要指定对象掩码以选择价格的CapacityRestrictionMaximum和CapacityRestrictionMiminum

Package id=835 is the public virtual servers 程序包id = 835是公共虚拟服务器

slcli --format=json call-api SoftLayer_Product_Package getItems --id=835 --mask="mask[prices[capacityRestrictionMaximum]]"

You can not get the vm data by terraform because terraform just allow us to create, update and delete. 您无法通过terraform获取vm数据,因为terraform仅允许我们创建,更新和删除。

You can see the following documentation: 您可以查看以下文档:

https://github.com/softlayer/terraform-provider-softlayer/blob/master/docs/resources/softlayer_virtual_guest.md
  1. You can use the data of "operatingSystemReferenceCode" in "os_reference_code" terraform, but you have to change the variable "os_reference_code" to "image". 您可以在“ os_reference_code”地形中使用“ operatingSystemReferenceCode”的数据,但是必须将变量“ os_reference_code”更改为“ image”。

Here is an example of a template to create a VM by terraform. 这是通过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
}
  1. To get the OS list you have to use the following python code: 要获取操作系统列表,您必须使用以下python代码:

""" “”

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))

The "operatingSystemReferenceCode" that you got from the method getCreateObjectOptions() of the service “'Virtual_Guest” is the same that the "referenceCode" that you will find in this code example and you will get the OS price. 从服务“ Virtual_Guest”的方法getCreateObjectOptions()获得的“ operatingSystemReferenceCode”与在此代码示例中找到的“ referenceCode”相同,并获得操作系统价格。

eg The "operatingSystemReferenceCode" = 'WIN_2012-STD_64' 例如,“ operatingSystemReferenceCode” ='WIN_2012-STD_64'

You have to choose the OS depending of the "recurringFee" that you want. 您必须根据所需的“ recurringFee”选择操作系统。 The OS priceId will be “id”: 175797. 操作系统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"
            }
        }
    },

In the item prices there is not the LATEST versions of the OS because when you send the request the server will take the last version of this OS. 在商品价格中,没有该操作系统的最新版本,因为在发送请求时,服务器将采用该操作系统的最新版本。

eg UBUNTU_ LATEST, WIN_ LATEST, etc. 例如UBUNTU_ LATEST,WIN_ LATEST等。

  1. The OS prices depend of the Flavor that you will choose and the Flavor will change depending of the datacenter that will be choosing. 操作系统价格取决于您选择的Flavor,并且Flavor将根据要选择的数据中心而变化。

  2. Yes, the OS prices differ from vm cores, to get the prices you have to see in the result of the example code the following attributes: 是的,操作系统价格与虚拟机内核不同,要获得在示例代码结果中必须看到的以下属性,价格:

"capacityRestrictionMaximum": "32", “ capacityRestrictionMaximum”:“ 32”,

"capacityRestrictionMinimum": "17", “ capacityRestrictionMinimum”:“ 17”,

"capacityRestrictionType": "CORE", “ capacityRestrictionType”:“ CORE”,

In this case the OS price will be depending of the "capacityRestrictionMinimum” and "capacityRestrictionMaximum" of the CORE: 在这种情况下,操作系统价格将取决于CORE的“ capacityRestrictionMinimum”和“ capacityRestrictionMaximum”:

eg For this example the capacity is from 17 to 32 CORE and the OS price will be "recurringFee": "68" for the "referenceCode": "WIN_2012-STD_64" OS. 例如,对于此示例,容量为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.

相关问题 SoftLayer API:如何在Softlayer中获取NetScaler列表 - SoftLayer API : How to get NetScaler list in Softlayer softlayer API:获取操作系统版本列表? - softlayer API : Get OS version list? 如何在OS软件中搜索Softlayer API的服务器列表 - How do I search softlayer api for a list of servers by os version Softlayer API:如何获取对象存储的有效使用价格列表? - Softlayer API : How to get list of active usage prices of object storage? Softlayer API:如何获取每个数据中心的负载均衡器的带宽价格? - Softlayer API: How to get load balancer's bandwidth price for each datacenter? SoftLayer API:如何获取questionId列表并回答itemCategoryQuestionAnswer对象中的值 - SoftLayer API: How to get list of questionId and answers values in itemCategoryQuestionAnswer object SoftLayer API:如何获取从裸机创建的列表虚拟机 - SoftLayer API : How to get list VM created from baremetal 如何在softlayer中找到任何产品的价格细节以将其放入API - How to find out the price details of any offering in softlayer to put it into API 如何使用SoftLayer API资源管理器在Softlayer票证中获取对话内容 - How to get conversation contents in Softlayer tickets using SoftLayer API explorer softlayer api:复制OS图像跨IDC时如何获取状态(完成或处理中)? - softlayer api: How to get the status(finish or processing) when copy os image cross IDC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM