Search in sources :

Example 1 with OVFVirtualHardwareItemTO

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

the class OVFHelper method getOVFVolumeInfoFromFile.

public List<DatadiskTO> getOVFVolumeInfoFromFile(String ovfFilePath, Document doc, String configurationId) throws InternalErrorException {
    if (StringUtils.isBlank(ovfFilePath)) {
        return null;
    }
    File ovfFile = new File(ovfFilePath);
    List<OVFVirtualHardwareItemTO> hardwareItems = getVirtualHardwareItemsFromDocumentTree(doc);
    List<OVFFile> files = extractFilesFromOvfDocumentTree(ovfFile, doc);
    List<OVFDisk> disks = extractDisksFromOvfDocumentTree(doc);
    List<OVFVirtualHardwareItemTO> diskHardwareItems = hardwareItems.stream().filter(x -> x.getResourceType() == OVFVirtualHardwareItemTO.HardwareResourceType.DiskDrive && hardwareItemContainsConfiguration(x, configurationId)).collect(Collectors.toList());
    return matchHardwareItemsToDiskAndFilesInformation(diskHardwareItems, files, disks, ovfFile.getParent());
}
Also used : OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) Arrays(java.util.Arrays) TransformerException(javax.xml.transform.TransformerException) StreamResult(javax.xml.transform.stream.StreamResult) InternalErrorException(com.cloud.exception.InternalErrorException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) NumberUtils(org.apache.commons.lang.math.NumberUtils) ResourceType(com.cloud.configuration.Resource.ResourceType) Logger(org.apache.log4j.Logger) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CollectionUtils(org.apache.commons.collections.CollectionUtils) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) LinkedList(java.util.LinkedList) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO) PrintWriter(java.io.PrintWriter) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) NodeList(org.w3c.dom.NodeList) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Pair(com.cloud.utils.Pair) Collectors(java.util.stream.Collectors) File(java.io.File) OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) CompressionUtil(com.cloud.utils.compression.CompressionUtil) List(java.util.List) Element(org.w3c.dom.Element) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal) NodeIterator(org.w3c.dom.traversal.NodeIterator) SAXException(org.xml.sax.SAXException) TransformerFactory(javax.xml.transform.TransformerFactory) NodeFilter(org.w3c.dom.traversal.NodeFilter) Collections(java.util.Collections) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) File(java.io.File)

Example 2 with OVFVirtualHardwareItemTO

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

the class OVFHelper method getVirtualHardwareItemsFromDocumentTree.

private List<OVFVirtualHardwareItemTO> getVirtualHardwareItemsFromDocumentTree(Document doc) {
    List<OVFVirtualHardwareItemTO> items = new LinkedList<>();
    if (doc == null) {
        return items;
    }
    NodeList hardwareSection = ovfParser.getElementsFromOVFDocument(doc, "VirtualHardwareSection");
    if (hardwareSection.getLength() == 0) {
        return items;
    }
    Node hardwareSectionNode = hardwareSection.item(0);
    NodeList childNodes = hardwareSectionNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node != null && (node.getNodeName().equals("Item") || node.getNodeName().equals("ovf:Item"))) {
            Element configuration = (Element) node;
            String configurationIds = ovfParser.getNodeAttribute(configuration, "configuration");
            String allocationUnits = ovfParser.getChildNodeValue(configuration, "AllocationUnits");
            String description = ovfParser.getChildNodeValue(configuration, "Description");
            String elementName = ovfParser.getChildNodeValue(configuration, "ElementName");
            String instanceID = ovfParser.getChildNodeValue(configuration, "InstanceID");
            String limit = ovfParser.getChildNodeValue(configuration, "Limit");
            String reservation = ovfParser.getChildNodeValue(configuration, "Reservation");
            String resourceType = ovfParser.getChildNodeValue(configuration, "ResourceType");
            String virtualQuantity = ovfParser.getChildNodeValue(configuration, "VirtualQuantity");
            String hostResource = ovfParser.getChildNodeValue(configuration, "HostResource");
            String addressOnParent = ovfParser.getChildNodeValue(configuration, "AddressOnParent");
            String parent = ovfParser.getChildNodeValue(configuration, "Parent");
            OVFVirtualHardwareItemTO item = new OVFVirtualHardwareItemTO();
            item.setConfigurationIds(configurationIds);
            item.setAllocationUnits(allocationUnits);
            item.setDescription(description);
            item.setElementName(elementName);
            item.setInstanceId(instanceID);
            item.setLimit(getLongValueFromString(limit));
            item.setReservation(getLongValueFromString(reservation));
            Integer resType = getIntValueFromString(resourceType);
            if (resType != null) {
                item.setResourceType(OVFVirtualHardwareItemTO.getResourceTypeFromId(resType));
            }
            item.setVirtualQuantity(getLongValueFromString(virtualQuantity));
            item.setHostResource(hostResource);
            item.setAddressOnParent(addressOnParent);
            item.setParent(parent);
            items.add(item);
        }
    }
    return items;
}
Also used : OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) LinkedList(java.util.LinkedList)

