use of org.ovirt.engine.sdk4.services.HostService 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.ovirt.engine.sdk4.services.HostService in project ovirt-engine-sdk-java by oVirt.
the class IscsiDiscover 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.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("myaddress")).send();
// Print only targets:
for (String target : response.iscsiTargets()) {
System.out.println(target);
}
// 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();
}
use of org.ovirt.engine.sdk4.services.HostService 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();
}
use of org.ovirt.engine.sdk4.services.HostService in project ovirt-engine-sdk-java by oVirt.
the class IscsiDiscoverTest method testActionParameters.
/**
* Test we don't get null vm service for existing vm id and correct object
*/
@Test
public void testActionParameters() {
HostsService hostsService = connection.systemService().hostsService();
HostService hostService = hostsService.hostService("123");
HostService.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("iscsi.example.com").port(3260)).send();
assertEquals("<action>" + "<iscsi>" + "<address>iscsi.example.com</address>" + "<port>3260</port>" + "</iscsi>" + "</action>", getLastRequestContent());
assertEquals("192.168.121.102", response.discoveredTargets().get(0).address());
assertEquals(BigInteger.valueOf(3260), response.discoveredTargets().get(0).port());
assertEquals("myiqn", response.iscsiTargets().get(0));
}
use of org.ovirt.engine.sdk4.services.HostService in project ovirt-engine-sdk-java by oVirt.
the class AddBond method main.
public static void main(String[] args) throws Exception {
// Create the connection to the server:
Connection connection = connection().url("https://engine42.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").insecure(true).build();
// Find the service that manages the collection of hosts:
HostsService hostsService = connection.systemService().hostsService();
// Find the host:
Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
// Find the service that manages the host:
HostService hostService = hostsService.hostService(host.id());
// Configure the host adding a bond with two slaves, and attaching it to a network with an static IP address:
hostService.setupNetworks().modifiedBonds(hostNic().name("bond0").bonding(bonding().options(option().name("mode").value("1"), option().name("miimon").value("100")).slaves(hostNic().name("eth0"), hostNic().name("eth1")))).modifiedNetworkAttachments(networkAttachment().network(network().name("mynetwork")).ipAddressAssignments(ipAddressAssignment().assignmentMethod(BootProtocol.STATIC).ip(ip().address("192.168.122.100").netmask("255.255.255.0")))).send();
// After modifying the network configuration it is very important to make it persistent:
hostService.commitNetConfig().send();
// Close the connection to the server:
connection.close();
}
Aggregations