Search in sources :

Example 1 with IscsiDetails

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

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

Aggregations

HostService (org.ovirt.engine.sdk4.services.HostService)2 HostsService (org.ovirt.engine.sdk4.services.HostsService)2 Test (org.junit.Test)1 Connection (org.ovirt.engine.sdk4.Connection)1 Host (org.ovirt.engine.sdk4.types.Host)1 IscsiDetails (org.ovirt.engine.sdk4.types.IscsiDetails)1