Example 3 with OVFVirtualHardwareItemTO

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

the class OVFHelper method getVirtualHardwareSectionFromDocument.

/**
 * Retrieve the virtual hardware section and its deployment options as configurations
 */
public OVFVirtualHardwareSectionTO getVirtualHardwareSectionFromDocument(Document doc) {
    List<OVFConfigurationTO> configurations = getDeploymentOptionsFromDocumentTree(doc);
    List<OVFVirtualHardwareItemTO> items = getVirtualHardwareItemsFromDocumentTree(doc);
    if (CollectionUtils.isNotEmpty(configurations)) {
        for (OVFConfigurationTO configuration : configurations) {
            List<OVFVirtualHardwareItemTO> confItems = items.stream().filter(x -> StringUtils.isNotBlank(x.getConfigurationIds()) && hardwareItemContainsConfiguration(x, configuration.getId())).collect(Collectors.toList());
            configuration.setHardwareItems(confItems);
        }
    }
    List<OVFVirtualHardwareItemTO> commonItems = null;
    if (CollectionUtils.isNotEmpty(items)) {
        commonItems = items.stream().filter(x -> StringUtils.isBlank(x.getConfigurationIds())).collect(Collectors.toList());
    }
    String minimumHardwareVersion = getMinimumHardwareVersionFromDocumentTree(doc);
    return new OVFVirtualHardwareSectionTO(configurations, commonItems, minimumHardwareVersion);
}
Also used : OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) Arrays(java.util.Arrays) TransformerException(javax.xml.transform.TransformerException) StreamResult(javax.xml.transform.stream.StreamResult) InternalErrorException(com.cloud.exception.InternalErrorException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) NumberUtils(org.apache.commons.lang.math.NumberUtils) ResourceType(com.cloud.configuration.Resource.ResourceType) Logger(org.apache.log4j.Logger) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CollectionUtils(org.apache.commons.collections.CollectionUtils) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) LinkedList(java.util.LinkedList) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO) PrintWriter(java.io.PrintWriter) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) NodeList(org.w3c.dom.NodeList) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Pair(com.cloud.utils.Pair) Collectors(java.util.stream.Collectors) File(java.io.File) OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) CompressionUtil(com.cloud.utils.compression.CompressionUtil) List(java.util.List) Element(org.w3c.dom.Element) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal) NodeIterator(org.w3c.dom.traversal.NodeIterator) SAXException(org.xml.sax.SAXException) TransformerFactory(javax.xml.transform.TransformerFactory) NodeFilter(org.w3c.dom.traversal.NodeFilter) Collections(java.util.Collections) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)

Example 4 with OVFVirtualHardwareItemTO

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

the class OVFHelper method matchHardwareItemsToDiskAndFilesInformation.

private List<DatadiskTO> matchHardwareItemsToDiskAndFilesInformation(List<OVFVirtualHardwareItemTO> diskHardwareItems, List<OVFFile> files, List<OVFDisk> disks, String ovfParentPath) throws InternalErrorException {
    List<DatadiskTO> diskTOs = new LinkedList<>();
    int diskNumber = 0;
    for (OVFVirtualHardwareItemTO diskItem : diskHardwareItems) {
        if (StringUtils.isBlank(diskItem.getHostResource())) {
            s_logger.error("Missing disk information for hardware item " + diskItem.getElementName() + " " + diskItem.getInstanceId());
            continue;
        }
        String diskId = extractDiskIdFromDiskHostResource(diskItem.getHostResource());
        OVFDisk diskDefinition = getDiskDefinitionFromDiskId(diskId, disks);
        if (diskDefinition == null) {
            s_logger.error("Missing disk definition for disk ID " + diskId);
        }
        OVFFile fileDefinition = getFileDefinitionFromDiskDefinition(diskDefinition._fileRef, files);
        DatadiskTO datadiskTO = generateDiskTO(fileDefinition, diskDefinition, ovfParentPath, diskNumber, diskItem);
        diskTOs.add(datadiskTO);
        diskNumber++;
    }
    List<OVFFile> isoFiles = files.stream().filter(x -> x.isIso).collect(Collectors.toList());
    for (OVFFile isoFile : isoFiles) {
        DatadiskTO isoTO = generateDiskTO(isoFile, null, ovfParentPath, diskNumber, null);
        diskTOs.add(isoTO);
        diskNumber++;
    }
    return diskTOs;
}
Also used : OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) Arrays(java.util.Arrays) TransformerException(javax.xml.transform.TransformerException) StreamResult(javax.xml.transform.stream.StreamResult) InternalErrorException(com.cloud.exception.InternalErrorException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) NumberUtils(org.apache.commons.lang.math.NumberUtils) ResourceType(com.cloud.configuration.Resource.ResourceType) Logger(org.apache.log4j.Logger) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CollectionUtils(org.apache.commons.collections.CollectionUtils) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) LinkedList(java.util.LinkedList) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO) PrintWriter(java.io.PrintWriter) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) NodeList(org.w3c.dom.NodeList) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Pair(com.cloud.utils.Pair) Collectors(java.util.stream.Collectors) File(java.io.File) OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) CompressionUtil(com.cloud.utils.compression.CompressionUtil) List(java.util.List) Element(org.w3c.dom.Element) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal) NodeIterator(org.w3c.dom.traversal.NodeIterator) SAXException(org.xml.sax.SAXException) TransformerFactory(javax.xml.transform.TransformerFactory) NodeFilter(org.w3c.dom.traversal.NodeFilter) Collections(java.util.Collections) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) LinkedList(java.util.LinkedList)

