Search in sources :

Example 1 with HostsService

use of org.ovirt.engine.sdk4.services.HostsService 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 2 with HostsService

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

use of org.ovirt.engine.sdk4.services.HostsService 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();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Example 4 with HostsService

use of org.ovirt.engine.sdk4.services.HostsService 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));
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) HostsService(org.ovirt.engine.sdk4.services.HostsService) Test(org.junit.Test)

Example 5 with HostsService

use of org.ovirt.engine.sdk4.services.HostsService 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();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Aggregations

HostsService (org.ovirt.engine.sdk4.services.HostsService)7 Connection (org.ovirt.engine.sdk4.Connection)6 HostService (org.ovirt.engine.sdk4.services.HostService)6 Host (org.ovirt.engine.sdk4.types.Host)6 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FenceAgentService (org.ovirt.engine.sdk4.services.FenceAgentService)1 FenceAgentsService (org.ovirt.engine.sdk4.services.FenceAgentsService)1 Agent (org.ovirt.engine.sdk4.types.Agent)1 IscsiDetails (org.ovirt.engine.sdk4.types.IscsiDetails)1 Option (org.ovirt.engine.sdk4.types.Option)1 Statistic (org.ovirt.engine.sdk4.types.Statistic)1