Search in sources :

Example 1 with OVFPropertyTO

use of com.cloud.agent.api.to.deployasis.OVFPropertyTO 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 OVFPropertyTO

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

the class TemplateDeployAsIsDetailsDaoImpl method findPropertyByTemplateAndKey.

@Override
public OVFPropertyTO findPropertyByTemplateAndKey(long templateId, String key) {
    SearchCriteria<TemplateDeployAsIsDetailVO> sc = createSearchCriteria();
    sc.addAnd("resourceId", SearchCriteria.Op.EQ, templateId);
    sc.addAnd("name", SearchCriteria.Op.EQ, key.startsWith(DeployAsIsConstants.PROPERTY_PREFIX) ? key : DeployAsIsConstants.PROPERTY_PREFIX + key);
    OVFPropertyTO property = null;
    TemplateDeployAsIsDetailVO detail = findOneBy(sc);
    if (detail != null) {
        property = gson.fromJson(detail.getValue(), OVFPropertyTO.class);
    }
    return property;
}
Also used : TemplateDeployAsIsDetailVO(com.cloud.deployasis.TemplateDeployAsIsDetailVO) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO)

Example 3 with OVFPropertyTO

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

the class OVFHelper method createOVFPropertyFromNode.

/**
 * Create OVFProperty class from the parsed node. Note that some fields may not be present.
 * The key attribute is required
 */
protected OVFPropertyTO createOVFPropertyFromNode(Node node, int index, String category) {
    Element element = (Element) node;
    String key = ovfParser.getNodeAttribute(element, "key");
    if (StringUtils.isBlank(key)) {
        return null;
    }
    String value = ovfParser.getNodeAttribute(element, "value");
    String type = ovfParser.getNodeAttribute(element, "type");
    String qualifiers = ovfParser.getNodeAttribute(element, "qualifiers");
    String userConfigurableStr = ovfParser.getNodeAttribute(element, "userConfigurable");
    boolean userConfigurable = StringUtils.isNotBlank(userConfigurableStr) && userConfigurableStr.equalsIgnoreCase("true");
    String passStr = ovfParser.getNodeAttribute(element, "password");
    boolean password = StringUtils.isNotBlank(passStr) && passStr.equalsIgnoreCase("true");
    String label = ovfParser.getChildNodeValue(node, "Label");
    String description = ovfParser.getChildNodeValue(node, "Description");
    s_logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category) + " with key = " + key);
    return new OVFPropertyTO(key, type, value, qualifiers, userConfigurable, label, description, password, index, category);
}
Also used : Element(org.w3c.dom.Element) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO)

Example 4 with OVFPropertyTO

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

the class OVFHelper method getConfigurableOVFPropertiesFromDocument.

/**
 * Retrieve OVF properties from a parsed OVF file including its category (if available) and in-order,
 * with attribute 'ovf:userConfigurable' set to true.
 */
public List<OVFPropertyTO> getConfigurableOVFPropertiesFromDocument(Document doc) {
    List<OVFPropertyTO> props = new ArrayList<>();
    if (doc == null) {
        return props;
    }
    int propertyIndex = 0;
    NodeList productSections = ovfParser.getElementsFromOVFDocument(doc, "ProductSection");
    if (productSections != null) {
        String lastCategoryFound = null;
        for (int i = 0; i < productSections.getLength(); i++) {
            Node node = productSections.item(i);
            if (node == null) {
                continue;
            }
            NodeList childNodes = node.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node child = childNodes.item(j);
                if (child == null) {
                    continue;
                }
                if (child.getNodeName().equalsIgnoreCase("Category") || child.getNodeName().endsWith(":Category")) {
                    lastCategoryFound = child.getTextContent();
                    s_logger.info("Category found " + lastCategoryFound);
                } else if (child.getNodeName().equalsIgnoreCase("Property") || child.getNodeName().endsWith(":Property")) {
                    OVFPropertyTO prop = createOVFPropertyFromNode(child, propertyIndex, lastCategoryFound);
                    if (prop != null && prop.isUserConfigurable()) {
                        props.add(prop);
                        propertyIndex++;
                    }
                }
            }
        }
    }
    return props;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) OVFPropertyTO(com.cloud.agent.api.to.deployasis.OVFPropertyTO)

Example 5 with OVFPropertyTO

use of com.cloud.agent.api.to.deployasis.OVFPropertyTO 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

OVFPropertyTO (com.cloud.agent.api.to.deployasis.OVFPropertyTO)9 OVFNetworkTO (com.cloud.agent.api.to.deployasis.OVFNetworkTO)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 UserVmDeployAsIsDetailVO (com.cloud.deployasis.UserVmDeployAsIsDetailVO)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)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 Pair (com.cloud.utils.Pair)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1