Search in sources :

Example 1 with Host

use of org.ovirt.engine.sdk4.types.Host 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 Host

use of org.ovirt.engine.sdk4.types.Host 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 Host

use of org.ovirt.engine.sdk4.types.Host in project ovirt-engine-sdk-java by oVirt.

the class AddNfsDataStorageDomain 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 storage domains service:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    // Create a new NFS storage domain:
    StorageDomain sd = sdsService.add().storageDomain(storageDomain().name("mydata").description("My data").type(StorageDomainType.DATA).host(host().name("myhost")).storage(hostStorage().type(StorageType.NFS).address("server0.example.com").path("/nfs/ovirt/40/mydata"))).send().storageDomain();
    // Wait till the storage domain is unattached:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = sdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.UNATTACHED) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Connection(org.ovirt.engine.sdk4.Connection)

Example 4 with Host

use of org.ovirt.engine.sdk4.types.Host 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 5 with Host

use of org.ovirt.engine.sdk4.types.Host 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

Connection (org.ovirt.engine.sdk4.Connection)9 HostsService (org.ovirt.engine.sdk4.services.HostsService)6 Host (org.ovirt.engine.sdk4.types.Host)6 HostService (org.ovirt.engine.sdk4.services.HostService)5 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)2 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)2 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)2 ArrayList (java.util.ArrayList)1 FenceAgentService (org.ovirt.engine.sdk4.services.FenceAgentService)1 FenceAgentsService (org.ovirt.engine.sdk4.services.FenceAgentsService)1 SystemService (org.ovirt.engine.sdk4.services.SystemService)1 VmService (org.ovirt.engine.sdk4.services.VmService)1 VmsService (org.ovirt.engine.sdk4.services.VmsService)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 Vm (org.ovirt.engine.sdk4.types.Vm)1