Search in sources :

Example 6 with File

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

the class CdRomMapper method map.

/**
 * Bi-directional Cdrom->VmTemplate not required as
 * template device collections are always read-only
 */
@Mapping(from = VmTemplate.class, to = Cdrom.class)
public static Cdrom map(VmTemplate entity, Cdrom template) {
    Cdrom model = template != null ? template : new Cdrom();
    model.setId(CDROM_ID.toString());
    if (!StringUtils.isEmpty(entity.getIsoPath())) {
        model.setFile(new File());
        model.getFile().setId(entity.getIsoPath());
    }
    return model;
}
Also used : Cdrom(org.ovirt.engine.api.model.Cdrom) File(org.ovirt.engine.api.model.File)

Example 7 with File

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

the class CdRomMapper method map.

@Mapping(from = VM.class, to = Cdrom.class)
public static Cdrom map(VM entity, Cdrom template) {
    Cdrom model = template != null ? template : new Cdrom();
    model.setId(CDROM_ID.toString());
    if (!StringUtils.isEmpty(entity.getStaticData().getIsoPath())) {
        model.setFile(new File());
        model.getFile().setId(entity.getStaticData().getIsoPath());
    }
    return model;
}
Also used : Cdrom(org.ovirt.engine.api.model.Cdrom) File(org.ovirt.engine.api.model.File)

Example 8 with File

use of org.ovirt.engine.api.model.File 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 9 with File

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

the class BackendVmCdromsResourceTest method getCdrom.

private Cdrom getCdrom() {
    Cdrom model = new Cdrom();
    model.setFile(new File());
    model.getFile().setId(ISO_PATH);
    return model;
}
Also used : Cdrom(org.ovirt.engine.api.model.Cdrom) File(org.ovirt.engine.api.model.File)

Example 10 with File

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

the class BackendVmCdromsResourceTest method testAddIncompleteParameters.

@Test
public void testAddIncompleteParameters() throws Exception {
    Cdrom model = new Cdrom();
    model.setName(NAMES[0]);
    model.setFile(new File());
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Cdrom", "add", "file.id");
    }
}
Also used : Cdrom(org.ovirt.engine.api.model.Cdrom) WebApplicationException(javax.ws.rs.WebApplicationException) File(org.ovirt.engine.api.model.File) Test(org.junit.Test)

Aggregations

File (org.ovirt.engine.api.model.File)11 Cdrom (org.ovirt.engine.api.model.Cdrom)6 Test (org.junit.Test)3 Host (org.ovirt.engine.api.model.Host)2 StorageDomain (org.ovirt.engine.api.model.StorageDomain)2 Vm (org.ovirt.engine.api.model.Vm)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Action (org.ovirt.engine.api.model.Action)1 AuthorizedKey (org.ovirt.engine.api.model.AuthorizedKey)1 Cdroms (org.ovirt.engine.api.model.Cdroms)1 Cluster (org.ovirt.engine.api.model.Cluster)1 ExternalVmImport (org.ovirt.engine.api.model.ExternalVmImport)1 Files (org.ovirt.engine.api.model.Files)1 Floppies (org.ovirt.engine.api.model.Floppies)1 Floppy (org.ovirt.engine.api.model.Floppy)1 Nic (org.ovirt.engine.api.model.Nic)1 Payload (org.ovirt.engine.api.model.Payload)1 User (org.ovirt.engine.api.model.User)1