Search in sources :

Example 71 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddNfsDataStorageDomain 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 storage domains service:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    // Create a new NFS storage domain:
    StorageDomain sd = sdsService.add().storageDomain(storageDomain().name("mydata").description("My data").type(StorageDomainType.DATA).host(host().name("myhost")).storage(hostStorage().type(StorageType.NFS).address("server0.example.com").path("/nfs/ovirt/40/mydata"))).send().storageDomain();
    // Wait till the storage domain is unattached:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = sdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.UNATTACHED) {
            break;
        }
    }
    // 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) Connection(org.ovirt.engine.sdk4.Connection)

Example 72 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddSystemPermission 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();
    // Get the reference to the service that manages system permissions:
    SystemPermissionsService permissionsService = systemService.permissionsService();
    // Add the "SupeUser" permission to the user with id "123":
    permissionsService.add().permission(permission().role(role().name("SuperUser")).user(user().id("123"))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : SystemService(org.ovirt.engine.sdk4.services.SystemService) SystemPermissionsService(org.ovirt.engine.sdk4.services.SystemPermissionsService) Connection(org.ovirt.engine.sdk4.Connection)

Example 73 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class ListAffinityLabels 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 affinity labels service:
    AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService();
    // Use the "list" method of the affinity labels service
    // to list all the affinity labels of the system:
    List<AffinityLabel> affinityLabels = affinityLabelsService.list().send().labels();
    // which has assigned that affinity label:
    for (AffinityLabel affinityLabel : affinityLabels) {
        System.out.printf("%s:\n", affinityLabel.name());
        for (Vm vm_link : connection.followLink(affinityLabel.vms())) {
            System.out.printf(" - %s\n", connection.followLink(vm_link).name());
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : AffinityLabelsService(org.ovirt.engine.sdk4.services.AffinityLabelsService) AffinityLabel(org.ovirt.engine.sdk4.types.AffinityLabel) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection)

Example 74 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class ListTags method main.

public static void main(String[] args) throws Exception {
    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();
    // Retrieve the tags:
    List<Tag> tags = tagsService.list().send().tags();
    // For each tag print its name and description:
    for (Tag tag : tags) {
        System.out.printf("%s: %s\n", tag.name(), tag.description());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : TagsService(org.ovirt.engine.sdk4.services.TagsService) Connection(org.ovirt.engine.sdk4.Connection) Tag(org.ovirt.engine.sdk4.types.Tag)

Example 75 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddVmSnapshot 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 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 snapshots of the virtual machine:
    SnapshotsService snapshotsService = vmsService.vmService(vm.id()).snapshotsService();
    // Add the snapshot:
    snapshotsService.add().snapshot(snapshot().description("My snapshot")).send();
    // Close the connection to the server:
    connection.close();
}
Also used : SnapshotsService(org.ovirt.engine.sdk4.services.SnapshotsService) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)64 Connection (com.trilead.ssh2.Connection)55 IOException (java.io.IOException)43 Session (com.trilead.ssh2.Session)32 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)25 VmService (org.ovirt.engine.sdk4.services.VmService)18 Connection (okhttp3.Connection)15 Connection (ch.ethz.ssh2.Connection)13 Request (okhttp3.Request)13 SystemService (org.ovirt.engine.sdk4.services.SystemService)13 Response (okhttp3.Response)12 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 MediaType (okhttp3.MediaType)11 ResponseBody (okhttp3.ResponseBody)11 RequestBody (okhttp3.RequestBody)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 Charset (java.nio.charset.Charset)9