Search in sources :

Example 66 with Connection

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

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

the class AddHost 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 hosts service:
    HostsService hostsService = connection.systemService().hostsService();
    // Add the host:
    Host host = hostsService.add().host(host().name("myhost").description("My host").address("node40.example.com").rootPassword("redhat123").cluster(cluster().name("mycluster"))).send().host();
    // Wait till the host is up:
    HostService hostService = hostsService.hostService(host.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        host = hostService.get().send().host();
        if (host.status() == HostStatus.UP) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 68 with Connection

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

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

the class RemoveVm 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();
    // Find the service that manages VMs:
    VmsService vmsService = connection.systemService().vmsService();
    // Find the VM:
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Note that the "vm" variable that we assigned above contains only the data of the VM, it doesn't have any
    // method like "remove". Methods are defined in the services. So now that we have the description of the VM
    // we can find the service that manages it, calling the locator method "vmService" defined in the "vms"
    // service. This locator method receives as parameter the identifier of the VM and returns a reference to the
    // service that manages that VM.
    VmService vmService = vmsService.vmService(vm.id());
    // Now that we have the reference to the service that manages the VM we can use it to remove the VM. Note that
    // this method doesn't need any parameter, as the identifier of the VM is already known by the service that we
    // located in the previous step.
    vmService.remove().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)

Example 70 with Connection

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

the class SearchVms 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 search the virtual machines that match a search query:
    List<Vm> vms = vmsService.list().search("name=MYVM").caseSensitive(false).send().vms();
    // Print the virtual machine names and identifiers:
    for (Vm vm : vms) {
        System.out.printf("%s: %s", 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)

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