Search in sources :

Example 1 with OVFNetworkTO

use of com.cloud.agent.api.to.deployasis.OVFNetworkTO in project cloudstack by apache.

the class DeployAsIsHelperImpl method persistTemplateOVFInformation.

private void persistTemplateOVFInformation(long templateId, OVFInformationTO ovfInformationTO) {
    List<OVFPropertyTO> ovfProperties = ovfInformationTO.getProperties();
    List<OVFNetworkTO> networkRequirements = ovfInformationTO.getNetworks();
    OVFVirtualHardwareSectionTO ovfHardwareSection = ovfInformationTO.getHardwareSection();
    List<OVFEulaSectionTO> eulaSections = ovfInformationTO.getEulaSections();
    Pair<String, String> guestOsInfo = ovfInformationTO.getGuestOsInfo();
    if (CollectionUtils.isNotEmpty(ovfProperties)) {
        persistTemplateDeployAsIsInformationTOList(templateId, ovfProperties);
    }
    if (CollectionUtils.isNotEmpty(networkRequirements)) {
        persistTemplateDeployAsIsInformationTOList(templateId, networkRequirements);
    }
    if (CollectionUtils.isNotEmpty(eulaSections)) {
        persistTemplateDeployAsIsInformationTOList(templateId, eulaSections);
    }
    String minimumHardwareVersion = null;
    if (ovfHardwareSection != null) {
        if (CollectionUtils.isNotEmpty(ovfHardwareSection.getConfigurations())) {
            persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getConfigurations());
        }
        if (CollectionUtils.isNotEmpty(ovfHardwareSection.getCommonHardwareItems())) {
            persistTemplateDeployAsIsInformationTOList(templateId, ovfHardwareSection.getCommonHardwareItems());
        }
        minimumHardwareVersion = ovfHardwareSection.getMinimiumHardwareVersion();
    }
    if (guestOsInfo != null) {
        String osType = guestOsInfo.first();
        String osDescription = guestOsInfo.second();
        LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription);
        handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion);
    }
}
Also used : OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)

Example 2 with OVFNetworkTO

use of com.cloud.agent.api.to.deployasis.OVFNetworkTO in project cloudstack by apache.

the class UserVmManagerImpl method getVmOvfNetworkMapping.

