Search in sources :

Example 1 with Session

use of org.ovirt.engine.api.model.Session in project ovirt-engine by oVirt.

the class VmMapper method mapConsoleSession.

/**
 * This method maps the session of the 'console user', if exists. This is the ovirt user who opened a session
 * through the user-console; the one who is said to be 'logged in' (or 'have the ticket') to this VM. Currently
 * engine makes available only the name and IP of this user. In the future it may make available also the connection
 * protocol used in the session (spice/vnc).
 */
private static Sessions mapConsoleSession(org.ovirt.engine.core.common.businessentities.VM vm, Sessions sessions) {
    // currently in format user@domain, so needs to be
    String consoleUserName = vm.getConsoleCurentUserName();
    // parsed.
    if (consoleUserName != null && !consoleUserName.isEmpty()) {
        String userName = parseUserName(consoleUserName);
        String domainName = parseDomainName(consoleUserName);
        User consoleUser = new User();
        consoleUser.setUserName(userName);
        consoleUser.setDomain(new Domain());
        consoleUser.getDomain().setName(domainName);
        Session consoleSession = new Session();
        consoleSession.setUser(consoleUser);
        if (vm.getClientIp() != null && !vm.getClientIp().isEmpty()) {
            Ip ip = new Ip();
            ip.setAddress(vm.getClientIp());
            consoleSession.setIp(ip);
        }
        consoleSession.setConsoleUser(true);
        // TODO: in the future, map the connection protocol as well
        sessions.getSessions().add(consoleSession);
    }
    return sessions;
}
Also used : User(org.ovirt.engine.api.model.User) Ip(org.ovirt.engine.api.model.Ip) Domain(org.ovirt.engine.api.model.Domain) Session(org.ovirt.engine.api.model.Session)

Example 2 with Session

use of org.ovirt.engine.api.model.Session in project ovirt-engine by oVirt.

the class BackendVmSessionsResource method list.

@Override
public Sessions list() {
    Object obj = getEntity(entityType, QueryType.GetVmByVmId, new IdQueryParameters(vmId), vmId.toString(), true);
    VM vm = (VM) obj;
    Sessions sessions = VmMapper.map(vm, new Sessions());
    org.ovirt.engine.api.model.Vm vmModel = new org.ovirt.engine.api.model.Vm();
    vmModel.setId(vm.getId().toString());
    if (sessions.isSetSessions()) {
        for (Session session : sessions.getSessions()) {
            setSessionId(session);
            setSessionVmId(vmModel, session);
            // only console user assumed to be an ovirt user, and only an ovirt-user has an ID & href
            if (session.isSetConsoleUser() && session.isConsoleUser()) {
                addLinksIncludingUser(session);
            } else {
                addLinks(session, org.ovirt.engine.api.model.Vm.class);
            }
        }
    }
    return sessions;
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Sessions(org.ovirt.engine.api.model.Sessions) Session(org.ovirt.engine.api.model.Session)

Example 3 with Session

use of org.ovirt.engine.api.model.Session in project ovirt-engine by oVirt.

the class VmMapper method mapGuestSessions.

/**
 * This method maps the sessions of users who are connected to the VM, but are not the 'logged-in'/'console' user.
 * Currently the information that engine supplies about these users is only a string, which contains the name of
 * only one such user, if exists (the user is not necessarily an ovirt user). In the future the engine may pass
 * multiple 'guest' users, along with their IPs and perhaps also the connection protocols that they are using (SSH,
 * RDP...)
 */
private static Sessions mapGuestSessions(org.ovirt.engine.core.common.businessentities.VM vm, Sessions sessions) {
    String guestUserName = vm.getGuestCurentUserName();
    if (guestUserName != null && !guestUserName.isEmpty()) {
        Session guestSession = new Session();
        User user = new User();
        user.setUserName(guestUserName);
        guestSession.setUser(user);
        // TODO: in the future, map the user-IP and connection protocol as well
        sessions.getSessions().add(guestSession);
    }
    return sessions;
}
Also used : User(org.ovirt.engine.api.model.User) Session(org.ovirt.engine.api.model.Session)

Example 4 with Session

use of org.ovirt.engine.api.model.Session in project ovirt-engine by oVirt.

the class VmMapperTest method testMapSessions.

@Test
public void testMapSessions() {
    org.ovirt.engine.core.common.businessentities.VM vm = new org.ovirt.engine.core.common.businessentities.VM();
    VmDynamic vmDynamic = new VmDynamic();
    vmDynamic.setConsoleCurrentUserName("admin");
    vmDynamic.setClientIp("1.1.1.1");
    vmDynamic.setGuestCurrentUserName("Ori");
    vm.setDynamicData(vmDynamic);
    Sessions sessions = VmMapper.map(vm, new Sessions());
    assertNotNull(sessions);
    assertEquals(2, sessions.getSessions().size());
    Session consoleSession = sessions.getSessions().get(0).getUser().getUserName().equals("admin") ? sessions.getSessions().get(0) : sessions.getSessions().get(1);
    Session guestSession = sessions.getSessions().get(0).getUser().getUserName().equals("Ori") ? sessions.getSessions().get(0) : sessions.getSessions().get(1);
    assertEquals("admin", consoleSession.getUser().getUserName());
    assertEquals("1.1.1.1", consoleSession.getIp().getAddress());
    assertTrue(consoleSession.isConsoleUser());
    assertEquals("Ori", guestSession.getUser().getUserName());
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) Sessions(org.ovirt.engine.api.model.Sessions) Session(org.ovirt.engine.api.model.Session) Test(org.junit.Test)

Aggregations

Session (org.ovirt.engine.api.model.Session)4 Sessions (org.ovirt.engine.api.model.Sessions)2 User (org.ovirt.engine.api.model.User)2 Test (org.junit.Test)1 Domain (org.ovirt.engine.api.model.Domain)1 Ip (org.ovirt.engine.api.model.Ip)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1