use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class ListVmDisks method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "vms" service:
VmsService vmsService = connection.systemService().vmsService();
// Find the virtual machine:
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Locate the service that manages the virtual machine:
VmService vmService = vmsService.vmService(vm.id());
// Locate the service that manages the disk attachments of the virtual machine:
DiskAttachmentsService diskAttachmentsService = vmService.diskAttachmentsService();
// Retrieve the list of disks attachments, and print the disk details. Note that each attachment contains a link
// to the corresponding disk, but not the actual disk data. In order to retrieve the actual disk data we use the
// `follow_link` method.
List<DiskAttachment> diskAttachments = diskAttachmentsService.list().send().attachments();
for (DiskAttachment diskAttachment : diskAttachments) {
Disk disk = connection.followLink(diskAttachment.disk());
System.out.printf("name: %s\n", disk.name());
System.out.printf("id: %s\n", disk.id());
System.out.printf("status: %s\n", disk.status());
System.out.printf("provisioned_size: %s\n", disk.provisionedSize());
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class AddLunDiskToVm method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine/ovirt-engine/api").user("admin@internal").password("123456").trustStoreFile("truststore.jks").build();
// Locate the virtual machines service and use it to find the virtual machine:
VmsService vmsService = connection.systemService().vmsService();
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Locate the service that manages the disk attachments of the virtual machine:
DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService();
// Use the "add" method of the disk attachments service to add the LUN disk.
diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("myiscsidisk").lunStorage(hostStorage().type(StorageType.ISCSI).logicalUnits(logicalUnit().address("192.168.200.3").port(3260).target("iqn.2014-07.org.ovirt:storage").id("36001405e793bf9c57a840f58c9a8a220").username("username").password("password")))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class ListVms method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "vms" service:
VmsService vmsService = connection.systemService().vmsService();
// Use the "list" method of the "vms" service to list all the virtual machines of the system:
List<Vm> vms = vmsService.list().send().vms();
// Print the virtual machine names and identifiers:
for (Vm vm : vms) {
System.out.printf("%s: %s\n", vm.name(), vm.id());
}
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class RemoveVm method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Find the service that manages VMs:
VmsService vmsService = connection.systemService().vmsService();
// Find the VM:
Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
// Note that the "vm" variable that we assigned above contains only the data of the VM, it doesn't have any
// method like "remove". Methods are defined in the services. So now that we have the description of the VM
// we can find the service that manages it, calling the locator method "vmService" defined in the "vms"
// service. This locator method receives as parameter the identifier of the VM and returns a reference to the
// service that manages that VM.
VmService vmService = vmsService.vmService(vm.id());
// Now that we have the reference to the service that manages the VM we can use it to remove the VM. Note that
// this method doesn't need any parameter, as the identifier of the VM is already known by the service that we
// located in the previous step.
vmService.remove().send();
// Close the connection to the server:
connection.close();
}
use of org.ovirt.engine.sdk4.services.VmsService in project ovirt-engine-sdk-java by oVirt.
the class SearchVms method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
// Get the reference to the "vms" service:
VmsService vmsService = connection.systemService().vmsService();
// Use the "list" method of the "vms" service to search the virtual machines that match a search query:
List<Vm> vms = vmsService.list().search("name=MYVM").caseSensitive(false).send().vms();
// Print the virtual machine names and identifiers:
for (Vm vm : vms) {
System.out.printf("%s: %s", vm.name(), vm.id());
}
// Close the connection to the server:
connection.close();
}
Aggregations