1

I'm develop an project to auto deploy infrastructure (vm instance and others) using terraform.

So, i need to find "os_reference_code" for Terraform.

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. I found another thread could get exactly the list, but i does not found "os code" in getItemPrices().

Following is my try to get os code list from 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?

  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?

  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

2 Answers2

1

You can not get the vm data by terraform because terraform just allow us to create, update and delete.

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".

Here is an example of a template to create a VM by terraform.

    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:

"""

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.

e.g. The "operatingSystemReferenceCode" = ‘WIN_2012-STD_64’

You have to choose the OS depending of the "recurringFee" that you want. The OS priceId will be “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.

e.g UBUNTU_ LATEST, WIN_ LATEST, etc.

  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.

  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",

"capacityRestrictionMinimum": "17",

"capacityRestrictionType": "CORE",

In this case the OS price will be depending of the "capacityRestrictionMinimum” and "capacityRestrictionMaximum" of the CORE:

e.g. 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.

{
        "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"
            }
        }
F.Ojeda
  • 718
  • 1
  • 4
  • 8
  • Thanks for reply, but i still have some question about the price, as i know, if item's price is differ from different datacenter, it would addressed the information at "locationGroupId" field, but it seems all null in item_price object, maybe it's all the same i thought. – YuZong Jiang Mar 28 '18 at 05:29
  • Also, for example "operatingSystemReferenceCode": "REDHAT_LATEST_64" in flavor does not exist in item_price object. And there is another [rest api](https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getVhdImportSoftwareDescriptions.json?objectMask=referenceCode) from terraform's doc that could get another list for os list. I still get a little confused about it.. – YuZong Jiang Mar 28 '18 at 05:33
  • I also found something strange that 'referenceCode': 'UBUNTU_14_64' in item_price but it could stand for 'Ubuntu 14.04-64 Minimal for VSI' or 'Ubuntu 14.04-64 LAMP for VSI' ? – YuZong Jiang Mar 28 '18 at 05:42
  • The prices of the flavor differ according to the datacenter, but the OS does not, that's why it comes out null in the attribute "locationGroupId" because the OS is the same for all the datacenter. – F.Ojeda Apr 03 '18 at 19:23
  • There is not possible to get data by terraform because it only allow us to create, update and delete, you can see the following documentation: https://github.com/softlayer/terraform-provider-softlayer/blob/master/docs/resources/softlayer_virtual_guest.md – F.Ojeda Apr 03 '18 at 19:40
  • The 'Ubuntu 14.04-64 Minimal" and 'Ubuntu 14.04-64 LAMP" are the technologies of Ubuntu, you can see the vm OS options in the following link: https://www.softlayer.com/Store/orderHourlyComputingInstance/1640,1644,2202 and to know more about this technologies you can see this documentation: https://help.ubuntu.com/lts/installation-guide/s390x/install.en.pdf?_ga=2.168727460.46326788.1522783869-251820255.1522783869 – F.Ojeda Apr 03 '18 at 19:45
0
  1. operatingSystemReferenceCode is the string needed to be passed into SoftLayer_Virtual_Guest::createObject as the operating system. I assume this is what terraform does, but I don't know enough to say for sure there.

  2. I'm not sure what is different. The OS list from createObjectOptions should have all the operating systems that are in the portal.

  3. createObjectOptions only displays the "Default" price as far as I can tell. 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

  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

Package id=835 is the public virtual servers

slcli --format=json call-api SoftLayer_Product_Package getItems --id=835 --mask="mask[prices[capacityRestrictionMaximum]]"
Chris Gallo
  • 191
  • 1
  • 4