Search in sources :

Example 26 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project photon-model by vmware.

the class Finder method ancestrySet.

private List<ObjectContent> ancestrySet(ManagedObjectReference ref) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ObjectSpec ospec = new ObjectSpec();
    ospec.setObj(ref);
    ospec.setSkip(false);
    TraversalSpec tspec = new TraversalSpec();
    tspec.setSkip(false);
    tspec.setPath("parent");
    tspec.setType("ManagedEntity");
    tspec.setName("traverseParent");
    SelectionSpec selSpec = new SelectionSpec();
    selSpec.setName("traverseParent");
    tspec.getSelectSet().add(selSpec);
    ospec.getSelectSet().add(tspec);
    PropertySpec pspec = new PropertySpec();
    pspec.setType("ManagedEntity");
    pspec.getPathSet().add("name");
    pspec.getPathSet().add("parent");
    PropertyFilterSpec filter = new PropertyFilterSpec();
    filter.getObjectSet().add(ospec);
    filter.getPropSet().add(pspec);
    return this.connection.getVimPort().retrieveProperties(this.connection.getServiceContent().getPropertyCollector(), Collections.singletonList(filter));
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec)

Example 27 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project vsphere-cloud-plugin by jenkinsci.

the class VSphere method folderExists.

/*
     Check if folder exists along all the vSphere folders
     */
public Boolean folderExists(String folderPath) throws VSphereException {
    try {
        String[] folderHierarchy = folderPath.split("/");
        ManagedEntity folder = null;
        for (int i = 0; i < folderHierarchy.length; i++) {
            if (i == 0) {
                folder = new InventoryNavigator(getServiceInstance().getRootFolder()).searchManagedEntity("Folder", folderHierarchy[i]);
            } else {
                folder = new InventoryNavigator(folder).searchManagedEntity(null, folderHierarchy[i]);
            }
            if (folder == null) {
                return false;
            }
        }
        return true;
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed while checking if folder exists");
        throw new VSphereException(e);
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 28 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project coprhd-controller by CoprHD.

the class VCenterAPI method searchManagedEntities.

/**
 * Searches from the given parent for managed entities of the given type.
 *
 * @param parent the parent entity.
 * @param type the desired type.
 * @param recurse whether to recurse.
 * @return the list of managed entities.
 *
 * @throws VMWareException if an error occurs.
 */
protected <T extends ManagedEntity> List<T> searchManagedEntities(ManagedEntity parent, Class<T> type, boolean recurse) throws VMWareException {
    String typeName = type.getSimpleName();
    List<T> results = Lists.newArrayList();
    for (ManagedEntity entity : searchManagedEntities(parent, typeName, recurse)) {
        results.add((T) entity);
    }
    return results;
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity)

Example 29 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project coprhd-controller by CoprHD.

the class VCenterAPI method searchManagedEntity.

/**
 * Searches from the given parent for a single managed entity with the specified type and name.
 *
 * @param type the type name.
 * @param name the entity name.
 * @return the managed entity.
 *
 * @throws VMWareException if an error occurs.
 */
public <T extends ManagedEntity> T searchManagedEntity(ManagedEntity parent, String type, String name) throws VMWareException {
    try {
        InventoryNavigator navigator = new InventoryNavigator(parent);
        ManagedEntity entity = navigator.searchManagedEntity(type, name);
        return (T) entity;
    } catch (InvalidProperty e) {
        throw new VMWareException(e);
    } catch (RuntimeFault e) {
        throw new VMWareException(e);
    } catch (RemoteException e) {
        throw new VMWareException(e);
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) RuntimeFault(com.vmware.vim25.RuntimeFault) RemoteException(java.rmi.RemoteException) InvalidProperty(com.vmware.vim25.InvalidProperty) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator)

Example 30 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project coprhd-controller by CoprHD.

the class VCenterAPI method searchManagedEntities.

/**
 * Searches from the given parent for managed entities of the specified type.
 *
 * @param parent the parent entity.
 * @param type the type name.
 * @param recurse whether to recurse.
 * @return the managed entities.
 *
 * @throws VMWareException if an error occurs.
 */
public ManagedEntity[] searchManagedEntities(ManagedEntity parent, String type, boolean recurse) throws VMWareException {
    try {
        String[][] typeInfo = new String[][] { new String[] { type, "name" } };
        InventoryNavigator navigator = new InventoryNavigator(parent);
        ManagedEntity[] entities = navigator.searchManagedEntities(typeInfo, recurse);
        return entities;
    } catch (InvalidProperty e) {
        throw new VMWareException(e);
    } catch (RuntimeFault e) {
        throw new VMWareException(e);
    } catch (RemoteException e) {
        throw new VMWareException(e);
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) RuntimeFault(com.vmware.vim25.RuntimeFault) RemoteException(java.rmi.RemoteException) InvalidProperty(com.vmware.vim25.InvalidProperty) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator)

Aggregations

ManagedEntity (com.vmware.vim25.mo.ManagedEntity)24 RemoteException (java.rmi.RemoteException)14 InventoryNavigator (com.vmware.vim25.mo.InventoryNavigator)12 MalformedURLException (java.net.MalformedURLException)10 HostSystem (com.vmware.vim25.mo.HostSystem)7 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 ObjectSpec (com.vmware.vim25.ObjectSpec)5 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)5 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)5 PropertySpec (com.vmware.vim25.PropertySpec)5 TraversalSpec (com.vmware.vim25.TraversalSpec)5 Datastore (com.vmware.vim25.mo.Datastore)5 ArrayList (java.util.ArrayList)5 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)4 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)4 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)4 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)4 ObjectContent (com.vmware.vim25.ObjectContent)4 SelectionSpec (com.vmware.vim25.SelectionSpec)4