Search in sources :

Example 6 with Folder

use of com.vmware.vim25.mo.Folder in project cloudstack by apache.

the class VmwareResource method syncDiskChain.

// return the finalized disk chain for startup, from top to bottom
private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO vol, VirtualMachineDiskInfo diskInfo, HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> dataStoresDetails) throws Exception {
    VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
    DataStoreTO primaryStore = volumeTO.getDataStore();
    Map<String, String> details = vol.getDetails();
    boolean isManaged = false;
    String iScsiName = null;
    if (details != null) {
        isManaged = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
        iScsiName = details.get(DiskTO.IQN);
    }
    // if the storage is managed, iScsiName should not be null
    String datastoreName = isManaged ? VmwareResource.getDatastoreName(iScsiName) : primaryStore.getUuid();
    Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(datastoreName);
    if (volumeDsDetails == null) {
        throw new Exception("Primary datastore " + primaryStore.getUuid() + " is not mounted on host.");
    }
    DatastoreMO dsMo = volumeDsDetails.second();
    // we will honor vCenter's meta if it exists
    if (diskInfo != null) {
        // to deal with run-time upgrade to maintain the new datastore folder structure
        String[] disks = diskInfo.getDiskChain();
        for (int i = 0; i < disks.length; i++) {
            DatastoreFile file = new DatastoreFile(disks[i]);
            if (!isManaged && file.getDir() != null && file.getDir().isEmpty()) {
                s_logger.info("Perform run-time datastore folder upgrade. sync " + disks[i] + " to VM folder");
                disks[i] = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, file.getFileBaseName());
            }
        }
        return disks;
    }
    final String datastoreDiskPath;
    if (isManaged) {
        if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
            datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, volumeTO.getName());
        } else {
            datastoreDiskPath = dsMo.getDatastorePath(dsMo.getName() + ".vmdk");
        }
    } else {
        datastoreDiskPath = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, volumeTO.getPath());
    }
    if (!dsMo.fileExists(datastoreDiskPath)) {
        s_logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath);
    }
    return new String[] { datastoreDiskPath };
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 7 with Folder

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

the class VapiConnectionTest method test.

