1

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!

Hengguo
  • 73
  • 5

1 Answers1

1

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

  • Your answer is very detailed and Really appreciate! I have one more question about softlayer rest api. After virtual server is created, I want to get the ID of this virtual server. At present I'm using 'https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests' to all virtual server information and then find the ID needed. I want to if there's a simple way to get the ID through the hostname of this virtual server or through other methods. Hope you can provide the answer. Thanks! – Hengguo Dec 14 '16 at 16:05
  • When you order a virtual guest using the method, that I posted, the result of the execution will return the ID of the newly created VSI, so you do not need to use the getVirtualGuests method. Also you may want to know how to know when the server has been provisioned I recomend you to see these posts http://sldn.softlayer.com/blog/phil/simplified-cci-creation http://sldn.softlayer.com/blog/phil/getting-started-ccis – Nelson Raul Cabero Mendoza Dec 14 '16 at 16:11
  • Also you could use objectFilters to get the VSI that you are looking for the request should be something like this: https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={"virtualGuests": {"hostname": {"operation": "myHostnameI want"}}} for more information about objectFilters see http://sldn.softlayer.com/article/object-filters – Nelson Raul Cabero Mendoza Dec 14 '16 at 16:15