Search in sources :

Example 66 with Connection

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

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

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

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

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

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)63 Connection (com.trilead.ssh2.Connection)52 IOException (java.io.IOException)41 VmsService (org.ovirt.engine.sdk4.services.VmsService)33 Session (com.trilead.ssh2.Session)32 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)25 VmService (org.ovirt.engine.sdk4.services.VmService)18 SystemService (org.ovirt.engine.sdk4.services.SystemService)14 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 Connection (okhttp3.Connection)11 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 Request (okhttp3.Request)10 File (java.io.File)9 Response (okhttp3.Response)9 Connection (ch.ethz.ssh2.Connection)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 MediaType (okhttp3.MediaType)8 RequestBody (okhttp3.RequestBody)8