@Test
public void test() throws IOException, RpcException {
    String url = System.getProperty("vapi.url");
    String username = System.getProperty("vc.username");
    String password = System.getProperty("vc.password");
    VapiConnection conn = new VapiConnection(URI.create(url));
    conn.setUsername(username);
    conn.setPassword(password);
    conn.setClient(VapiConnection.newUnsecureHttpClient());
    conn.login();
    System.out.println(conn.getSessionId());
    TaggingClient client = conn.newTaggingClient();
    ManagedObjectReference ref = new ManagedObjectReference();
    ref.setType("HostSystem");
    ref.setValue("host-4121");
    for (String tid : client.getAttachedTags(ref)) {
        ObjectNode model = client.getTagModel(tid);
        System.out.println(model);
        System.out.println(client.getCategoryName(model.get("category_id").asText()));
    }
    LibraryClient libraryClient = conn.newLibraryClient();
    List<String> libs = libraryClient.listLibs();
    for (String lib : libs) {
        System.out.println(libraryClient.loadLib(lib));
        List<String> items = libraryClient.listItemsInLib(lib);
        for (String it : items) {
            System.out.println(libraryClient.loadItem(it));
        }
    }
    ManagedObjectReference folder = VimUtils.convertStringToMoRef("Folder:group-v3");
    ManagedObjectReference ds = VimUtils.convertStringToMoRef("Datastore:datastore-4125");
    ManagedObjectReference rp = VimUtils.convertStringToMoRef("ResourcePool:resgroup-18");
    ObjectNode result = libraryClient.deployOvfLibItem("f2de22cb-ac8e-4fa8-933e-1caa70bed721", "test", folder, ds, null, rp, new HashMap<>(), null);
    System.out.println(result);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Example 8 with Folder

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

the class GetMoRef method inFolderByType.

/**
 * Returns all the MOREFs of the specified type that are present under the
 * folder
 *
 * @param folder    {@link ManagedObjectReference} of the folder to begin the search
 *                  from
 * @param morefType Type of the managed entity that needs to be searched
 * @return Map of name and MOREF of the managed objects present. If none
 *         exist then empty Map is returned
 * @throws InvalidPropertyFaultMsg
 *
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, ManagedObjectReference> inFolderByType(final ManagedObjectReference folder, final String morefType, final RetrieveOptions retrieveOptions) throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {
    final PropertyFilterSpec[] propertyFilterSpecs = propertyFilterSpecs(folder, morefType, "name");
    // reuse this property collector again later to scroll through results
    final ManagedObjectReference propertyCollector = this.serviceContent.getPropertyCollector();
    RetrieveResult results = this.vimPort.retrievePropertiesEx(propertyCollector, Arrays.asList(propertyFilterSpecs), retrieveOptions);
    final Map<String, ManagedObjectReference> tgtMoref = new HashMap<>();
    while (results != null && !results.getObjects().isEmpty()) {
        resultsToTgtMorefMap(results, tgtMoref);
        final String token = results.getToken();
        // if we have a token, we can scroll through additional results, else there's nothing to do.
        results = (token != null) ? this.vimPort.continueRetrievePropertiesEx(propertyCollector, token) : null;
    }
    return tgtMoref;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) HashMap(java.util.HashMap) RetrieveResult(com.vmware.vim25.RetrieveResult) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 9 with Folder

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

the class GetMoRef method inContainerByType.

/**
 * Returns all the MOREFs of the specified type that are present under the
 * container
 *
 * @param folder    {@link ManagedObjectReference} of the container to begin the
 *                  search from
 * @param morefType Type of the managed entity that needs to be searched
 * @return Map of name and MOREF of the managed objects present. If none
 *         exist then empty Map is returned
 * @throws InvalidPropertyFaultMsg
 * @throws RuntimeFaultFaultMsg
 */
public Map<String, ManagedObjectReference> inContainerByType(ManagedObjectReference folder, String morefType, RetrieveOptions retrieveOptions) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    init();
    RetrieveResult rslts = containerViewByType(folder, morefType, retrieveOptions);
    return toMap(rslts);
}
Also used : RetrieveResult(com.vmware.vim25.RetrieveResult)

Example 10 with Folder

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

the class SanityCheckTest method example.

@Test
public void example() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    BasicConnection conn = new BasicConnection();
    String url = System.getProperty("vsphere.url");
    String username = System.getProperty("vsphere.username");
    String password = System.getProperty("vsphere.password");
    conn.setURI(URI.create(url));
    conn.setUsername(username);
    conn.setPassword(password);
    conn.setIgnoreSslErrors(true);
    conn.setRequestTimeout(30, TimeUnit.SECONDS);
    conn.connect();
    AboutInfo about = conn.getServiceContent().getAbout();
    System.out.println(Utils.toJsonHtml(about));
    ManagedObjectReference rootFolder = conn.getServiceContent().getRootFolder();
    GetMoRef getMoRef = new GetMoRef(conn);
    String name = getMoRef.entityProp(rootFolder, "name");
    System.out.println("Root folder is called \'" + name + "\'");
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) AboutInfo(com.vmware.vim25.AboutInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Test(org.junit.Test)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)30 TraversalSpec (com.vmware.vim25.TraversalSpec)15 ArrayList (java.util.ArrayList)15 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)13 SelectionSpec (com.vmware.vim25.SelectionSpec)12 ObjectSpec (com.vmware.vim25.ObjectSpec)11 PropertySpec (com.vmware.vim25.PropertySpec)11 TaskInfo (com.vmware.vim25.TaskInfo)10 RemoteException (java.rmi.RemoteException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)8 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)8 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)6 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)6 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)6 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)6 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)6