Search in sources :

Example 91 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class ImportVm method main.

public static void main(String[] args) throws Exception {
    // Create connection to the oVirt engine server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get storage domains service
    StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
    // Get export storage domain
    StorageDomain exportDomain = storageDomainsService.list().search("name=myexport").send().storageDomains().get(0);
    // Get target storage domain
    StorageDomain targetStorageDomain = storageDomainsService.list().search("name=mydata").send().storageDomains().get(0);
    // Get cluster service
    ClustersService clustersService = connection.systemService().clustersService();
    // Get the cluster we import the VM to
    Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
    // Get VM service for export storage domain
    StorageDomainVmsService vmsService = storageDomainsService.storageDomainService(exportDomain.id()).vmsService();
    // Get the first exported VM, assuming we have one
    Vm exportedVm = vmsService.list().send().vm().get(0);
    // Import the exported VM into target storage domain, 'mydata'
    vmsService.vmService(exportedVm.id()).import_().storageDomain(storageDomain().id(targetStorageDomain.id())).cluster(cluster().id(cluster.id())).vm(vm().id(exportedVm.id())).send();
    // Close the connection
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) ClustersService(org.ovirt.engine.sdk4.services.ClustersService) Cluster(org.ovirt.engine.sdk4.types.Cluster) StorageDomainVmsService(org.ovirt.engine.sdk4.services.StorageDomainVmsService)

Example 92 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class ListGlanceImages 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 service 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();
    // List the images available in the storage domain:
    List<Image> images = imagesService.list().send().images();
    for (Image image : images) {
        System.out.println(image.name());
    }
    // 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)

Example 93 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class ListVmDisks 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:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the disk attachments of the virtual machine:
    DiskAttachmentsService diskAttachmentsService = vmService.diskAttachmentsService();
    // Retrieve the list of disks attachments, and print the disk details. Note that each attachment contains a link
    // to the corresponding disk, but not the actual disk data. In order to retrieve the actual disk data we use the
    // `follow_link` method.
    List<DiskAttachment> diskAttachments = diskAttachmentsService.list().send().attachments();
    for (DiskAttachment diskAttachment : diskAttachments) {
        Disk disk = connection.followLink(diskAttachment.disk());
        System.out.printf("name: %s\n", disk.name());
        System.out.printf("id: %s\n", disk.id());
        System.out.printf("status: %s\n", disk.status());
        System.out.printf("provisioned_size: %s\n", disk.provisionedSize());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) 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) Disk(org.ovirt.engine.sdk4.types.Disk) DiskAttachmentsService(org.ovirt.engine.sdk4.services.DiskAttachmentsService)

Example 94 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class ListVms 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();
    // Use the "list" method of the "vms" service to list all the virtual machines of the system:
    List<Vm> vms = vmsService.list().send().vms();
    // Print the virtual machine names and identifiers:
    for (Vm vm : vms) {
        System.out.printf("%s: %s\n", vm.name(), vm.id());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService)

Example 95 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddVmFromTemplateVersion 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 the storage domains:
    StorageDomainsService storageDomainsService = systemService.storageDomainsService();
    // Find the storage domain we want to be used for virtual machine disks:
    StorageDomain storageDomain = storageDomainsService.list().search("name=mydata").send().storageDomains().get(0);
    // Get the reference to the service that manages the templates:
    TemplatesService templatesService = systemService.templatesService();
    // When a template has multiple versions they all have the same name, so we need to explicitly find the one that
    // has the version name or version number that we want to use. In this case we want to use version 3 of the
    // template.
    List<Template> templates = templatesService.list().search("name=mytemplate").send().templates();
    String templateId = null;
    for (Template template : templates) {
        if (template.version().versionNumber().equals(BigInteger.valueOf(3))) {
            templateId = template.id();
            break;
        }
    }
    // Find the template disk we want be created on specific storage domain
    // for our virtual machine:
    TemplateService templateService = templatesService.templateService(templateId);
    List<DiskAttachment> diskAttachments = connection.followLink(templateService.get().send().template().diskAttachments());
    Disk disk = diskAttachments.get(0).disk();
    // Get the reference to the service that manages the virtual machines:
    VmsService vmsService = connection.systemService().vmsService();
    // Add a new virtual machine explicitly indicating the identifier of the template version that we want to use:
    vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().id(templateId)).diskAttachments(diskAttachment().disk(disk().id(disk.id()).format(DiskFormat.COW).storageDomains(storageDomain().id(storageDomain.id()))))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) TemplatesService(org.ovirt.engine.sdk4.services.TemplatesService) Template(org.ovirt.engine.sdk4.types.Template) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) TemplateService(org.ovirt.engine.sdk4.services.TemplateService) Disk(org.ovirt.engine.sdk4.types.Disk)

Aggregations

IOException (java.io.IOException)68 Connection (org.ovirt.engine.sdk4.Connection)64 Connection (com.trilead.ssh2.Connection)61 Connection (org.osate.aadl2.Connection)57 Session (com.trilead.ssh2.Session)33 Connection (org.jboss.remoting3.Connection)33 Connection (com.google.cloud.bigquery.connection.v1.Connection)31 Test (org.junit.Test)30 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)29 Connection (okhttp3.Connection)28 Connection (ch.ethz.ssh2.Connection)24 Request (okhttp3.Request)20 Subcomponent (org.osate.aadl2.Subcomponent)19 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)18 PortConnection (org.osate.aadl2.PortConnection)18 VmService (org.ovirt.engine.sdk4.services.VmService)18 ArrayList (java.util.ArrayList)17 Response (okhttp3.Response)17