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();
}
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;
}
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);
}
}
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);
}
}
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));
}
Aggregations