use of com.vmware.vim25.DatastoreInfo in project CloudStack-archive by CloudStack-extras.
the class ClusterMO method findDatastoreByExportPath.
@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.get_value() + ", exportPath: " + exportPath);
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet(0).getVal();
if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
if (info != null) {
String vmwareUrl = info.getUrl();
if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
URI uri = new URI(vmwareUrl);
if (uri.getPath().equals("/" + exportPath)) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
return oc.getObj();
}
}
}
}
}
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
return null;
}
use of com.vmware.vim25.DatastoreInfo in project cloudstack by apache.
the class ClusterMO method findDatastoreByExportPath.
@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath);
ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
if (ocs != null && ocs.length > 0) {
for (ObjectContent oc : ocs) {
DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet().get(0).getVal();
if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
if (info != null) {
String vmwareUrl = info.getUrl();
if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
URI uri = new URI(vmwareUrl);
if (uri.getPath().equals("/" + exportPath)) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
return oc.getObj();
}
}
}
}
}
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
return null;
}
use of com.vmware.vim25.DatastoreInfo in project coprhd-controller by CoprHD.
the class TestVcenter method main.
public static void main(String[] args) throws MalformedURLException, InvalidProperty, RuntimeFault, RemoteException {
VCenterAPI vcenterAPI = getVcenterApi("lglw1045.lss.emc.com", "root", "vmware");
try {
Datastore ds = vcenterAPI.findDatastore("DC-Simulator-1", "ds-1");
DatastoreInfo dsInfo = ds.getInfo();
if (dsInfo != null) {
return;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.vmware.vim25.DatastoreInfo in project cloudstack by apache.
the class VmwareResource method getUnmanageInstanceDisks.
private List<UnmanagedInstanceTO.Disk> getUnmanageInstanceDisks(VirtualMachineMO vmMo) {
List<UnmanagedInstanceTO.Disk> instanceDisks = new ArrayList<>();
VirtualDisk[] disks = null;
try {
disks = vmMo.getAllDiskDevice();
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance disks. " + e.getMessage());
}
if (disks != null) {
for (VirtualDevice diskDevice : disks) {
try {
if (diskDevice instanceof VirtualDisk) {
UnmanagedInstanceTO.Disk instanceDisk = new UnmanagedInstanceTO.Disk();
VirtualDisk disk = (VirtualDisk) diskDevice;
instanceDisk.setDiskId(disk.getDiskObjectId());
instanceDisk.setLabel(disk.getDeviceInfo() != null ? disk.getDeviceInfo().getLabel() : "");
instanceDisk.setFileBaseName(vmMo.getVmdkFileBaseName(disk));
instanceDisk.setImagePath(getAbsoluteVmdkFile(disk));
instanceDisk.setCapacity(disk.getCapacityInBytes());
instanceDisk.setPosition(diskDevice.getUnitNumber());
DatastoreFile file = new DatastoreFile(getAbsoluteVmdkFile(disk));
if (StringUtils.isNoneEmpty(file.getFileBaseName(), file.getDatastoreName())) {
VirtualMachineDiskInfo diskInfo = vmMo.getDiskInfoBuilder().getDiskInfoByBackingFileBaseName(file.getFileBaseName(), file.getDatastoreName());
instanceDisk.setChainInfo(getGson().toJson(diskInfo));
}
for (VirtualDevice device : vmMo.getAllDeviceList()) {
if (diskDevice.getControllerKey() == device.getKey()) {
if (device instanceof VirtualIDEController) {
instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
instanceDisk.setControllerUnit(((VirtualIDEController) device).getBusNumber());
} else if (device instanceof VirtualSCSIController) {
instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
instanceDisk.setControllerUnit(((VirtualSCSIController) device).getBusNumber());
} else {
instanceDisk.setController(DiskControllerType.none.toString());
}
break;
}
}
if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
VirtualDeviceFileBackingInfo diskBacking = (VirtualDeviceFileBackingInfo) disk.getBacking();
ManagedObjectReference morDs = diskBacking.getDatastore();
DatastoreInfo info = (DatastoreInfo) vmMo.getContext().getVimClient().getDynamicProperty(diskBacking.getDatastore(), "info");
if (info instanceof NasDatastoreInfo) {
NasDatastoreInfo dsInfo = (NasDatastoreInfo) info;
instanceDisk.setDatastoreName(dsInfo.getName());
if (dsInfo.getNas() != null) {
instanceDisk.setDatastoreHost(dsInfo.getNas().getRemoteHost());
instanceDisk.setDatastorePath(dsInfo.getNas().getRemotePath());
instanceDisk.setDatastoreType(dsInfo.getNas().getType());
}
} else {
instanceDisk.setDatastoreName(info.getName());
}
}
s_logger.info(vmMo.getName() + " " + disk.getDeviceInfo().getLabel() + " " + disk.getDeviceInfo().getSummary() + " " + disk.getDiskObjectId() + " " + disk.getCapacityInKB() + " " + instanceDisk.getController());
instanceDisks.add(instanceDisk);
}
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance disk info. " + e.getMessage());
}
}
Collections.sort(instanceDisks, new Comparator<UnmanagedInstanceTO.Disk>() {
@Override
public int compare(final UnmanagedInstanceTO.Disk disk1, final UnmanagedInstanceTO.Disk disk2) {
return extractInt(disk1) - extractInt(disk2);
}
int extractInt(UnmanagedInstanceTO.Disk disk) {
String num = disk.getLabel().replaceAll("\\D", "");
// return 0 if no digits found
return num.isEmpty() ? 0 : Integer.parseInt(num);
}
});
}
return instanceDisks;
}
Aggregations