use of com.vmware.vim25.PropertyFilterSpec in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method processAllTemplates.
private void processAllTemplates(Set<String> oldImages, String endpointLink, String taskLink, EnumerationClient client, List<String> tenantLinks) throws RuntimeFaultFaultMsg {
PropertyFilterSpec spec = client.createVmFilterSpec(client.getDatacenter());
for (List<ObjectContent> page : client.retrieveObjects(spec)) {
Phaser phaser = new Phaser(1);
for (ObjectContent oc : page) {
if (!VimUtils.isVirtualMachine(oc.getObj())) {
continue;
}
VmOverlay vm = new VmOverlay(oc);
if (!vm.isTemplate()) {
continue;
}
ImageState state = makeImageFromTemplate(vm);
state.documentSelfLink = buildStableImageLink(endpointLink, state.id);
state.endpointLink = endpointLink;
state.tenantLinks = tenantLinks;
state.regionId = VimUtils.convertMoRefToString(client.getDatacenter());
oldImages.remove(state.documentSelfLink);
phaser.register();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(), ImageService.FACTORY_LINK)).setBody(state).setCompletion((o, e) -> phaser.arrive()).sendWith(this);
}
phaser.arriveAndAwaitAdvance();
}
}
use of com.vmware.vim25.PropertyFilterSpec in project cloudstack by apache.
the class VirtualMachineMO method getAllDatastores.
public List<DatastoreMO> getAllDatastores() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.getPathSet().add("name");
TraversalSpec vmDatastoreTraversal = new TraversalSpec();
vmDatastoreTraversal.setType("VirtualMachine");
vmDatastoreTraversal.setPath("datastore");
vmDatastoreTraversal.setName("vmDatastoreTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(vmDatastoreTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
List<DatastoreMO> datastores = new ArrayList<DatastoreMO>();
if (CollectionUtils.isNotEmpty(ocs)) {
for (ObjectContent oc : ocs) {
datastores.add(new DatastoreMO(_context, oc.getObj()));
}
}
return datastores;
}
use of com.vmware.vim25.PropertyFilterSpec in project cloudstack by apache.
the class VirtualMachineMO method getNetworks.
public String[] getNetworks() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.getPathSet().add("name");
TraversalSpec vm2NetworkTraversal = new TraversalSpec();
vm2NetworkTraversal.setType("VirtualMachine");
vm2NetworkTraversal.setPath("network");
vm2NetworkTraversal.setName("vm2NetworkTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(vm2NetworkTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
List<String> networks = new ArrayList<String>();
if (ocs != null && ocs.size() > 0) {
for (ObjectContent oc : ocs) {
networks.add(oc.getPropSet().get(0).getVal().toString());
}
}
return networks.toArray(new String[0]);
}
use of com.vmware.vim25.PropertyFilterSpec in project cloudstack by apache.
the class HostMO method getVmPropertiesOnHyperHost.
@Override
public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() for VM properties. target MOR: " + _mor.getValue() + ", properties: " + new Gson().toJson(propertyPaths));
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
TraversalSpec host2VmTraversal = new TraversalSpec();
host2VmTraversal.setType("HostSystem");
host2VmTraversal.setPath("vm");
host2VmTraversal.setName("host2VmTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(host2VmTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> properties = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - retrieveProperties() done");
return properties.toArray(new ObjectContent[properties.size()]);
}
use of com.vmware.vim25.PropertyFilterSpec in project cloudstack by apache.
the class HostMO method getNetworkMor.
public ManagedObjectReference getNetworkMor(String portGroupName) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.getPathSet().add("summary.name");
TraversalSpec host2NetworkTraversal = new TraversalSpec();
host2NetworkTraversal.setType("HostSystem");
host2NetworkTraversal.setPath("network");
host2NetworkTraversal.setName("host2NetworkTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(host2NetworkTraversal);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.getPropSet().add(pSpec);
pfSpec.getObjectSet().add(oSpec);
List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
pfSpecArr.add(pfSpec);
List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
if (ocs != null) {
for (ObjectContent oc : ocs) {
List<DynamicProperty> props = oc.getPropSet();
if (props != null) {
for (DynamicProperty prop : props) {
if (prop.getVal().equals(portGroupName))
return oc.getObj();
}
}
}
}
return null;
}
Aggregations