Search in sources :

Example 16 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method testUpdate.

@Test
public void testUpdate() {
    addVmInit();
    VmInit init = vmInitDao.get(EXISTING_VM);
    init.setHostname("newhostname");
    vmInitDao.update(init);
    VmInit result = vmInitDao.get(init.getId());
    assertNotNull(result);
    assertEquals("newhostname", result.getHostname());
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Test(org.junit.Test)

Example 17 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method testRemove.

@Test
public void testRemove() {
    addVmInit();
    VmInit result = vmInitDao.get(EXISTING_VM);
    assertNotNull(result);
    vmInitDao.remove(EXISTING_VM);
    result = vmInitDao.get(EXISTING_VM);
    assertNull(result);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Test(org.junit.Test)

Example 18 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmMapper method map.

@Mapping(from = Vm.class, to = VmStatic.class)
public static VmStatic map(Vm vm, VmStatic template) {
    VmStatic staticVm = template != null ? template : new VmStatic();
    mapVmBaseModelToEntity(staticVm, vm);
    if (!vm.isSetMemory() && staticVm.getMemSizeMb() == 0) {
        // TODO: Get rid of this logic code when Backend supports default memory.
        staticVm.setMemSizeMb(DEFAULT_MEMORY_SIZE);
    }
    if (vm.isSetTemplate()) {
        if (vm.getTemplate().getId() != null) {
            staticVm.setVmtGuid(GuidUtils.asGuid(vm.getTemplate().getId()));
        }
        // it will be handled by the backend.
        if (vm.isSetUseLatestTemplateVersion()) {
            staticVm.setUseLatestVersion(vm.isUseLatestTemplateVersion());
        }
    }
    if (vm.isSetCpu()) {
        if (vm.getCpu().isSetMode()) {
            staticVm.setUseHostCpuFlags(vm.getCpu().getMode() == CpuMode.HOST_PASSTHROUGH);
        }
        if (vm.getCpu().isSetCpuTune()) {
            staticVm.setCpuPinning(cpuTuneToString(vm.getCpu().getCpuTune()));
        }
    }
    if (vm.isSetInitialization()) {
        staticVm.setVmInit(InitializationMapper.map(vm.getInitialization(), staticVm.getVmInit()));
    }
    // if the Domain set via VmInit we ignore it
    if (vm.isSetDomain() && vm.getDomain().isSetName()) {
        if (staticVm.getVmInit() == null) {
            staticVm.setVmInit(new VmInit());
        }
        // We don't want to override the domain if it set via the Initialization object
        if (!vm.isSetInitialization() || !vm.getInitialization().isSetDomain()) {
            staticVm.getVmInit().setDomain(vm.getDomain().getName());
        }
    }
    if (vm.isSetNumaTuneMode()) {
        staticVm.setNumaTuneMode(map(vm.getNumaTuneMode(), null));
    }
    if (vm.isSetExternalHostProvider()) {
        String providerId = vm.getExternalHostProvider().getId();
        staticVm.setProviderId(providerId == null ? null : GuidUtils.asGuid(providerId));
    }
    return staticVm;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 19 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit 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 20 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class TemplateMapper method map.

@Mapping(from = Template.class, to = VmStatic.class)
public static VmStatic map(Template model, VmStatic incoming) {
    VmStatic staticVm = incoming != null ? incoming : new VmStatic();
    mapVmBaseModelToEntity(staticVm, model);
    if (model.isSetInitialization()) {
        staticVm.setVmInit(InitializationMapper.map(model.getInitialization(), staticVm.getVmInit()));
    }
    if (model.isSetDomain() && model.getDomain().isSetName()) {
        if (staticVm.getVmInit() == null) {
            staticVm.setVmInit(new VmInit());
        }
        staticVm.getVmInit().setDomain(model.getDomain().getName());
    }
    return staticVm;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Aggregations

VmInit (org.ovirt.engine.core.common.businessentities.VmInit)34 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)14 Pair (org.ovirt.engine.core.common.utils.Pair)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 Guid (org.ovirt.engine.core.compat.Guid)3 List (java.util.List)2 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Before (org.junit.Before)1