The following example outlines how to add sub-resources to a resource. In this example, a new disk with a size of '1073741824L', interface 'virtio' and format 'cow' are added to a virtual machine with the name 'test'.
Procedure
-
Declare an instance of the resource to which sub-resources are to be added:
VM vm = api.getVMs().get("test");
-
Create parameters to define the attributes of the resource:
Disk diskParam = new Disk(); diskParam.setProvisionedSize(1073741824L); diskParam.setInterface("virtio"); diskParam.setFormat("cow");
-
Add the sub-resource:
Disk disk = vm.getDisks().add(diskParam);