In the context of the SoftLayer API, SoftLayer Virtual Server Instances(VSIs) are represented by [[SoftLayer_Virtual_Guest (type)]] objects. The [[SoftLayer_Virtual_Guest]] service allows for interaction with a specific VSI and you are able to interact with all VSIs on your account through the [[SoftLayer_Account]] service. You will want to make sure you are on the latest version of the Softlayer PHP API SoapClient.
Ordering new VSIs is accomplished through [[SoftLayer_Virtual_Guest::createObject]]. First, a SoftLayer_Virtual_Guest template object is created that contains the details of the VSI. Every VSI template object will need, at minimum, the following properties defined:
$user = ‘set me’; $key = ‘set me’;
$virtualGuestClient = \SoftLayer\SoapClient::getClient(‘SoftLayer_Virtual_Guest’, null, $user, $key); $virtualGuestTemplate = new stdClass(); $virtualGuestTemplate->hostname = ’test1’; $virtualGuestTemplate->domain = ’example.com’; $virtualGuestTemplate->startCpus = 1; $virtualGuestTemplate->maxMemory = 1024; $virtualGuestTemplate->datacenter = new stdClass(); $virtualGuestTemplate->datacenter->name = ‘dal05’; $virtualGuestTemplate->hourlyBillingFlag = true; $virtualGuestTemplate->operatingSystemReferenceCode = ‘UBUNTU_LATEST’; $virtualGuestTemplate->localDiskFlag = false;
$result = $virtualGuestClient->createObject($virtualGuestTemplate);
print_r($result);
All options for VSI ordering can be retrieved with [[SoftLayer_Virtual_Guest::getCreateObjectOptions]].
The [[SoftLayer_Virtual_Guest::createObject|createObject()]] method incurs charges on the account so it is best to test VSI creation without causing an order to be placed with [[SoftLayer_Virtual_Guest::generateOrderTemplate]] to generate an order object. The [[SoftLayer_Container_Product_Order (type)]] returned by this method can be passed into [[SoftLayer_Product_Order::verifyOrder]] which informs of any issues that would prevent the order from processing.
A list of all Virtual Server Instances can be gathered from the [[SoftLayer_Account]] service with the [[SoftLayer_Account::getVirtualGuests]] method. This method returns an array of [[SoftLayer_Virtual_Guest (type)]] data type objects.
To get information about a specific VSI we can use [[SoftLayer_Virtual_Guest::getObject]] which returns a [[SoftLayer_Virtual_Guest (type)]] object. [[Object masks]] can be used to include data outside of [[SoftLayer_Virtual_Guest (type)|SoftLayer_Virtual_Guest’s]] local properties. Below is an example of using getObject on the SoftLayer_Virtual_Guest service with an object mask which provides the passwords for the operating system installed on the server.
Canceling VSIs can be done by pulling the ID from the SoftLayer_Account service. In this example we pull all virtual guests from the account and use the hostname to parse the specific guest we want to cancel. This should be used with caution as the hostname of a virtual guest is not unique.
SoftLayer_Virtual_Guest::deleteObject
Power cycling a VSI can be done two ways: