How to create virtual server using standard template softlayer using rest api?

517 Views Asked by At

I create one image template, and want to create a virtual server using this template. I can do this on WEB GUI. For rest api, I saw that operatingSystemReferenceCode is used to create virtual server. I think operatingSystemReferenceCode is different with image template.

I want to know which api is used when creating virtual server using image template and it's very nice of you to give an example. Thanks!

1

There are 1 best solutions below

3
On BEST ANSWER

Well the easy way is using the createObject method, in that method you can pass the image that you want to use for more information see:

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/createObject

you just need to configure this property in the request:

enter image description here

here a RESTful example:

POST https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/createObject Payload:

{ 
 "parameters":[ 
     { 
         "hostname": "host1", 
         "domain": "example.com", 
         "startCpus": 1, 
         "maxMemory": 1024, 
         "hourlyBillingFlag": true, 
         "localDiskFlag": true, 
         "datacenter": { 
            "name": "dal05" 
         } 
         "blockDeviceTemplateGroup": { 
            "globalIdentifier": "07beadaa-1e11-476e-a188-3f7795feb9fb" 
        }
     } 
 ] 
}

Likely you are wondering how to get the globalIdentifier of the tamplate you want to use, well there are two types of images templates: private and public.

The private templates (the ones that you created) can be fetched using this method:

http://sldn.softlayer.com/reference/services/SoftLayer_Account/getBlockDeviceTemplateGroups

In another hand the public templates can be fetched using this method:

http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages

I hope it helps you

Regards