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