The WsDevClient class contains an example of the creation of a virtual machine:
... Vm testVm = new Vm(); testVm.setVmDomainType(VmDomainType.XEN_HVM); testVm.setName(testVmName); testVm.setRepositoryId(testRepoId); final Job vmCreateJob = api.vmCreate(testVm, testPoolId); System.out.println("create vm job id: " + vmCreateJob.getId()); testVmId = waitForJobComplete(api, vmCreateJob, Vm.class);
In this code, some basic attributes of the virtual machine are
set before it is created. In fact, there are a large number of
attributes specific to a virtual machine that can be set to
control how the virtual machine is configured. Here the most
basic attributes have been selected to create a virtual
machine using Xen hardware virtualization with its
configuration located on the repository defined in the
WsDevClient.properties
file.
The vmCreate method also requires the server pool ID to be provided so that the virtual machine is created within the correct server pool. In fact, the method sets the value for the ServerPoolId attribute of the VM object before calling the more generic create method:
@Override public Job vmCreate(final Vm vm, final Id<ServerPool> serverPoolId) throws WsException { vm.setServerPoolId(serverPoolId); return create(vm); }
The WsDevClient class goes on to demonstrate many other actions that can be performed on a virtual machine via the REST API including removing and restoring server pool association, basic modifications of attributes, assigning VNICs and killing a virtual machine. It is recommended that the reader explore these examples and how they relate to methods within the OvmWsRestClient class to understand how to expand any interactions with virtual machines through the REST API.