use of org.ovirt.engine.sdk4.services.FenceAgentsService 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();
}
Aggregations