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);
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations