Search in sources :

Example 11 with User

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

the class BackendDomainUsersResource method mapUsers.

private Users mapUsers(List<DirectoryUser> entities) {
    Users collection = new Users();
    for (DirectoryUser entity : entities) {
        User user = map(entity);
        user = populate(user, entity);
        user = addLinks(user, true);
        collection.getUsers().add(user);
    }
    return collection;
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) User(org.ovirt.engine.api.model.User) Users(org.ovirt.engine.api.model.Users)

Example 12 with User

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

the class LinkHelperTest method testUserTagLinks.

@Test
public void testUserTagLinks() throws Exception {
    Tag tag = new Tag();
    tag.setId(TAG_ID);
    tag.setUser(new User());
    tag.getUser().setId(USER_ID);
    LinkHelper.addLinks(tag);
    assertEquals(USER_TAG_HREF, tag.getHref());
}
Also used : User(org.ovirt.engine.api.model.User) Tag(org.ovirt.engine.api.model.Tag) Test(org.junit.Test)

Example 13 with User

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

the class HostMapperTest method testUpdateSshHost.

@Test
public void testUpdateSshHost() {
    Ssh sshConf = new Ssh();
    sshConf.setPort(22);
    sshConf.setUser(new User());
    sshConf.getUser().setUserName("root");
    sshConf.setFingerprint("1234");
    VdsStatic vdsStatic = new VdsStatic();
    vdsStatic.setSshUsername("root");
    vdsStatic.setSshPort(22);
    vdsStatic.setSshKeyFingerprint("1234");
    VdsStatic mappedVdsStatic = HostMapper.map(sshConf, vdsStatic);
    assertEquals(22, mappedVdsStatic.getSshPort());
    assertEquals("1234", mappedVdsStatic.getSshKeyFingerprint());
    assertEquals("root", mappedVdsStatic.getSshUsername());
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) User(org.ovirt.engine.api.model.User) Ssh(org.ovirt.engine.api.model.Ssh) Test(org.junit.Test)

Example 14 with User

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

the class VmMapper method map.

@Mapping(from = CloudInit.class, to = VmInit.class)
public static VmInit map(CloudInit model, VmInit template) {
    VmInit entity = template != null ? template : new VmInit();
    if (model.isSetHost() && model.getHost().isSetAddress()) {
        entity.setHostname(model.getHost().getAddress());
    }
    if (model.isSetAuthorizedKeys() && model.getAuthorizedKeys().isSetAuthorizedKeys() && !model.getAuthorizedKeys().getAuthorizedKeys().isEmpty()) {
        StringBuilder keys = new StringBuilder();
        for (AuthorizedKey authKey : model.getAuthorizedKeys().getAuthorizedKeys()) {
            if (keys.length() > 0) {
                keys.append("\n");
            }
            keys.append(authKey.getKey());
        }
        entity.setAuthorizedKeys(keys.toString());
    }
    if (model.isSetRegenerateSshKeys()) {
        entity.setRegenerateKeys(model.isRegenerateSshKeys());
    }
    if (model.isSetNetworkConfiguration()) {
        if (model.getNetworkConfiguration().isSetNics()) {
            List<VmInitNetwork> interfaces = new ArrayList<>();
            for (Nic iface : model.getNetworkConfiguration().getNics().getNics()) {
                VmInitNetwork vmInitInterface = new VmInitNetwork();
                if (iface.isSetName()) {
                    vmInitInterface.setName(iface.getName());
                }
                interfaces.add(vmInitInterface);
                if (iface.isSetBootProtocol()) {
                    Ipv4BootProtocol protocol = Ipv4BootProtocolMapper.map(iface.getBootProtocol());
                    vmInitInterface.setBootProtocol(protocol);
                    if (protocol != Ipv4BootProtocol.DHCP && iface.isSetNetwork() && iface.getNetwork().isSetIp()) {
                        if (iface.getNetwork().getIp().isSetAddress()) {
                            vmInitInterface.setIp(iface.getNetwork().getIp().getAddress());
                        }
                        if (iface.getNetwork().getIp().isSetNetmask()) {
                            vmInitInterface.setNetmask(iface.getNetwork().getIp().getNetmask());
                        }
                        if (iface.getNetwork().getIp().isSetGateway()) {
                            vmInitInterface.setGateway(iface.getNetwork().getIp().getGateway());
                        }
                    }
                    if (iface.isSetOnBoot() && iface.isOnBoot()) {
                        vmInitInterface.setStartOnBoot(true);
                    }
                }
            }
            entity.setNetworks(interfaces);
        }
        if (model.getNetworkConfiguration().isSetDns()) {
            if (model.getNetworkConfiguration().getDns().isSetServers() && model.getNetworkConfiguration().getDns().getServers().isSetHosts() && !model.getNetworkConfiguration().getDns().getServers().getHosts().isEmpty()) {
                List<String> dnsServers = new ArrayList<>();
                for (Host host : model.getNetworkConfiguration().getDns().getServers().getHosts()) {
                    if (host.isSetAddress()) {
                        dnsServers.add(host.getAddress());
                    }
                }
                entity.setDnsServers(String.join(" ", dnsServers));
            }
            if (model.getNetworkConfiguration().getDns().isSetSearchDomains() && model.getNetworkConfiguration().getDns().getSearchDomains().isSetHosts() && !model.getNetworkConfiguration().getDns().getSearchDomains().getHosts().isEmpty()) {
                List<String> searchDomains = new ArrayList<>();
                for (Host host : model.getNetworkConfiguration().getDns().getSearchDomains().getHosts()) {
                    if (host.isSetAddress()) {
                        searchDomains.add(host.getAddress());
                    }
                }
                entity.setDnsSearch(String.join(" ", searchDomains));
            }
        }
    }
    if (model.isSetTimezone() && model.getTimezone() != null) {
        entity.setTimeZone(model.getTimezone());
    }
    if (model.isSetUsers()) {
        for (User user : model.getUsers().getUsers()) {
            String userName = user.getUserName();
            if (StringUtils.equals(userName, "root")) {
                entity.setUserName(userName);
                String userPassword = user.getPassword();
                if (userPassword != null) {
                    entity.setRootPassword(userPassword);
                }
            }
        }
    }
    // for RunOnce backward compatibility.
    if (model.isSetFiles() && model.getFiles().isSetFiles() && !model.getFiles().getFiles().isEmpty()) {
        File file = model.getFiles().getFiles().get(0);
        entity.setCustomScript(file.getContent());
    }
    return entity;
}
Also used : User(org.ovirt.engine.api.model.User) VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) ArrayList(java.util.ArrayList) Nic(org.ovirt.engine.api.model.Nic) Host(org.ovirt.engine.api.model.Host) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) AuthorizedKey(org.ovirt.engine.api.model.AuthorizedKey) File(org.ovirt.engine.api.model.File)

Example 15 with User

use of org.ovirt.engine.api.model.User 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)

Aggregations

User (org.ovirt.engine.api.model.User)31 Test (org.junit.Test)12 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)9 Role (org.ovirt.engine.api.model.Role)7 Permission (org.ovirt.engine.api.model.Permission)6 DirectoryUser (org.ovirt.engine.core.aaa.DirectoryUser)6 Roles (org.ovirt.engine.api.model.Roles)5 Domain (org.ovirt.engine.api.model.Domain)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)3 Group (org.ovirt.engine.api.model.Group)3 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)3 Groups (org.ovirt.engine.api.model.Groups)2 Session (org.ovirt.engine.api.model.Session)2 Ssh (org.ovirt.engine.api.model.Ssh)2 Users (org.ovirt.engine.api.model.Users)2 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)2 ArrayList (java.util.ArrayList)1 AuthorizedKey (org.ovirt.engine.api.model.AuthorizedKey)1 BaseResource (org.ovirt.engine.api.model.BaseResource)1