Search in sources :

Example 66 with Service

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

the class AddDataCenter 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 data centers service:
    DataCentersService dcsService = connection.systemService().dataCentersService();
    // Use the "add" method to create a new data center:
    dcsService.add().dataCenter(dataCenter().name("mydc").description("My data center").local(false)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : DataCentersService(org.ovirt.engine.sdk4.services.DataCentersService) Connection(org.ovirt.engine.sdk4.Connection)

Example 67 with Service

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

the class AddGroup 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 groups service:
    GroupsService groupsService = connection.systemService().groupsService();
    // Use the "add" method to add group from a directory service. Please note that domain name is name of the
    // authorization provider:
    groupsService.add().group(group().name("Developers").domain(domain().name("internal-authz"))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : GroupsService(org.ovirt.engine.sdk4.services.GroupsService) Connection(org.ovirt.engine.sdk4.Connection)

Example 68 with Service

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

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

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

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