Search in sources :

Example 81 with Connection

use of org.openmuc.j60870.Connection in project ovirt-engine-sdk-java by oVirt.

the class UpdateFencingOptions 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();
    // The name and value of the option that we want to add or update:
    String name = "lanplus";
    String value = "1";
    // Get the reference to the service that manages the hosts:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Get the reference to the service that manages the fencing agents used by the host that we found in the
    // previous step:
    HostService hostService = hostsService.hostService(host.id());
    FenceAgentsService agentsService = hostService.fenceAgentsService();
    // The host may have multiple fencing agents, so we need to locate the first of type 'ipmilan':
    List<Agent> agents = agentsService.list().send().agents();
    Agent agent = null;
    for (Agent x : agents) {
        if ("ipmlan".equals(x.type())) {
            agent = x;
            break;
        }
    }
    // Get the options of the fencing agent. There may be no options, in that case we need to use an empty list.
    List<Option> original = agent.options();
    if (original == null) {
        original = Collections.emptyList();
    }
    // Create a list of modified options, containing all the original options except the one with the name we want
    // to modify, as we will add that with the right value later:
    List<Option> modified = new ArrayList<>();
    for (Option option : original) {
        if (!name.equals(option.name())) {
            modified.add(option);
        }
    }
    // Add the modified option to the list of modified options:
    Option option = option().name(name).value(value).build();
    modified.add(option);
    // Find the service that manages the fence agent:
    FenceAgentService agentService = agentsService.agentService(agent.id());
    // Send the update request containing the modified list of options:
    agentService.update().agent(agent().options(modified)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Agent(org.ovirt.engine.sdk4.types.Agent) FenceAgentService(org.ovirt.engine.sdk4.services.FenceAgentService) Connection(org.ovirt.engine.sdk4.Connection) ArrayList(java.util.ArrayList) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host) Option(org.ovirt.engine.sdk4.types.Option) FenceAgentsService(org.ovirt.engine.sdk4.services.FenceAgentsService)

Example 82 with Connection

use of org.openmuc.j60870.Connection in project agileway by fangjinuo.

the class Ssh2ForwardingClient method startLocalForwarding.

@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
    ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
    if (!localForwarderMap.containsKey(ForwardingChannelInfo.id(channel))) {
        Connection delegate = this.connection.getDelegate();
        try {
            LocalPortForwarder localPortForwarder = delegate.createLocalPortForwarder(new InetSocketAddress(bindToHost, bindToPort), destHost, destPort);
            localForwarderMap.put(ForwardingChannelInfo.id(channel), localPortForwarder);
        } catch (Throwable ex) {
            throw new SshException(ex);
        }
    }
    return channel;
}
Also used : LocalPortForwarder(com.trilead.ssh2.LocalPortForwarder) InetSocketAddress(java.net.InetSocketAddress) Connection(com.trilead.ssh2.Connection) ForwardingChannelInfo(com.jn.agileway.ssh.client.channel.forwarding.ForwardingChannelInfo) SshException(com.jn.agileway.ssh.client.SshException)

Example 83 with Connection

use of org.openmuc.j60870.Connection in project agileway by fangjinuo.

the class Ssh2Connection method connect.

@Override
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SshException {
    try {
        if (delegate == null) {
            Socket localSocket = null;
            if (localAddr != null && Nets.isValidPort(localPort)) {
                localSocket = new Socket(localAddr, localPort);
            }
            Connection conn = new Connection(host.getHostName(), port, localSocket);
            if (this.hostKeyVerifier.isEmpty()) {
                conn.connect();
            } else {
                conn.connect(new ToSsh2HostKeyVerifierAdapter(this.hostKeyVerifier));
            }
            setStatus(SshConnectionStatus.CONNECTED);
            this.delegate = conn;
        }
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : ToSsh2HostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.ganymedssh2.verifier.ToSsh2HostKeyVerifierAdapter) AbstractSshConnection(com.jn.agileway.ssh.client.AbstractSshConnection) Connection(ch.ethz.ssh2.Connection) SshException(com.jn.agileway.ssh.client.SshException) Socket(java.net.Socket)

Example 84 with Connection

use of org.openmuc.j60870.Connection in project agileway by fangjinuo.

the class Ssh2Connection method connect.

@Override
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SshException {
    try {
        if (delegate == null) {
            Connection conn = new Connection(host.getHostName(), port);
            if (this.hostKeyVerifier.isEmpty()) {
                conn.connect();
            } else {
                conn.connect(new ToSsh2HostKeyVerifierAdapter(this.hostKeyVerifier));
            }
            setStatus(SshConnectionStatus.CONNECTED);
            this.delegate = conn;
        }
    } catch (Throwable ex) {
        throw new SshException(ex);
    }
}
Also used : ToSsh2HostKeyVerifierAdapter(com.jn.agileway.ssh.client.impl.trileadssh2.verifier.ToSsh2HostKeyVerifierAdapter) AbstractSshConnection(com.jn.agileway.ssh.client.AbstractSshConnection) Connection(com.trilead.ssh2.Connection) SshException(com.jn.agileway.ssh.client.SshException)

Example 85 with Connection

use of org.openmuc.j60870.Connection in project open-smart-grid-platform by OSGP.

the class AsduSteps method thenIShouldSendAGeneralInterrogationCommandToDevice.

@Then("I should send a general interrogation command to device {string}")
public void thenIShouldSendAGeneralInterrogationCommandToDevice(final String deviceIdentification) throws Exception {
    LOGGER.debug("Then I should send a general interrogation command to device {}", deviceIdentification);
    final DeviceConnection deviceConnection = (DeviceConnection) this.clientConnectionCacheSpy.getConnection(deviceIdentification);
    final Connection connectionMock = deviceConnection.getConnection();
    verify(connectionMock).interrogation(eq(0), eq(CauseOfTransmission.ACTIVATION), any(IeQualifierOfInterrogation.class));
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) Then(io.cucumber.java.en.Then)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)64 Connection (com.trilead.ssh2.Connection)55 IOException (java.io.IOException)43 Session (com.trilead.ssh2.Session)32 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)25 VmService (org.ovirt.engine.sdk4.services.VmService)18 Connection (okhttp3.Connection)15 Connection (ch.ethz.ssh2.Connection)13 Request (okhttp3.Request)13 SystemService (org.ovirt.engine.sdk4.services.SystemService)13 Response (okhttp3.Response)12 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)12 MediaType (okhttp3.MediaType)11 ResponseBody (okhttp3.ResponseBody)11 RequestBody (okhttp3.RequestBody)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 Charset (java.nio.charset.Charset)9