Softlayer API:如何获得OS价格表?

时间:2018-03-23 05:26:51

标签: api ibm-cloud ibm-cloud-infrastructure infrastructure

我正在开发一个项目,使用terraform自动部署基础架构(vm实例和其他)。

所以,我需要找到" os_reference_code"对于Terraform。

理想情况下,我想显示os列表与门户网站一样,它可以用于在terraform中部署。 我发现another thread可以得到完全列表,但我没有找到" os code"在getItemPrices()。

以下是我尝试从flavor中获取os代码列表:

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. " operatingSystemReferenceCode"可以用于" os_reference_code"在Terrafrom,或者如何获得它?

  2. 来自flavor的os列表与门户站点上的os列表不同。有没有办法让os列表像门户网站一样,然后在terraform中部署该操作系统?

  3. 如果不同的数据中心不同,如何获得os价格。

  4. os的价格似乎与vm核心不同,如何计算价格?

  5. BR

2 个答案:

答案 0 :(得分:0)

  1. operatingSystemReferenceCode是需要作为操作系统传递到SoftLayer_Virtual_Guest::createObject的字符串。我认为这就是terraform的作用,但我不知道在那里肯定会说。

  2. 我不确定有什么不同。 createObjectOptions中的OS列表应包含门户中的所有操作系统。

  3. createObjectOptions只显示“默认”价格,据我所知。要获取特定位置的定价,您需要使用SoftLayer_Product_Package::getItems然后将locationGroupId与您要订购的locationGroup匹配

  4. 同样,请使用SoftLayer_Product_Package::getItems,但您需要指定一个对象掩码来选择价格capacityRestrictionMaximum和capacityRestrictionMiminum

  5. Package id = 835是公共虚拟服务器

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

答案 1 :(得分:0)

您无法通过terraform获取vm数据,因为terraform只允许我们创建,更新和删除。

您可以看到以下文档:

https://github.com/softlayer/terraform-provider-softlayer/blob/master/docs/resources/softlayer_virtual_guest.md
  1. 您可以使用" operatingSystemReferenceCode"的数据。 in" os_reference_code" terraform,但你必须改变变量" os_reference_code"到"图像"。
  2. 以下是通过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. 要获取操作系统列表,您必须使用以下python代码:
    2. """

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

      &#34; operatingSystemReferenceCode&#34;你从方法getCreateObjectOptions()得到的 服务“&#39; Virtual_Guest”与&#34; referenceCode&#34;相同。您将在此代码示例中找到并获得操作系统价格。

      e.g。 &#34; operatingSystemReferenceCode&#34; ='WIN_2012-STD_64'

      您必须根据&#34; recurringFee&#34;选择操作系统。你要的那个。 OS 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"
                  }
              }
          },
      

      在商品价格中没有最新版本的操作系统,因为当您发送请求时,服务器将采用此操作系统的最新版本。

      e.g UBUNTU_ LATEST,WIN_ LATEST等等。

      1. 操作系统价格取决于您将选择的风味,风味将根据将要选择的数据中心而变化。

      2. 是的,操作系统价格与vm核心不同,要获得您必须在示例代码的结果中看到以下属性的价格:

      3. &#34; capacityRestrictionMaximum&#34;:&#34; 32&#34;,

        &#34; capacityRestrictionMinimum&#34;:&#34; 17&#34;,

        &#34; capacityRestrictionType&#34;:&#34; CORE&#34;,

        在这种情况下,操作系统价格将取决于&#34; capacityRestrictionMinimum“和&#34; capacityRestrictionMaximum&#34;核心:

        e.g。对于这个例子,容量从17到32 CORE,OS价格将是&#34; recurringFee&#34;:&#34; 68&#34;对于&#34; referenceCode&#34;:&#34; WIN_2012-STD_64&#34; OS。

        {
                "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"
                    }
                }