Search in sources :

Example 61 with Connection

use of com.trilead.ssh2.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 62 with Connection

use of com.trilead.ssh2.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddLogicalNetwork 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 "networks" service:
    NetworksService networksService = connection.systemService().networksService();
    // Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag
    // 100 and MTU 1500.
    networksService.add().network(network().name("mynetwork").description("My logical network").dataCenter(dataCenter().name("mydatacenter")).vlan(vlan().id(100)).usages(Arrays.asList(NetworkUsage.DISPLAY)).mtu(1500)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) NetworksService(org.ovirt.engine.sdk4.services.NetworksService)

Example 63 with Connection

use of com.trilead.ssh2.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddLunDiskToVm 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("123456").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 disk attachments of the virtual machine:
    DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService();
    // Use the "add" method of the disk attachments service to add the LUN disk.
    diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("myiscsidisk").lunStorage(hostStorage().type(StorageType.ISCSI).logicalUnits(logicalUnit().address("192.168.200.3").port(3260).target("iqn.2014-07.org.ovirt:storage").id("36001405e793bf9c57a840f58c9a8a220").username("username").password("password")))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
    // 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) DiskAttachmentsService(org.ovirt.engine.sdk4.services.DiskAttachmentsService)

Example 64 with Connection

use of com.trilead.ssh2.Connection in project ovirt-engine-sdk-java by oVirt.

the class AddMacPool 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 service that manages the MAC address pools:
    MacPoolsService poolsService = connection.systemService().macPoolsService();
    // Add a new MAC address pool:
    MacPool pool = poolsService.add().pool(macPool().name("mymacpool").ranges(range().from("02:00:00:00:00:00").to("02:00:00:01:00:00"))).send().pool();
    // Find the service that manages clusters, as we need it in order to find the cluster where we wnt to set the
    // MAC address pool:
    ClustersService clustersService = connection.systemService().clustersService();
    // Find the cluster:
    Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
    // Find the service that manages the cluster, as we need it in order to do the update:
    ClusterService clusterService = clustersService.clusterService(cluster.id());
    // Update the service so that it uses the new MAC pool:
    clusterService.update().cluster(cluster().macPool(macPool().id(pool.id()))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : ClusterService(org.ovirt.engine.sdk4.services.ClusterService) MacPool(org.ovirt.engine.sdk4.types.MacPool) MacPoolsService(org.ovirt.engine.sdk4.services.MacPoolsService) Connection(org.ovirt.engine.sdk4.Connection) ClustersService(org.ovirt.engine.sdk4.services.ClustersService) Cluster(org.ovirt.engine.sdk4.types.Cluster)

Example 65 with Connection

use of com.trilead.ssh2.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)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)63 Connection (com.trilead.ssh2.Connection)54 IOException (java.io.IOException)52 Session (com.trilead.ssh2.Session)39 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)28 SCPClient (com.trilead.ssh2.SCPClient)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 VmService (org.ovirt.engine.sdk4.services.VmService)18 File (java.io.File)13 SystemService (org.ovirt.engine.sdk4.services.SystemService)13 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 Connection (okhttp3.Connection)11 Request (okhttp3.Request)10 Response (okhttp3.Response)9 Connection (ch.ethz.ssh2.Connection)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 ConfigurationException (javax.naming.ConfigurationException)8