Search in sources :

Example 96 with Connection

use of org.osate.aadl2.Connection in project cosmic by MissionCriticalCloud.

the class SshHelperTest method openConnectionSessionTest.

@Test
public void openConnectionSessionTest() throws IOException, InterruptedException {
    final Connection conn = Mockito.mock(Connection.class);
    PowerMockito.mockStatic(Thread.class);
    SshHelper.openConnectionSession(conn);
    Mockito.verify(conn).openSession();
    PowerMockito.verifyStatic();
}
Also used : Connection(com.trilead.ssh2.Connection) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with Connection

use of org.osate.aadl2.Connection in project new-cloud by xie-summer.

the class SSHTemplate method getConnection.

/**
 * 获取连接并校验
 * @param ip
 * @param port
 * @param username
 * @param password
 * @return Connection
 * @throws Exception
 */
private Connection getConnection(String ip, int port, String username, String password) throws Exception {
    Connection conn = new Connection(ip, port);
    conn.connect(null, CONNCET_TIMEOUT, CONNCET_TIMEOUT);
    boolean isAuthenticated = conn.authenticateWithPassword(username, password);
    if (isAuthenticated == false) {
        throw new Exception("SSH authentication failed with [ userName: " + username + ", password: " + password + "]");
    }
    return conn;
}
Also used : Connection(ch.ethz.ssh2.Connection) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) SSHException(com.sohu.cache.exception.SSHException)

Example 98 with Connection

use of org.osate.aadl2.Connection in project ovirt-engine-sdk-java by oVirt.

the class DiscoverIscsi 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();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Locate the service that manages the host, as that is where the action methods are defined:
    HostService hostService = hostsService.hostService(host.id());
    // Call the "iscsiDiscover" method of the service to start it:
    HostService.DiscoverIscsiResponse response = hostService.discoverIscsi().iscsi(iscsiDetails().address("myaddress")).send();
    // Print only address corresponding to target:
    for (IscsiDetails detail : response.discoveredTargets()) {
        System.out.println(detail.address() + ":" + detail.target());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) IscsiDetails(org.ovirt.engine.sdk4.types.IscsiDetails) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 99 with Connection

use of org.osate.aadl2.Connection in project ovirt-engine-sdk-java by oVirt.

the class GetDisplayTicket 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();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Find the service that manages the graphics consoles of the virtual machine:
    VmService vmService = vmsService.vmService(vm.id());
    VmGraphicsConsolesService consolesService = vmService.graphicsConsolesService();
    // The method that lists the graphics consoles doesn't support search, so in order to find the console
    // corresponding to the access protocol that we are interested on (SPICE in this example) we need to get all of
    // them and filter explicitly. In addition the `current` parameter must be `true`, as otherwise you will *not*
    // get important values like the `address` and `port` where the console is available.
    List<GraphicsConsole> consoles = consolesService.list().current(true).send().consoles();
    GraphicsConsole console = null;
    for (GraphicsConsole c : consoles) {
        if (c.protocol() == GraphicsType.SPICE) {
            console = c;
            break;
        }
    }
    // Find the service that manages the graphics console that was selected in the previous step:
    VmGraphicsConsoleService consoleService = consolesService.consoleService(console.id());
    // Request the ticket. The virtual machine must be up and running, as it doesn't make sense to get a console
    // ticket for a virtual machine that is down. If you try that, the request will fail.
    Ticket ticket = consoleService.ticket().send().ticket();
    // Print the details needed to connect to the console (the ticket value is the password):
    System.out.printf("address: %s\n", console.address());
    System.out.printf("port: %d\n", console.port());
    System.out.printf("tls_port: %d\n", console.tlsPort());
    System.out.printf("password: %s\n", ticket.value());
    // Close the connection to the server:
    connection.close();
}
Also used : Ticket(org.ovirt.engine.sdk4.types.Ticket) SystemService(org.ovirt.engine.sdk4.services.SystemService) VmGraphicsConsolesService(org.ovirt.engine.sdk4.services.VmGraphicsConsolesService) VmGraphicsConsoleService(org.ovirt.engine.sdk4.services.VmGraphicsConsoleService) 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) GraphicsConsole(org.ovirt.engine.sdk4.types.GraphicsConsole)

Example 100 with Connection

use of org.osate.aadl2.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)

Aggregations

IOException (java.io.IOException)82 Connection (com.trilead.ssh2.Connection)69 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)64 Connection (org.ovirt.engine.sdk4.Connection)64 Connection (org.osate.aadl2.Connection)57 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)51 Connection (ch.ethz.ssh2.Connection)37 ArrayList (java.util.ArrayList)36 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)35 Session (com.trilead.ssh2.Session)33 Connection (org.jboss.remoting3.Connection)33 Connection (okhttp3.Connection)32 Test (org.junit.Test)32 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)32 Connection (com.google.cloud.bigquery.connection.v1.Connection)31 InputStream (java.io.InputStream)31 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)29 Subcomponent (org.osate.aadl2.Subcomponent)28