Exemplo n.º 1
0
 protected XmlNode selectSingleNode(XmlNode node, String pattern, XmlNamespaceManager ns) {
   this.lastReadEntry = pattern;
   if (ns == null) {
     return node.selectSingleNode(pattern);
   }
   return node.selectSingleNode(pattern, ns);
 }
Exemplo n.º 2
0
  @Override
  protected void readGeneralData(XmlNode content) {
    // General Vm
    XmlNode node = content.SelectSingleNode(OvfProperties.NAME);
    if (node != null) {
      _vmTemplate.setName(node.innerText);
      name = _vmTemplate.getName();
    }
    node = content.SelectSingleNode(OvfProperties.TEMPLATE_ID);
    if (node != null) {
      if (StringUtils.isNotEmpty(node.innerText)) {
        _vmTemplate.setId(new Guid(node.innerText));
      }
    }

    node = content.SelectSingleNode(OvfProperties.IS_DISABLED);
    if (node != null) {
      _vmTemplate.setDisabled(Boolean.parseBoolean(node.innerText));
    }

    node = content.SelectSingleNode(OvfProperties.TRUSTED_SERVICE);
    if (node != null) {
      _vmTemplate.setTrustedService(Boolean.parseBoolean(node.innerText));
    }

    node = content.SelectSingleNode(OvfProperties.TEMPLATE_TYPE);
    if (node != null) {
      _vmTemplate.setTemplateType(VmEntityType.valueOf(node.innerText));
    }

    node = content.SelectSingleNode(OvfProperties.BASE_TEMPLATE_ID);
    if (node != null) {
      _vmTemplate.setBaseTemplateId(Guid.createGuidFromString(node.innerText));
    } else {
      // in case base template is missing, we assume it is a base template
      _vmTemplate.setBaseTemplateId(_vmTemplate.getId());
    }

    node = content.SelectSingleNode(OvfProperties.TEMPLATE_VERSION_NUMBER);
    if (node != null) {
      _vmTemplate.setTemplateVersionNumber(Integer.parseInt(node.innerText));
    }

    node = content.SelectSingleNode(OvfProperties.TEMPLATE_VERSION_NAME);
    if (node != null) {
      _vmTemplate.setTemplateVersionName(node.innerText);
    }

    node = content.SelectSingleNode("AutoStartup");
    if (node != null) {
      _vmTemplate.setAutoStartup(Boolean.parseBoolean(node.innerText));
    }
  }
Exemplo n.º 3
0
 @Override
 protected void readOsSection(XmlNode section) {
   _vmTemplate.setId(new Guid(section.attributes.get("ovf:id").getValue()));
   XmlNode node = section.SelectSingleNode("Description");
   if (node != null) {
     int osId = osRepository.getOsIdByUniqueName(node.innerText);
     _vmTemplate.setOsId(osId);
     _vmTemplate.setClusterArch(osRepository.getArchitectureFromOS(osId));
   } else {
     _vmTemplate.setClusterArch(ArchitectureType.undefined);
   }
 }
Exemplo n.º 4
0
  private static Map<String, Object> getMapNode(XmlNode node) {
    Map<String, Object> returnValue = new HashMap<>();

    NodeList list = node.getChildNodes();
    for (int index = 0; index < list.getLength(); ++index) {
      Node currNode = list.item(index);
      short nodeType = currNode.getNodeType();
      if (nodeType == Node.ELEMENT_NODE) {
        NodeList childNodes = currNode.getChildNodes();
        // If the element node has only one child, then it contains the value
        if (childNodes.getLength() == 1) {
          Node valueNode = childNodes.item(0);
          if (valueNode.getNodeType() == Node.TEXT_NODE) {
            returnValue.put(currNode.getNodeName(), valueNode.getNodeValue());
          }
        } else if (childNodes.getLength() > 1) {
          // In this case, we have a nested map, so we parse it
          returnValue.put(currNode.getNodeName(), getMapNode(new XmlNode(currNode)));
        }
      }
    }

    return returnValue;
  }
Exemplo n.º 5
0
 protected XmlNodeList selectNodes(XmlNode node, String pattern) {
   this.lastReadEntry = pattern;
   return node.selectNodes(pattern);
 }
Exemplo n.º 6
0
  @Override
  protected void readDiskImageItem(XmlNode node) {
    final Guid guid = new Guid(node.SelectSingleNode("rasd:InstanceId", _xmlNS).innerText);

    DiskImage image =
        LinqUtils.firstOrNull(
            _images,
            new Predicate<DiskImage>() {
              @Override
              public boolean eval(DiskImage diskImage) {
                return diskImage.getImageId().equals(guid);
              }
            });
    image.setId(
        OvfParser.GetImageGrupIdFromImageFile(
            node.SelectSingleNode("rasd:HostResource", _xmlNS).innerText));
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText)) {
      image.setParentId(new Guid(node.SelectSingleNode("rasd:Parent", _xmlNS).innerText));
    }
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:Template", _xmlNS).innerText)) {
      image.setImageTemplateId(new Guid(node.SelectSingleNode("rasd:Template", _xmlNS).innerText));
    }
    image.setAppList(node.SelectSingleNode("rasd:ApplicationList", _xmlNS).innerText);
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText)) {
      image.setStorageIds(
          new ArrayList<Guid>(
              Arrays.asList(new Guid(node.SelectSingleNode("rasd:StorageId", _xmlNS).innerText))));
    }
    if (StringUtils.isNotEmpty(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText)) {
      image.setStoragePoolId(
          new Guid(node.SelectSingleNode("rasd:StoragePoolId", _xmlNS).innerText));
    }
    final Date creationDate =
        OvfParser.UtcDateStringToLocaDate(
            node.SelectSingleNode("rasd:CreationDate", _xmlNS).innerText);
    if (creationDate != null) {
      image.setCreationDate(creationDate);
    }
    final Date lastModified =
        OvfParser.UtcDateStringToLocaDate(
            node.SelectSingleNode("rasd:LastModified", _xmlNS).innerText);
    if (lastModified != null) {
      image.setLastModified(lastModified);
    }
    readManagedVmDevice(node, image.getId());
  }