Search in sources :

Example 41 with User

use of org.ovirt.engine.sdk4.types.User in project ovirt-engine-sdk-java by oVirt.

the class AddFloatingDisk 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 disks service:
    DisksService disksService = connection.systemService().disksService();
    // Add the disk. Note that the size of the disk, the `provisionedSize` attribute, is specified in bytes,
    // so to create a disk of 10 GiB the value should be 10 * 2^30.
    Disk disk = disksService.add().disk(disk().name("mydisk").description("My disk").format(DiskFormat.COW).provisionedSize(BigInteger.valueOf(10).multiply(BigInteger.valueOf(2).pow(30))).storageDomains(storageDomain().name("mydata"))).send().disk();
    // Wait till the disk is completely created:
    DiskService diskService = disksService.diskService(disk.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        disk = diskService.get().send().disk();
        if (disk.status() == DiskStatus.OK) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : DisksService(org.ovirt.engine.sdk4.services.DisksService) Connection(org.ovirt.engine.sdk4.Connection) Disk(org.ovirt.engine.sdk4.types.Disk) DiskService(org.ovirt.engine.sdk4.services.DiskService)

Example 42 with User

use of org.ovirt.engine.sdk4.types.User in project ovirt-engine-sdk-java by oVirt.

the class AssignTagToVm 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=myvm0").send().vms().get(0);
    // Find the service that manages the vm:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the tags of the vm:
    AssignedTagsService assignedTagsService = vmService.tagsService();
    // Assign tag to virtual machine:
    assignedTagsService.add().tag(tag().name("mytag")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) AssignedTagsService(org.ovirt.engine.sdk4.services.AssignedTagsService)

Example 43 with User

use of org.ovirt.engine.sdk4.types.User in project ovirt-engine-sdk-java by oVirt.

the class AttachNfsIsoStorageDomain 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();
    // Locate the service that manages the storage domains, and use it to search for the storage domain:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    StorageDomain sd = sdsService.list().search("name=myiso").send().storageDomains().get(0);
    // Locate the service that manages the data centers and use it to search for the data center:
    DataCentersService dcsService = connection.systemService().dataCentersService();
    DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
    // Locate the service that manages the data center where we want to attach the storage domain:
    DataCenterService dcService = dcsService.dataCenterService(dc.id());
    // Locate the service that manages the storage domains that are attached to the data center:
    AttachedStorageDomainsService attachedSdsService = dcService.storageDomainsService();
    // Use the "add" method of the service that manages the attached storage domains to attach it:
    attachedSdsService.add().storageDomain(storageDomain().id(sd.id())).send();
    // Wait till the storage domain is active:
    AttachedStorageDomainService attachedSdService = attachedSdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = attachedSdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.ACTIVE) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : AttachedStorageDomainsService(org.ovirt.engine.sdk4.services.AttachedStorageDomainsService) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) DataCentersService(org.ovirt.engine.sdk4.services.DataCentersService) DataCenter(org.ovirt.engine.sdk4.types.DataCenter) AttachedStorageDomainService(org.ovirt.engine.sdk4.services.AttachedStorageDomainService) Connection(org.ovirt.engine.sdk4.Connection) DataCenterService(org.ovirt.engine.sdk4.services.DataCenterService) AttachedStorageDomainsService(org.ovirt.engine.sdk4.services.AttachedStorageDomainsService)

Example 44 with User

use of org.ovirt.engine.sdk4.types.User in project ovirt-engine-sdk-java by oVirt.

the class FollowVmLinks 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 service that manages virtual machines:
    VmsService vmsService = connection.systemService().vmsService();
    // Find the virtual machine:
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // When the server returns a virtual machine it will return links to related objects, like the cluster,
    // template and permissions something like this:
    // 
    // <link href="/api/vms/123/permissions" rel="permissions"/>
    // ...
    // <cluster id="123" href="/api/clusters/123"/>
    // <template id="456" href="/api/templates/456"/>
    // 
    // The SDK provides a "followLink" method that can be used to retrieve the complete content of these related
    // objects.
    Cluster cluster = connection.followLink(vm.cluster());
    Template template = connection.followLink(vm.template());
    List<Permission> permissions = connection.followLink(vm.permissions());
    // Now we can use the details of the cluster, template and permissions:
    System.out.printf("cluster: %s\n", cluster.name());
    System.out.printf("template: %s\n", template.name());
    for (Permission permission : permissions) {
        System.out.printf("role: %s\n", permission.role().id());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) Permission(org.ovirt.engine.sdk4.types.Permission) Cluster(org.ovirt.engine.sdk4.types.Cluster) VmsService(org.ovirt.engine.sdk4.services.VmsService) Template(org.ovirt.engine.sdk4.types.Template)

Example 45 with User

use of org.ovirt.engine.sdk4.types.User in project ovirt-engine-sdk-java by oVirt.

the class ExportVm 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 root of the services tree:
    SystemService systemService = connection.systemService();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Export the virtual machine. Note that the 'exclusive' parameter is optional, and only required if you want
    // to overwrite a virtual machine that has already been exported before.
    VmService vmService = vmsService.vmService(vm.id());
    vmService.export().exclusive(true).discardSnapshots(true).storageDomain(storageDomain().name("myexport")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : SystemService(org.ovirt.engine.sdk4.services.SystemService) Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)63 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 VmService (org.ovirt.engine.sdk4.services.VmService)18 SystemService (org.ovirt.engine.sdk4.services.SystemService)13 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 HostsService (org.ovirt.engine.sdk4.services.HostsService)6 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)6 Host (org.ovirt.engine.sdk4.types.Host)6 DataCentersService (org.ovirt.engine.sdk4.services.DataCentersService)5 HostService (org.ovirt.engine.sdk4.services.HostService)5 Disk (org.ovirt.engine.sdk4.types.Disk)5 ClustersService (org.ovirt.engine.sdk4.services.ClustersService)4 Cluster (org.ovirt.engine.sdk4.types.Cluster)4 ArrayList (java.util.ArrayList)3 AffinityLabelsService (org.ovirt.engine.sdk4.services.AffinityLabelsService)3 AssignedTagsService (org.ovirt.engine.sdk4.services.AssignedTagsService)3 DataCenterService (org.ovirt.engine.sdk4.services.DataCenterService)3 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)3