use of com.vmware.photon.controller.model.adapters.vsphere.CustomProperties in project photon-model by vmware.
the class OvfParser method parse.
/**
* Produces several descriptions based on the different hardware configuration defined in the
* OVF descriptor.
*
* @param doc
* OVF descriptor to parse
* @param template
* use as a basis of the ComputeDescription.
* @return
*/
public List<ComputeDescription> parse(Document doc, ComputeDescription template) {
CustomProperties cust = CustomProperties.of(template);
NodeList props = nodes(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Property");
for (Element prop : iterableElements(props)) {
String userConfigurable = attr("ovf:userConfigurable", prop);
if (!"true".equals(userConfigurable)) {
continue;
}
String key = attr("ovf:key", prop);
Element section = (Element) prop.getParentNode();
String instanceId = attr("ovf:instance", section);
String classId = attr("ovf:class", section);
String description = text(prop, "ovf:Description/text()");
cust.put(property(classId, key, instanceId), description);
}
if (template.name == null) {
String productName = text(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Product/text()");
String productVersion = text(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:ProductSection/ovf:Version/text()");
template.name = productName + " " + productVersion;
}
NodeList hwItems = nodes(doc, "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item");
Map<String, ComputeDescription> hwByConfigName = new HashMap<>();
for (Element item : iterableElements(hwItems)) {
String configName = attr("ovf:configuration", item);
ComputeDescription desc = hwByConfigName.get(configName);
if (desc == null) {
desc = Utils.clone(template);
desc.documentSelfLink = UUID.randomUUID().toString();
desc.id = "ovf-imported-" + desc.documentSelfLink;
desc.customProperties.put(PROP_OVF_CONFIGURATION, configName);
hwByConfigName.put(configName, desc);
}
String resourceType = text(item, "rasd:ResourceType/text()");
if (RESOURCE_TYPE_CPU.equals(resourceType)) {
long qty = Long.parseLong(text(item, "rasd:VirtualQuantity/text()"));
desc.cpuCount = qty;
}
if (RESOURCE_TYPE_MEMORY.equals(resourceType)) {
double qty = Double.parseDouble(text(item, "rasd:VirtualQuantity/text()"));
long mult = memAllocationUnit2Multiplier(text(item, "rasd:AllocationUnits/text()"));
desc.totalMemoryBytes = (long) (qty * mult);
}
}
for (Iterator<ComputeDescription> it = hwByConfigName.values().iterator(); it.hasNext(); ) {
ComputeDescription desc = it.next();
if (desc.cpuCount <= 0) {
it.remove();
}
}
return new ArrayList<>(hwByConfigName.values());
}
use of com.vmware.photon.controller.model.adapters.vsphere.CustomProperties in project photon-model by vmware.
the class NetworkDeviceBackingFactory method getDistributedPortBackingInfo.
/**
* Backing info for distributed virtual switch port or portgroup
*/
private static VirtualEthernetCardDistributedVirtualPortBackingInfo getDistributedPortBackingInfo(CustomProperties props, QueryConfigTargetRequest queryConfigTargetRequest) {
DistributedVirtualSwitchPortConnection port = new DistributedVirtualSwitchPortConnection();
String portGroupKey = props.getString(DvsProperties.PORT_GROUP_KEY);
String dvsUuid = props.getString(DvsProperties.DVS_UUID);
if (StringUtil.isNullOrEmpty(dvsUuid)) {
// NSX-V sets the value to a list of dvPortGroupsKeys as the logical switch is
// created in a transport zone which could be associated with multiple clusters.
// Hence dvPortGroup is created per cluster. The configTarget will filter based on
// the cluster where machine is being provisioned.
Type listType = new TypeToken<ArrayList<String>>() {
}.getType();
final List<String> portGroupIds = Utils.fromJson(portGroupKey, listType);
// NSX-V doesn't have UUID information in its API response
DistributedVirtualPortgroupInfo info = null;
try {
ConfigTarget configTarget = queryConfigTargetRequest.getConfigTarget();
info = configTarget.getDistributedVirtualPortgroup().stream().filter(d -> {
return portGroupIds.contains(d.getPortgroupKey());
}).findFirst().orElse(null);
} catch (Exception e) {
logger.error("getDistributedPortBackingInfo::Failed to get dvportgroup info.", e);
}
if (info == null) {
throw new IllegalArgumentException("getDistributedPortBackingInfo::The port group " + "information is not found for key: " + portGroupKey);
}
portGroupKey = info.getPortgroupKey();
dvsUuid = info.getSwitchUuid();
}
port.setPortgroupKey(portGroupKey);
port.setSwitchUuid(dvsUuid);
VirtualEthernetCardDistributedVirtualPortBackingInfo backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
backing.setPort(port);
return backing;
}
Aggregations