use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class HostDatastoreSystemMO method createVmfsDatastore.
public ManagedObjectReference createVmfsDatastore(String datastoreName, HostScsiDisk hostScsiDisk) throws Exception {
// just grab the first instance of VmfsDatastoreOption
VmfsDatastoreOption vmfsDatastoreOption = _context.getService().queryVmfsDatastoreCreateOptions(_mor, hostScsiDisk.getDevicePath(), 5).get(0);
VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption.getSpec();
// set the name of the datastore to be created
vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
return _context.getService().createVmfsDatastore(_mor, vmfsDatastoreCreateSpec);
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class HostDatastoreSystemMO method findDatastoreByUrl.
// storeUrl in nfs://host/exportpath format
public ManagedObjectReference findDatastoreByUrl(String storeUrl) throws Exception {
assert (storeUrl != null);
List<ManagedObjectReference> datastores = getDatastores();
if (datastores != null && datastores.size() > 0) {
for (ManagedObjectReference morDatastore : datastores) {
NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
if (info != null) {
URI uri = new URI(storeUrl);
String vmwareStyleUrl = "netfs://" + uri.getHost() + "/" + uri.getPath() + "/";
if (info.getUrl().equals(vmwareStyleUrl))
return morDatastore;
}
}
}
return null;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class DatastoreMO method deleteFolder.
public boolean deleteFolder(String folder, ManagedObjectReference morDc) throws Exception {
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, folder, morDc);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class DatastoreMO method deleteFile.
public boolean deleteFile(String path, ManagedObjectReference morDc, boolean testExistence) throws Exception {
String datastoreName = getName();
ManagedObjectReference morFileManager = _context.getServiceContent().getFileManager();
String fullPath = path;
if (!DatastoreFile.isFullDatastorePath(fullPath))
fullPath = String.format("[%s] %s", datastoreName, path);
DatastoreFile file = new DatastoreFile(fullPath);
// Test if file specified is null or empty. We don't need to attempt to delete and return success.
if (file.getFileName() == null || file.getFileName().isEmpty()) {
return true;
}
try {
if (testExistence && !fileExists(fullPath)) {
String searchResult = searchFileInSubFolders(file.getFileName(), true);
if (searchResult == null) {
return true;
} else {
fullPath = searchResult;
}
}
} catch (Exception e) {
s_logger.info("Unable to test file existence due to exception " + e.getClass().getName() + ", skip deleting of it");
return true;
}
ManagedObjectReference morTask = _context.getService().deleteDatastoreFileTask(morFileManager, fullPath, morDc);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware deleteDatastoreFile_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.
the class DistributedVirtualSwitchMO method retrieveVlanPvlan.
public Map<Integer, HypervisorHostHelper.PvlanType> retrieveVlanPvlan(int vlanid, int secondaryvlanid, ManagedObjectReference dvSwitchMor) throws Exception {
assert (dvSwitchMor != null);
Map<Integer, HypervisorHostHelper.PvlanType> result = new HashMap<Integer, HypervisorHostHelper.PvlanType>();
VMwareDVSConfigInfo configinfo = (VMwareDVSConfigInfo) _context.getVimClient().getDynamicProperty(dvSwitchMor, "config");
List<VMwareDVSPvlanMapEntry> pvlanconfig = null;
pvlanconfig = configinfo.getPvlanConfig();
if (null == pvlanconfig || 0 == pvlanconfig.size()) {
return result;
}
for (VMwareDVSPvlanMapEntry mapEntry : pvlanconfig) {
int entryVlanid = mapEntry.getPrimaryVlanId();
int entryPvlanid = mapEntry.getSecondaryVlanId();
if (entryVlanid == entryPvlanid) {
// promiscuous
if (vlanid == entryVlanid) {
// pvlan type will always be promiscuous in this case.
result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
} else if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
}
} else {
if (vlanid == entryVlanid) {
// vlan id in entry is promiscuous
result.put(vlanid, HypervisorHostHelper.PvlanType.promiscuous);
} else if (vlanid == entryPvlanid) {
result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
}
if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
//promiscuous
result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.promiscuous);
} else if (secondaryvlanid == entryPvlanid) {
result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
}
}
// go over the entire list. Return.
if (result.containsKey(vlanid) && result.get(vlanid) != HypervisorHostHelper.PvlanType.promiscuous)
return result;
// If we've already found both vlanid and pvlanid, we have enough info to make a decision. Return.
if (result.containsKey(vlanid) && result.containsKey(secondaryvlanid))
return result;
}
return result;
}
Aggregations