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 };
}
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);
}
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;
}
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);
}
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 + "\'");
}
Aggregations