Search in sources :

Example 46 with User

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

the class ImportGlanceImage 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 root of the services tree:
    SystemService systemService = connection.systemService();
    // Find the Glance storage domain that is available for default in any oVirt installation:
    StorageDomainsService sdsService = systemService.storageDomainsService();
    StorageDomain sd = sdsService.list().search("name=ovirt-image-repository").send().storageDomains().get(0);
    // Find the servie that manages the Glance storage domain:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    // Find the service that manages the images available in that storage domain:
    ImagesService imagesService = sdService.imagesService();
    // The images service doesn't support search, so in roder to find an image we need to retrieve all of them and
    // do the filtering explicitly:
    List<Image> images = imagesService.list().send().images();
    Image image = null;
    for (Image i : images) {
        if (Objects.equals(i.name(), "CirrOS 0.3.4 for x86_64")) {
            image = i;
            break;
        }
    }
    // Find the service that manages the image that we found in the previous step:
    ImageService imageService = imagesService.imageService(image.id());
    // Import the image:
    imageService.import_().importAsTemplate(true).template(template().name("mytemplate")).cluster(cluster().name("mycluster")).storageDomain(storageDomain().name("mydata")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) Connection(org.ovirt.engine.sdk4.Connection) ImagesService(org.ovirt.engine.sdk4.services.ImagesService) Image(org.ovirt.engine.sdk4.types.Image) ImageService(org.ovirt.engine.sdk4.services.ImageService)

Example 47 with User

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

the class PinVm 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 tree of services:
    SystemService systemService = connection.systemService();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Update the placement policy of the virtual machine so that it is pinned to the host:
    VmService vmService = vmsService.vmService(vm.id());
    vmService.update().vm(vm().placementPolicy(vmPlacementPolicy().hosts(host().name("myhost")))).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)

Example 48 with User

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

the class RegisterVm 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("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the "StorageDomains" service:
    StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
    // Find the storage domain with unregistered VM:
    StorageDomain sd = storageDomainsService.list().search("name=mysd").send().storageDomains().get(0);
    // Locate the service that manages the storage domain, as that is where the action methods are defined:
    StorageDomainService storageDomainService = storageDomainsService.storageDomainService(sd.id());
    // Locate the service that manages the VMs in storage domain:
    StorageDomainVmsService storageDomainVmsService = storageDomainService.vmsService();
    // Find the the unregistered VM we want to register:
    List<Vm> unregisteredVms = storageDomainVmsService.list().unregistered(true).send().vm();
    Vm vm = null;
    for (Vm x : unregisteredVms) {
        if ("myvm".equals(x.name())) {
            vm = x;
            break;
        }
    }
    // Locate the service that manages virtual machine in the storage domain, as that is where the action methods
    // are defined:
    StorageDomainVmService storageDomainVmService = storageDomainVmsService.vmService(vm.id());
    // Register the VM into the system:
    storageDomainVmService.register().vm(vm().name("exported_myvm")).cluster(cluster().name("mycluster")).vnicProfileMappings(vnicProfileMapping().sourceNetworkName("mynetwork").sourceNetworkProfileName("mynetwork").targetVnicProfile(vnicProfile().name("mynetwork"))).reassignBadMacs(true).send();
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) StorageDomainVmsService(org.ovirt.engine.sdk4.services.StorageDomainVmsService) StorageDomainVmService(org.ovirt.engine.sdk4.services.StorageDomainVmService)

Example 49 with User

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

the class RemoveHost 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 hosts:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Find the service that manages the host:
    HostService hostService = hostsService.hostService(host.id());
    // If the host isn't down or in maintenance then move it to maintenance:
    if (host.status() != HostStatus.MAINTENANCE) {
        hostService.deactivate().send();
    }
    // Remove the host:
    hostService.remove().send();
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 50 with User

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

the class RemoveTag 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 tags:
    TagsService tagsService = connection.systemService().tagsService();
    // Find the tag id:
    String tagId = null;
    for (Tag tag : tagsService.list().send().tags()) {
        if (tag.name().equals("mytag")) {
            tagId = tag.id();
            break;
        }
    }
    // Find the service that manages the tag:
    TagService tagService = tagsService.tagService(tagId);
    // Remove the tag:
    tagService.remove().send();
    // Close the connection to the server:
    connection.close();
}
Also used : TagsService(org.ovirt.engine.sdk4.services.TagsService) TagService(org.ovirt.engine.sdk4.services.TagService) Connection(org.ovirt.engine.sdk4.Connection) Tag(org.ovirt.engine.sdk4.types.Tag)

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