private LinkedHashMap<Integer, Long> getVmOvfNetworkMapping(DataCenter zone, Account owner, VirtualMachineTemplate template, Map<Integer, Long> vmNetworkMapping) throws InsufficientCapacityException, ResourceAllocationException {
    LinkedHashMap<Integer, Long> mapping = new LinkedHashMap<>();
    if (ImageFormat.OVA.equals(template.getFormat())) {
        List<OVFNetworkTO> OVFNetworkTOList = templateDeployAsIsDetailsDao.listNetworkRequirementsByTemplateId(template.getId());
        if (CollectionUtils.isNotEmpty(OVFNetworkTOList)) {
            Network lastMappedNetwork = null;
            for (OVFNetworkTO OVFNetworkTO : OVFNetworkTOList) {
                Long networkId = vmNetworkMapping.get(OVFNetworkTO.getInstanceID());
                if (networkId == null && lastMappedNetwork == null) {
                    lastMappedNetwork = getNetworkForOvfNetworkMapping(zone, owner);
                }
                if (networkId == null) {
                    networkId = lastMappedNetwork.getId();
                }
                mapping.put(OVFNetworkTO.getInstanceID(), networkId);
            }
        }
    }
    return mapping;
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with OVFNetworkTO

use of com.cloud.agent.api.to.deployasis.OVFNetworkTO in project cloudstack by apache.

the class OVFHelper method getNetworksFromDocumentTree.

private Map<String, OVFNetworkTO> getNetworksFromDocumentTree(Document doc) {
    NodeList networkElements = ovfParser.getElementsFromOVFDocument(doc, "Network");
    Map<String, OVFNetworkTO> nets = new HashMap<>();
    for (int i = 0; i < networkElements.getLength(); i++) {
        Element networkElement = (Element) networkElements.item(i);
        String networkName = ovfParser.getNodeAttribute(networkElement, "name");
        String description = ovfParser.getChildNodeValue(networkElement, "Description");
        OVFNetworkTO network = new OVFNetworkTO();
        network.setName(networkName);
        network.setNetworkDescription(description);
        nets.put(networkName, network);
    }
    if (s_logger.isTraceEnabled()) {
        s_logger.trace(String.format("found %d networks in template", nets.size()));
    }
    return nets;
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO)

Example 4 with OVFNetworkTO

use of com.cloud.agent.api.to.deployasis.OVFNetworkTO in project cloudstack by apache.

the class OVFHelper method matchNicsToNets.

private void matchNicsToNets(Map<String, OVFNetworkTO> nets, Node systemElement) {
    final DocumentTraversal traversal = (DocumentTraversal) systemElement;
    final NodeIterator iterator = traversal.createNodeIterator(systemElement, NodeFilter.SHOW_ELEMENT, null, true);
    if (s_logger.isTraceEnabled()) {
        s_logger.trace(String.format("starting out with %d network-prerequisites, parsing hardware", nets.size()));
    }
    int nicCount = 0;
    for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
        final Element e = (Element) n;
        if ("rasd:Connection".equals(e.getTagName())) {
            nicCount++;
            // should be in our nets
            String name = e.getTextContent();
            if (nets.get(name) == null) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name));
                }
                nets.put(name, new OVFNetworkTO());
            }
            OVFNetworkTO thisNet = nets.get(name);
            if (e.getParentNode() != null) {
                fillNicPrerequisites(thisNet, e.getParentNode());
            }
        }
    }
    if (s_logger.isTraceEnabled()) {
        s_logger.trace(String.format("ending up with %d network-prerequisites, parsed %d nics", nets.size(), nicCount));
    }
}
Also used : NodeIterator(org.w3c.dom.traversal.NodeIterator) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO)

Example 5 with OVFNetworkTO

use of com.cloud.agent.api.to.deployasis.OVFNetworkTO in project cloudstack by apache.

the class DownloadAnswerTest method properties.

@Test
public void properties() {
    List<OVFPropertyTO> properties = new ArrayList<>();
    properties.add(new OVFPropertyTO());
    List<OVFNetworkTO> networks = new ArrayList<>();
    networks.add(new OVFNetworkTO());
    OVFInformationTO informationTO = new OVFInformationTO();
    informationTO.setProperties(properties);
    informationTO.setNetworks(networks);
    answer.setOvfInformationTO(informationTO);
    String json = gson.toJson(answer);
    Answer received = gson.fromJson(json, Answer.class);
    Assert.assertEquals(received, answer);
}
Also used : Answer(com.cloud.agent.api.Answer) OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) ArrayList(java.util.ArrayList) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) Test(org.junit.Test)

Aggregations

OVFNetworkTO (com.cloud.agent.api.to.deployasis.OVFNetworkTO)7 OVFPropertyTO (com.cloud.agent.api.to.deployasis.OVFPropertyTO)3 OVFInformationTO (com.cloud.agent.api.to.OVFInformationTO)2 OVFEulaSectionTO (com.cloud.agent.api.to.deployasis.OVFEulaSectionTO)2 OVFVirtualHardwareSectionTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)2 ArrayList (java.util.ArrayList)2 Element (org.w3c.dom.Element)2 Answer (com.cloud.agent.api.Answer)1 DatadiskTO (com.cloud.agent.api.to.DatadiskTO)1 OVFConfigurationTO (com.cloud.agent.api.to.deployasis.OVFConfigurationTO)1 OVFVirtualHardwareItemTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO)1 TemplateDeployAsIsDetailVO (com.cloud.deployasis.TemplateDeployAsIsDetailVO)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 DocumentTraversal (org.w3c.dom.traversal.DocumentTraversal)1