Search in sources :

Example 76 with Service

use of org.ovirt.engine.sdk4.Service 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)

Example 77 with Service

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

the class StartVm 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, as that is where the action methods are defined:
    VmService vmService = vmsService.vmService(vm.id());
    // Call the "start" method of the service to start it:
    vmService.start().send();
    // What till the virtual machine is up:
    for (; ; ) {
        Thread.sleep(5 * 1000);
        vm = vmService.get().send().vm();
        if (vm.status() == VmStatus.UP) {
            break;
        }
    }
    // 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)

Example 78 with Service

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

the class StopVm 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, as that is where the action methods are defined:
    VmService vmService = vmsService.vmService(vm.id());
    // Call the "stop" method of the service to stop it:
    vmService.stop().send();
    // What till the virtual machine is down:
    for (; ; ) {
        Thread.sleep(5 * 1000);
        vm = vmService.get().send().vm();
        if (vm.status() == VmStatus.DOWN) {
            break;
        }
    }
    // 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)

Example 79 with Service

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

the class ListRoles method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine41.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the service that manages the roles:
    RolesService rolesService = connection.systemService().rolesService();
    // Retrieve the roles:
    List<Role> roles = rolesService.list().send().roles();
    // For each role print its name and description:
    for (Role role : roles) {
        System.out.printf("%s: %s\n", role.name(), role.description());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Role(org.ovirt.engine.sdk4.types.Role) RolesService(org.ovirt.engine.sdk4.services.RolesService) Connection(org.ovirt.engine.sdk4.Connection)

Example 80 with Service

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

the class ListVmSnapshots 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 service:
    SystemService systemService = connection.systemService();
    // Find all the virtual machines and store the id and name in a
    // map, so that looking them up later will be faster:
    VmsService vmsService = systemService.vmsService();
    Map<String, String> vmsMap = new HashMap<>();
    for (Vm vm : vmsService.list().send().vms()) {
        vmsMap.put(vm.id(), vm.name());
    }
    // Same for storage domains:
    StorageDomainsService storageDomainsService = systemService.storageDomainsService();
    Map<String, String> storageDomainsMap = new HashMap<>();
    for (StorageDomain sd : storageDomainsService.list().send().storageDomains()) {
        storageDomainsMap.put(sd.id(), sd.name());
    }
    // find its disks:
    for (Map.Entry<String, String> vm : vmsMap.entrySet()) {
        VmService vmService = vmsService.vmService(vm.getKey());
        SnapshotsService snapshotsService = vmService.snapshotsService();
        Map<String, String> snapshotsMap = new HashMap<>();
        for (Snapshot snapshot : snapshotsService.list().send().snapshots()) {
            snapshotsMap.put(snapshot.id(), snapshot.description());
        }
        for (Map.Entry<String, String> snapshot : snapshotsMap.entrySet()) {
            SnapshotService snapshotService = snapshotsService.snapshotService(snapshot.getKey());
            SnapshotDisksService snapshotDisksService = snapshotService.disksService();
            for (Disk disk : snapshotDisksService.list().send().disks()) {
                if (disk.storageDomains().size() > 0) {
                    String storageDomainId = disk.storageDomains().get(0).id();
                    String storageDomainName = storageDomainsMap.get(storageDomainId);
                    System.out.printf("%s:%s:%s:%s\n", vm.getValue(), snapshot.getValue(), disk.alias(), storageDomainName);
                }
            }
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : SnapshotService(org.ovirt.engine.sdk4.services.SnapshotService) SnapshotsService(org.ovirt.engine.sdk4.services.SnapshotsService) HashMap(java.util.HashMap) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) Snapshot(org.ovirt.engine.sdk4.types.Snapshot) SnapshotDisksService(org.ovirt.engine.sdk4.services.SnapshotDisksService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) Vm(org.ovirt.engine.sdk4.types.Vm) HashMap(java.util.HashMap) Map(java.util.Map) Disk(org.ovirt.engine.sdk4.types.Disk)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)55 Vm (org.ovirt.engine.sdk4.types.Vm)26 VmsService (org.ovirt.engine.sdk4.services.VmsService)25 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 CoreException (org.eclipse.core.runtime.CoreException)18 VmService (org.ovirt.engine.sdk4.services.VmService)15 ArrayList (java.util.ArrayList)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)11 SystemService (org.ovirt.engine.sdk4.services.SystemService)10 ServerPort (org.eclipse.wst.server.core.ServerPort)9 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)7 HostService (org.ovirt.engine.sdk4.services.HostService)6 HostsService (org.ovirt.engine.sdk4.services.HostsService)6 Disk (org.ovirt.engine.sdk4.types.Disk)6 Test (org.junit.Test)5 DataCenterService (org.ovirt.engine.sdk4.services.DataCenterService)5 DataCentersService (org.ovirt.engine.sdk4.services.DataCentersService)5 Cluster (org.ovirt.engine.sdk4.types.Cluster)5