Example 5 with OVFVirtualHardwareItemTO

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

the class OVAProcessor method createOvfInformationTO.

private OVFInformationTO createOvfInformationTO(OVFHelper ovfHelper, Document doc, String ovfFilePath) throws InternalErrorException {
    OVFInformationTO ovfInformationTO = new OVFInformationTO();
    List<DatadiskTO> disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, doc, null);
    if (CollectionUtils.isNotEmpty(disks)) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath));
        }
        ovfInformationTO.setDisks(disks);
    }
    List<OVFNetworkTO> nets = ovfHelper.getNetPrerequisitesFromDocument(doc);
    if (CollectionUtils.isNotEmpty(nets)) {
        LOGGER.info("Found " + nets.size() + " prerequisite networks");
        ovfInformationTO.setNetworks(nets);
    } else if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(String.format("no net prerequisites found in template %s", ovfFilePath));
    }
    List<OVFPropertyTO> ovfProperties = ovfHelper.getConfigurableOVFPropertiesFromDocument(doc);
    if (CollectionUtils.isNotEmpty(ovfProperties)) {
        LOGGER.info("Found " + ovfProperties.size() + " configurable OVF properties");
        ovfInformationTO.setProperties(ovfProperties);
    } else if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(String.format("no ovf properties found in template %s", ovfFilePath));
    }
    OVFVirtualHardwareSectionTO hardwareSection = ovfHelper.getVirtualHardwareSectionFromDocument(doc);
    List<OVFConfigurationTO> configurations = hardwareSection.getConfigurations();
    if (CollectionUtils.isNotEmpty(configurations)) {
        LOGGER.info("Found " + configurations.size() + " deployment option configurations");
    }
    List<OVFVirtualHardwareItemTO> hardwareItems = hardwareSection.getCommonHardwareItems();
    if (CollectionUtils.isNotEmpty(hardwareItems)) {
        LOGGER.info("Found " + hardwareItems.size() + " virtual hardware items");
    }
    if (StringUtils.isNotBlank(hardwareSection.getMinimiumHardwareVersion())) {
        LOGGER.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion());
    }
    ovfInformationTO.setHardwareSection(hardwareSection);
    List<OVFEulaSectionTO> eulaSections = ovfHelper.getEulaSectionsFromDocument(doc);
    if (CollectionUtils.isNotEmpty(eulaSections)) {
        LOGGER.info("Found " + eulaSections.size() + " license agreements");
        ovfInformationTO.setEulaSections(eulaSections);
    }
    Pair<String, String> guestOsPair = ovfHelper.getOperatingSystemInfoFromDocument(doc);
    if (guestOsPair != null) {
        LOGGER.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second());
        ovfInformationTO.setGuestOsInfo(guestOsPair);
    }
    return ovfInformationTO;
}
Also used : OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) OVFConfigurationTO(com.cloud.agent.api.to.deployasis.OVFConfigurationTO) OVFNetworkTO(com.cloud.agent.api.to.deployasis.OVFNetworkTO) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO) OVFEulaSectionTO(com.cloud.agent.api.to.deployasis.OVFEulaSectionTO) OVFVirtualHardwareItemTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) OVFVirtualHardwareSectionTO(com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)

Aggregations

OVFVirtualHardwareItemTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareItemTO)5 DatadiskTO (com.cloud.agent.api.to.DatadiskTO)4 OVFConfigurationTO (com.cloud.agent.api.to.deployasis.OVFConfigurationTO)4 OVFEulaSectionTO (com.cloud.agent.api.to.deployasis.OVFEulaSectionTO)4 OVFNetworkTO (com.cloud.agent.api.to.deployasis.OVFNetworkTO)4 OVFPropertyTO (com.cloud.agent.api.to.deployasis.OVFPropertyTO)4 OVFVirtualHardwareSectionTO (com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO)4 LinkedList (java.util.LinkedList)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 ResourceType (com.cloud.configuration.Resource.ResourceType)3 InternalErrorException (com.cloud.exception.InternalErrorException)3 Pair (com.cloud.utils.Pair)3 CompressionUtil (com.cloud.utils.compression.CompressionUtil)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 File (java.io.File)3 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3