Search in sources :

Example 51 with PropertyFilterSpec

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();
    }
}
Also used : PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) HashSet(java.util.HashSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) ImageService(com.vmware.photon.controller.model.resources.ImageService) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ObjectContent(com.vmware.vim25.ObjectContent) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) IOException(java.io.IOException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Phaser(java.util.concurrent.Phaser) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) Phaser(java.util.concurrent.Phaser) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 52 with PropertyFilterSpec

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;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 53 with PropertyFilterSpec

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]);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 54 with PropertyFilterSpec

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()]);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson)

Example 55 with PropertyFilterSpec

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;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Aggregations

PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)68 ObjectSpec (com.vmware.vim25.ObjectSpec)60 PropertySpec (com.vmware.vim25.PropertySpec)60 TraversalSpec (com.vmware.vim25.TraversalSpec)47 ObjectContent (com.vmware.vim25.ObjectContent)46 ArrayList (java.util.ArrayList)37 DynamicProperty (com.vmware.vim25.DynamicProperty)21 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)19 SelectionSpec (com.vmware.vim25.SelectionSpec)11 Gson (com.google.gson.Gson)10 RetrieveOptions (com.vmware.vim25.RetrieveOptions)6 RetrieveResult (com.vmware.vim25.RetrieveResult)6 HashMap (java.util.HashMap)6 Pair (com.cloud.utils.Pair)4 ObjectSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.ObjectSpecBuilder)4 PropertyFilterSpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertyFilterSpecBuilder)4 PropertySpecBuilder (com.vmware.photon.controller.model.adapters.vsphere.util.builders.PropertySpecBuilder)4 ObjectUpdate (com.vmware.vim25.ObjectUpdate)4 PropertyFilterUpdate (com.vmware.vim25.PropertyFilterUpdate)4 UpdateSet (com.vmware.vim25.UpdateSet)4