diff --git a/deps/install-non-oss.sh b/deps/install-non-oss.sh
index 28eb03e1562..3476ea9922f 100755
--- a/deps/install-non-oss.sh
+++ b/deps/install-non-oss.sh
@@ -29,3 +29,10 @@ mvn install:install-file -Dfile=manageontap.jar -DgroupId=com.cloud.com.netapp
mvn install:install-file -Dfile=vim25.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim25 -Dversion=4.1 -Dpackaging=jar
mvn install:install-file -Dfile=apputils.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-apputils -Dversion=4.1 -Dpackaging=jar
mvn install:install-file -Dfile=vim.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim -Dversion=4.1 -Dpackaging=jar
+
+#
+# From https://my.vmware.com/group/vmware/get-download?downloadGroup=VSP510-WEBSDK-510
+# Version: 5.1, Release-date: 2012-09-10, Build: 774886
+mvn install:install-file -Dfile=vim25_51.jar -DgroupId=com.cloud.com.vmware -DartifactId=vmware-vim25 -Dversion=5.1 -Dpackaging=jar
+
+
diff --git a/plugins/hypervisors/vmware/pom.xml b/plugins/hypervisors/vmware/pom.xml
index d990e89b388..ad27ab7300a 100644
--- a/plugins/hypervisors/vmware/pom.xml
+++ b/plugins/hypervisors/vmware/pom.xml
@@ -38,18 +38,6 @@
${cs.vmware.api.version}
compile
-
- com.cloud.com.vmware
- vmware-vim
- ${cs.vmware.api.version}
- compile
-
-
- com.cloud.com.vmware
- vmware-apputils
- ${cs.vmware.api.version}
- compile
-
org.apache.axis
axis
diff --git a/pom.xml b/pom.xml
index 35d6520ce6b..c5081f2e969 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,7 @@
2.4
1.2
1.0-20081010.060147
- 4.1
+ 5.1
1.9.5
1.3.21.1
2.6
diff --git a/vmware-base/pom.xml b/vmware-base/pom.xml
index bd536fb574a..09509981f2d 100644
--- a/vmware-base/pom.xml
+++ b/vmware-base/pom.xml
@@ -43,18 +43,6 @@
${cs.vmware.api.version}
compile
-
- com.cloud.com.vmware
- vmware-vim
- ${cs.vmware.api.version}
- compile
-
-
- com.cloud.com.vmware
- vmware-apputils
- ${cs.vmware.api.version}
- compile
-
org.apache.axis
axis
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index cd54127fcc2..0dc41a1f597 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -103,22 +103,22 @@ public class VirtualMachineMO extends BaseMO {
public VirtualMachineMO(VmwareContext context, ManagedObjectReference morVm) {
super(context, morVm);
}
-
+
public VirtualMachineMO(VmwareContext context, String morType, String morValue) {
super(context, morType, morValue);
}
-
+
public Pair getOwnerDatacenter() throws Exception {
return DatacenterMO.getOwnerDatacenter(getContext(), getMor());
}
-
+
public Pair getOwnerDatastore(String dsFullPath) throws Exception {
String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
-
+
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.setPathSet(new String[] { "name" });
-
+
TraversalSpec vmDatastoreTraversal = new TraversalSpec();
vmDatastoreTraversal.setType("VirtualMachine");
vmDatastoreTraversal.setPath("datastore");
@@ -132,11 +132,11 @@ public class VirtualMachineMO extends BaseMO {
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
-
+
ObjectContent[] ocs = _context.getService().retrieveProperties(
- _context.getServiceContent().getPropertyCollector(),
+ _context.getServiceContent().getPropertyCollector(),
new PropertyFilterSpec[] { pfSpec });
-
+
if(ocs != null) {
for(ObjectContent oc : ocs) {
DynamicProperty prop = oc.getPropSet(0);
@@ -145,23 +145,23 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return null;
}
-
+
public HostMO getRunningHost() throws Exception {
VirtualMachineRuntimeInfo runtimeInfo = getRuntimeInfo();
return new HostMO(_context, runtimeInfo.getHost());
}
-
+
public String getVmName() throws Exception {
return (String)getContext().getServiceUtil().getDynamicProperty(_mor, "name");
}
-
+
public GuestInfo getVmGuestInfo() throws Exception {
return (GuestInfo)getContext().getServiceUtil().getDynamicProperty(_mor, "guest");
}
-
+
public boolean isVMwareToolsRunning() throws Exception {
GuestInfo guestInfo = getVmGuestInfo();
if(guestInfo != null) {
@@ -170,13 +170,13 @@ public class VirtualMachineMO extends BaseMO {
}
return false;
}
-
+
public boolean powerOn() throws Exception {
if(getPowerState() == VirtualMachinePowerState.poweredOn)
return true;
-
+
ManagedObjectReference morTask = _context.getService().powerOnVM_Task(_mor, null);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -184,64 +184,64 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware powerOnVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public boolean powerOff() throws Exception {
if(getPowerState() == VirtualMachinePowerState.poweredOff)
return true;
-
+
return powerOffNoCheck();
}
-
+
public boolean safePowerOff(int shutdownWaitMs) throws Exception {
-
+
if(getPowerState() == VirtualMachinePowerState.poweredOff)
return true;
-
+
if(isVMwareToolsRunning()) {
try {
String vmName = this.getName();
-
+
s_logger.info("Try gracefully shut down VM " + vmName);
shutdown();
-
+
long startTick = System.currentTimeMillis();
while(getPowerState() != VirtualMachinePowerState.poweredOff && System.currentTimeMillis() - startTick < shutdownWaitMs) {
- try {
+ try {
Thread.sleep(1000);
} catch(InterruptedException e) {
}
}
-
+
if(getPowerState() != VirtualMachinePowerState.poweredOff) {
s_logger.info("can not gracefully shutdown VM within " + (shutdownWaitMs/1000) + " seconds, we will perform force power off on VM " + vmName);
return powerOffNoCheck();
}
-
+
return true;
} catch(Exception e) {
- s_logger.warn("Failed to do guest-os graceful shutdown due to " + VmwareHelper.getExceptionMessage(e));
+ s_logger.warn("Failed to do guest-os graceful shutdown due to " + VmwareHelper.getExceptionMessage(e));
}
}
-
+
return powerOffNoCheck();
}
-
+
private boolean powerOffNoCheck() throws Exception {
ManagedObjectReference morTask = _context.getService().powerOffVM_Task(_mor);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
-
+
// It seems that even if a power-off task is returned done, VM state may still not be marked,
// wait up to 5 seconds to make sure to avoid race conditioning for immediate following on operations
// that relies on a powered-off VM
long startTick = System.currentTimeMillis();
while(getPowerState() != VirtualMachinePowerState.poweredOff && System.currentTimeMillis() - startTick < 5000) {
- try {
+ try {
Thread.sleep(1000);
} catch(InterruptedException e) {
}
@@ -249,21 +249,21 @@ public class VirtualMachineMO extends BaseMO {
return true;
} else {
if(getPowerState() == VirtualMachinePowerState.poweredOff) {
- // to help deal with possible race-condition
+ // to help deal with possible race-condition
s_logger.info("Current power-off task failed. However, VM has been switched to the state we are expecting for");
return true;
}
-
+
s_logger.error("VMware powerOffVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public VirtualMachinePowerState getPowerState() throws Exception {
-
+
VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff;
-
+
// This is really ugly, there is a case that when windows guest VM is doing sysprep, the temporary
// rebooting process may let us pick up a "poweredOff" state during VMsync process, this can trigger
// a series actions. Unfortunately, from VMware API we can not distinguish power state into such details.
@@ -282,13 +282,13 @@ public class VirtualMachineMO extends BaseMO {
break;
}
}
-
+
return powerState;
}
-
+
public boolean reset() throws Exception {
ManagedObjectReference morTask = _context.getService().resetVM_Task(_mor);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -298,28 +298,28 @@ public class VirtualMachineMO extends BaseMO {
}
return false;
}
-
+
public void shutdown() throws Exception {
_context.getService().shutdownGuest(_mor);
}
-
+
public void rebootGuest() throws Exception {
_context.getService().rebootGuest(_mor);
}
-
+
public void markAsTemplate() throws Exception {
_context.getService().markAsTemplate(_mor);
}
-
+
public boolean isTemplate() throws Exception {
VirtualMachineConfigInfo configInfo = this.getConfigInfo();
return configInfo.isTemplate();
}
-
+
public boolean migrate(ManagedObjectReference morRp, ManagedObjectReference morTargetHost) throws Exception {
ManagedObjectReference morTask = _context.getService().migrateVM_Task(_mor,
morRp, morTargetHost, VirtualMachineMovePriority.defaultPriority, null);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -327,17 +327,17 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware migrateVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public boolean relocate(ManagedObjectReference morTargetHost) throws Exception {
VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
relocateSpec.setHost(morTargetHost);
-
- ManagedObjectReference morTask = _context.getService().relocateVM_Task(_mor,
+
+ ManagedObjectReference morTask = _context.getService().relocateVM_Task(_mor,
relocateSpec, null);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -345,20 +345,20 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware relocateVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public VirtualMachineSnapshotInfo getSnapshotInfo() throws Exception {
return (VirtualMachineSnapshotInfo)_context.getServiceUtil().getDynamicProperty(_mor, "snapshot");
}
-
- public boolean createSnapshot(String snapshotName, String snapshotDescription,
+
+ public boolean createSnapshot(String snapshotName, String snapshotDescription,
boolean dumpMemory, boolean quiesce) throws Exception {
-
- ManagedObjectReference morTask = _context.getService().createSnapshot_Task(_mor, snapshotName,
+
+ ManagedObjectReference morTask = _context.getService().createSnapshot_Task(_mor, snapshotName,
snapshotDescription, dumpMemory, quiesce);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -371,28 +371,28 @@ public class VirtualMachineMO extends BaseMO {
if(morSnapshot != null) {
break;
}
-
+
try { Thread.sleep(1000); } catch(InterruptedException e) {}
}
-
+
if(morSnapshot == null)
s_logger.error("We've been waiting for over 10 seconds for snapshot MOR to be appearing in vCenter after CreateSnapshot task is done, but it is still not there?!");
-
+
return true;
} else {
s_logger.error("VMware createSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public boolean removeSnapshot(String snapshotName, boolean removeChildren) throws Exception {
ManagedObjectReference morSnapshot = getSnapshotMor(snapshotName);
if(morSnapshot == null) {
s_logger.warn("Unable to find snapshot: " + snapshotName);
return false;
}
-
+
ManagedObjectReference morTask = _context.getService().removeSnapshot_Task(morSnapshot, removeChildren);
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
@@ -401,13 +401,13 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware removeSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public boolean removeAllSnapshots() throws Exception {
VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();
-
+
if(snapshotInfo != null && snapshotInfo.getRootSnapshotList() != null) {
VirtualMachineSnapshotTree[] tree = snapshotInfo.getRootSnapshotList();
for(VirtualMachineSnapshotTree treeNode : tree) {
@@ -421,88 +421,88 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return true;
}
-
- public String getSnapshotDiskFileDatastorePath(VirtualMachineFileInfo vmFileInfo,
+
+ public String getSnapshotDiskFileDatastorePath(VirtualMachineFileInfo vmFileInfo,
List> datastoreMounts,
String snapshotDiskFile) throws Exception {
-
+
// if file path start with "/", need to search all datastore mounts on the host in order
- // to form fully qualified datastore path
+ // to form fully qualified datastore path
if(snapshotDiskFile.startsWith("/")) {
for(Pair mount: datastoreMounts) {
if(snapshotDiskFile.startsWith(mount.second())) {
DatastoreMO dsMo = new DatastoreMO(_context, mount.first());
-
+
String dsFullPath = String.format("[%s] %s", dsMo.getName(), snapshotDiskFile.substring(mount.second().length() + 1));
s_logger.info("Convert snapshot disk file name to datastore path. " + snapshotDiskFile + "->" + dsFullPath);
return dsFullPath;
}
}
-
+
s_logger.info("Convert snapshot disk file name to datastore path. " + snapshotDiskFile + "->" + snapshotDiskFile);
return snapshotDiskFile;
} else {
-
- // snapshot directory string from VirtualMachineFileInfo ends with /
+
+ // snapshot directory string from VirtualMachineFileInfo ends with /
String dsFullPath = vmFileInfo.getSnapshotDirectory() + snapshotDiskFile;
s_logger.info("Convert snapshot disk file name to datastore path. " + snapshotDiskFile + "->" + dsFullPath);
return dsFullPath;
}
}
-
+
public SnapshotDescriptor getSnapshotDescriptor() throws Exception {
Pair dcPair = getOwnerDatacenter();
-
+
String dsPath = getSnapshotDescriptorDatastorePath();
assert(dsPath != null);
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), dsPath);
byte[] content = getContext().getResourceContent(url);
-
+
if(content == null || content.length < 1) {
s_logger.warn("Snapshot descriptor file (vsd) does not exist anymore?");
}
-
+
SnapshotDescriptor descriptor = new SnapshotDescriptor();
descriptor.parse(content);
return descriptor;
}
-
+
public String getSnapshotDescriptorDatastorePath() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.setPathSet(new String[] { "name", "config.files" });
-
+
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.FALSE);
-
+
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
-
+
ObjectContent[] ocs = _context.getService().retrieveProperties(
- _context.getServiceContent().getPropertyCollector(),
+ _context.getServiceContent().getPropertyCollector(),
new PropertyFilterSpec[] { pfSpec });
assert(ocs != null);
String vmName = null;
VirtualMachineFileInfo fileInfo = null;
-
+
assert(ocs.length == 1);
for(ObjectContent oc : ocs) {
DynamicProperty[] props = oc.getPropSet();
if(props != null) {
assert(props.length == 2);
-
+
for(DynamicProperty prop : props) {
if(prop.getName().equals("name")) {
vmName = prop.getVal().toString();
} else {
- fileInfo = (VirtualMachineFileInfo)prop.getVal();
+ fileInfo = (VirtualMachineFileInfo)prop.getVal();
}
}
}
@@ -514,29 +514,29 @@ public class VirtualMachineMO extends BaseMO {
DatastoreFile vmxFile = new DatastoreFile(fileInfo.getVmPathName());
return vmxFile.getCompanionPath(vmName + ".vmsd");
}
-
+
public ManagedObjectReference getSnapshotMor(String snapshotName) throws Exception {
VirtualMachineSnapshotInfo info = getSnapshotInfo();
if(info != null) {
- VirtualMachineSnapshotTree[] snapTree = info.getRootSnapshotList();
- return VmwareHelper.findSnapshotInTree(snapTree, snapshotName);
+ List snapTree = info.getRootSnapshotList();
+ return VmwareHelper.findSnapshotInTree(snapTree, snapshotName);
}
return null;
}
-
- public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool,
+
+ public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool,
ManagedObjectReference morDs) throws Exception {
-
+
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
-
+
relocSpec.setDatastore(morDs);
relocSpec.setPool(morResourcePool);
- ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
-
+ ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -544,19 +544,19 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
- public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot,
- ManagedObjectReference morFolder, ManagedObjectReference morResourcePool,
+
+ public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot,
+ ManagedObjectReference morFolder, ManagedObjectReference morResourcePool,
ManagedObjectReference morDs) throws Exception {
-
+
assert(morBaseSnapshot != null);
assert(morFolder != null);
assert(morResourcePool != null);
assert(morDs != null);
-
+
VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
if(independentDisks.length > 0) {
@@ -567,22 +567,22 @@ public class VirtualMachineMO extends BaseMO {
diskLocator[i].setDiskId(independentDisks[i].getKey());
diskLocator[i].setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._moveAllDiskBackingsAndDisallowSharing);
}
-
+
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
rSpec.setDisk(diskLocator);
} else {
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
}
rSpec.setPool(morResourcePool);
-
+
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
cloneSpec.setLocation(rSpec);
cloneSpec.setSnapshot(morBaseSnapshot);
-
- ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
-
+
+ ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -590,30 +590,30 @@ public class VirtualMachineMO extends BaseMO {
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
return false;
}
-
+
public VirtualMachineRuntimeInfo getRuntimeInfo() throws Exception {
return (VirtualMachineRuntimeInfo)_context.getServiceUtil().getDynamicProperty(
_mor, "runtime");
}
-
+
public VirtualMachineConfigInfo getConfigInfo() throws Exception {
return (VirtualMachineConfigInfo)_context.getServiceUtil().getDynamicProperty(
_mor, "config");
}
-
+
public VirtualMachineConfigSummary getConfigSummary() throws Exception {
return (VirtualMachineConfigSummary)_context.getServiceUtil().getDynamicProperty(
_mor, "summary.config");
}
-
+
public VirtualMachineFileInfo getFileInfo() throws Exception {
return (VirtualMachineFileInfo)_context.getServiceUtil().getDynamicProperty(
_mor, "config.files");
}
-
+
public ManagedObjectReference getParentMor() throws Exception {
return (ManagedObjectReference)_context.getServiceUtil().getDynamicProperty(
_mor, "parent");
@@ -623,7 +623,7 @@ public class VirtualMachineMO extends BaseMO {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.setPathSet(new String[] {"name"});
-
+
TraversalSpec vm2NetworkTraversal = new TraversalSpec();
vm2NetworkTraversal.setType("VirtualMachine");
vm2NetworkTraversal.setPath("network");
@@ -637,11 +637,11 @@ public class VirtualMachineMO extends BaseMO {
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
-
+
ObjectContent[] ocs = _context.getService().retrieveProperties(
- _context.getServiceContent().getPropertyCollector(),
+ _context.getServiceContent().getPropertyCollector(),
new PropertyFilterSpec[] { pfSpec });
-
+
List networks = new ArrayList();
if(ocs != null && ocs.length > 0) {
for(ObjectContent oc : ocs) {
@@ -655,16 +655,16 @@ public class VirtualMachineMO extends BaseMO {
List networks = new ArrayList();
int gcTagKey = getCustomFieldKey("Network", CustomFieldConstants.CLOUD_GC);
-
+
if(gcTagKey == 0) {
gcTagKey = getCustomFieldKey("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP);
s_logger.debug("The custom key for dvPortGroup is : " + gcTagKey);
}
-
+
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Network");
pSpec.setPathSet(new String[] {"name", "vm", String.format("value[%d]", gcTagKey)});
-
+
TraversalSpec vm2NetworkTraversal = new TraversalSpec();
vm2NetworkTraversal.setType("VirtualMachine");
vm2NetworkTraversal.setPath("network");
@@ -678,11 +678,11 @@ public class VirtualMachineMO extends BaseMO {
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
-
+
ObjectContent[] ocs = _context.getService().retrieveProperties(
- _context.getServiceContent().getPropertyCollector(),
+ _context.getServiceContent().getPropertyCollector(),
new PropertyFilterSpec[] { pfSpec });
-
+
if(ocs != null && ocs.length > 0) {
for(ObjectContent oc : ocs) {
ArrayOfManagedObjectReference morVms = null;
@@ -700,29 +700,29 @@ public class VirtualMachineMO extends BaseMO {
gcTagValue = val.getValue();
}
}
-
- NetworkDetails details = new NetworkDetails(name, oc.getObj(),
- (morVms != null ? morVms.getManagedObjectReference() : null),
+
+ NetworkDetails details = new NetworkDetails(name, oc.getObj(),
+ (morVms != null ? morVms.getManagedObjectReference() : null),
gcTagValue);
-
+
networks.add(details);
}
s_logger.debug("Retrieved " + networks.size() + " networks with key : " + gcTagKey);
}
-
+
return networks;
}
-
+
/**
- * Retrieve path info to access VM files via vSphere web interface
- * @return [0] vm-name, [1] data-center-name, [2] datastore-name
+ * Retrieve path info to access VM files via vSphere web interface
+ * @return [0] vm-name, [1] data-center-name, [2] datastore-name
* @throws Exception
*/
public String[] getHttpAccessPathInfo() throws Exception {
String[] pathInfo = new String[3];
-
+
Pair dcInfo = getOwnerDatacenter();
-
+
VirtualMachineFileInfo fileInfo = getFileInfo();
String vmxFilePath = fileInfo.getVmPathName();
String vmxPathTokens[] = vmxFilePath.split("\\[|\\]|/");
@@ -732,14 +732,14 @@ public class VirtualMachineMO extends BaseMO {
pathInfo[3] = vmxPathTokens[0].trim(); // vSphere datastore name
return pathInfo;
}
-
+
public String getVmxHttpAccessUrl() throws Exception {
Pair dcInfo = getOwnerDatacenter();
-
+
VirtualMachineFileInfo fileInfo = getFileInfo();
String vmxFilePath = fileInfo.getVmPathName();
String vmxPathTokens[] = vmxFilePath.split("\\[|\\]|/");
-
+
StringBuffer sb = new StringBuffer("https://" + _context.getServerAddress() + "/folder/");
sb.append(URLEncoder.encode(vmxPathTokens[2].trim()));
sb.append("/");
@@ -748,16 +748,16 @@ public class VirtualMachineMO extends BaseMO {
sb.append(URLEncoder.encode(dcInfo.second()));
sb.append("&dsName=");
sb.append(URLEncoder.encode(vmxPathTokens[1].trim()));
-
+
return sb.toString();
}
-
+
public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, int vncPort, String keyboard) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, enableVnc, vncPassword, vncPort, keyboard);
vmConfigSpec.setExtraConfig(vncOptions);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, vmConfigSpec);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -767,10 +767,10 @@ public class VirtualMachineMO extends BaseMO {
}
return false;
}
-
+
public boolean configureVm(VirtualMachineConfigSpec vmConfigSpec) throws Exception {
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, vmConfigSpec);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -780,12 +780,12 @@ public class VirtualMachineMO extends BaseMO {
}
return false;
}
-
- public boolean configureVm(Ternary[] devices) throws Exception {
-
+
assert(devices != null);
-
+
VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
int i = 0;
@@ -799,7 +799,7 @@ public class VirtualMachineMO extends BaseMO {
configSpec.setDeviceChange(deviceConfigSpecArray);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, configSpec);
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if(result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
@@ -809,14 +809,14 @@ public class VirtualMachineMO extends BaseMO {
}
return false;
}
-
+
public Pair getVncPort(String hostNetworkName) throws Exception {
HostMO hostMo = getRunningHost();
VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);
VirtualMachineConfigInfo configInfo = getConfigInfo();
OptionValue[] values = configInfo.getExtraConfig();
-
+
if(values != null) {
for(OptionValue option : values) {
if(option.getKey().equals("RemoteDisplay.vnc.port")) {
@@ -829,32 +829,32 @@ public class VirtualMachineMO extends BaseMO {
}
return new Pair(summary.getHostIp(), 0);
}
-
+
// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
createDisk(vmdkDatastorePath, VirtualDiskType.thin, VirtualDiskMode.persistent, null, sizeInMb, morDs, controllerKey);
}
-
+
// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode,
String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + vmdkDatastorePath
- + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName
+ + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName
+ ", datastore: " + morDs.get_value() + ", controllerKey: " + controllerKey);
-
+
assert(vmdkDatastorePath != null);
assert(morDs != null);
-
+
if(controllerKey < 0) {
controllerKey = getIDEDeviceControllerKey();
}
-
+
VirtualDisk newDisk = new VirtualDisk();
if(diskType == VirtualDiskType.thin || diskType == VirtualDiskType.preallocated
|| diskType == VirtualDiskType.eagerZeroedThick) {
-
+
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDiskMode(diskMode.persistent.toString());
if(diskType == VirtualDiskType.thin) {
@@ -862,19 +862,19 @@ public class VirtualMachineMO extends BaseMO {
} else {
backingInfo.setThinProvisioned(false);
}
-
+
if(diskType == VirtualDiskType.eagerZeroedThick) {
backingInfo.setEagerlyScrub(true);
} else {
backingInfo.setEagerlyScrub(false);
}
-
+
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
} else if(diskType == VirtualDiskType.rdm || diskType == VirtualDiskType.rdmp) {
- VirtualDiskRawDiskMappingVer1BackingInfo backingInfo =
- new VirtualDiskRawDiskMappingVer1BackingInfo();
+ VirtualDiskRawDiskMappingVer1BackingInfo backingInfo =
+ new VirtualDiskRawDiskMappingVer1BackingInfo();
if(diskType == VirtualDiskType.rdm) {
backingInfo.setCompatibilityMode("virtualMode");
} else {
@@ -884,118 +884,118 @@ public class VirtualMachineMO extends BaseMO {
if(diskType == VirtualDiskType.rdm) {
backingInfo.setDiskMode(diskMode.persistent.toString());
}
-
+
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
}
-
+
int deviceNumber = getNextDeviceNumber(controllerKey);
-
+
newDisk.setControllerKey(controllerKey);
newDisk.setKey(-deviceNumber);
newDisk.setUnitNumber(deviceNumber);
newDisk.setCapacityInKB(sizeInMb*1024);
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(failed)");
throw new Exception("Unable to create disk " + vmdkDatastorePath + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
_context.waitForTaskProgressDone(morTask);
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(successfully)");
}
-
+
public void attachDisk(String[] vmdkDatastorePathChain, ManagedObjectReference morDs) throws Exception {
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.get_value());
-
- VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, getScsiDeviceControllerKey(),
+
+ VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, getScsiDeviceControllerKey(),
vmdkDatastorePathChain, morDs, -1, 1);
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk() done(failed)");
+ s_logger.trace("vCenter API trace - attachDisk() done(failed)");
throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
_context.waitForTaskProgressDone(morTask);
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
+ s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
-
+
public void attachDisk(Pair[] vmdkDatastorePathChain, int controllerKey) throws Exception {
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ new Gson().toJson(vmdkDatastorePathChain));
-
- VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey,
+
+ VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey,
vmdkDatastorePathChain, -1, 1);
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk() done(failed)");
+ s_logger.trace("vCenter API trace - attachDisk() done(failed)");
throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
_context.waitForTaskProgressDone(morTask);
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
+ s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
-
+
// vmdkDatastorePath: [datastore name] vmdkFilePath
public List> detachDisk(String vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - detachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ s_logger.trace("vCenter API trace - detachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ vmdkDatastorePath + ", deleteBacking: " + deleteBackingFile);
-
+
// Note: if VM has been taken snapshot, original backing file will be renamed, therefore, when we try to find the matching
// VirtualDisk, we only perform prefix matching
Pair deviceInfo = getDiskDevice(vmdkDatastorePath, false);
@@ -1004,29 +1004,29 @@ public class VirtualMachineMO extends BaseMO {
s_logger.trace("vCenter API trace - detachDisk() done (failed)");
throw new Exception("No such disk device: " + vmdkDatastorePath);
}
-
+
List> chain = getDiskDatastorePathChain(deviceInfo.first(), true);
-
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(deviceInfo.first());
if(deleteBackingFile) {
deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);
}
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachDisk() done (failed)");
-
+
throw new Exception("Failed to detach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
@@ -1038,65 +1038,65 @@ public class VirtualMachineMO extends BaseMO {
} catch(Exception e) {
s_logger.info("Unable to retrieve snapshot descriptor, will skip updating snapshot reference");
}
-
+
if(snapshotDescriptor != null) {
for(Pair pair: chain) {
DatastoreFile dsFile = new DatastoreFile(pair.first());
snapshotDescriptor.removeDiskReferenceFromSnapshot(dsFile.getFileName());
}
-
+
Pair dcPair = getOwnerDatacenter();
String dsPath = getSnapshotDescriptorDatastorePath();
assert(dsPath != null);
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), dsPath);
getContext().uploadResourceContent(url, snapshotDescriptor.getVmsdContent());
}
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachDisk() done (successfully)");
return chain;
}
-
+
public void detachAllDisks() throws Exception {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachAllDisk(). target MOR: " + _mor.get_value());
-
+
VirtualDisk[] disks = getAllDiskDevice();
if(disks.length > 0) {
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[disks.length];
-
+
for(int i = 0; i < disks.length; i++) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(disks[i]);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
}
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachAllDisk() done(failed)");
throw new Exception("Failed to detach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
_context.waitForTaskProgressDone(morTask);
}
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachAllDisk() done(successfully)");
}
-
+
// isoDatastorePath: [datastore name] isoFilePath
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs,
boolean connect, boolean connectAtBoot) throws Exception {
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: "
+ s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: "
+ isoDatastorePath + ", datastore: " + morDs.get_value() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
-
+
assert(isoDatastorePath != null);
assert(morDs != null);
@@ -1106,54 +1106,54 @@ public class VirtualMachineMO extends BaseMO {
newCdRom = true;
cdRom = new VirtualCdrom();
cdRom.setControllerKey(getIDEDeviceControllerKey());
-
+
int deviceNumber = getNextIDEDeviceNumber();
- cdRom.setUnitNumber(deviceNumber);
+ cdRom.setUnitNumber(deviceNumber);
cdRom.setKey(-deviceNumber);
}
-
+
VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
cInfo.setConnected(connect);
cInfo.setStartConnected(connectAtBoot);
cdRom.setConnectable(cInfo);
-
+
VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
backingInfo.setFileName(isoDatastorePath);
backingInfo.setDatastore(morDs);
cdRom.setBacking(backingInfo);
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(cdRom);
if(newCdRom) {
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
} else {
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
}
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(failed)");
throw new Exception("Failed to attach ISO due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
-
+
_context.waitForTaskProgressDone(morTask);
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
-
+
public void detachIso(String isoDatastorePath) throws Exception {
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: "
+ s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: "
+ isoDatastorePath);
VirtualDevice device = getIsoDevice();
@@ -1162,48 +1162,48 @@ public class VirtualMachineMO extends BaseMO {
s_logger.trace("vCenter API trace - detachIso() done(failed)");
throw new Exception("Unable to find a CDROM device");
}
-
+
VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
backingInfo.setDeviceName("");
device.setBacking(backingInfo);
-
- VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
+
+ VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
-
+
deviceConfigSpec.setDevice(device);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
-
+
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
-
+
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
-
+
if(!result.equals("sucess")) {
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(failed)");
throw new Exception("Failed to detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
-
+
if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
-
+
public Pair getVmdkFileInfo(String vmdkDatastorePath) throws Exception {
-
+
if(s_logger.isTraceEnabled())
- s_logger.trace("vCenter API trace - getVmdkFileInfo(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ s_logger.trace("vCenter API trace - getVmdkFileInfo(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: "
+ vmdkDatastorePath);
-
+
Pair dcPair = getOwnerDatacenter();
-
+
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), vmdkDatastorePath);
byte[] content = getContext().getResourceContent(url);
VmdkFileDescriptor descriptor = new VmdkFileDescriptor();
descriptor.parse(content);
-
+
Pair result = new Pair(descriptor, content);
if(s_logger.isTraceEnabled()) {
s_logger.trace("vCenter API trace - getVmdkFileInfo() done");
@@ -1211,32 +1211,32 @@ public class VirtualMachineMO extends BaseMO {
}
return result;
}
-
+
public void exportVm(String exportDir, String exportName, boolean packToOva, boolean leaveOvaFileOnly) throws Exception {
ManagedObjectReference morOvf = _context.getServiceContent().getOvfManager();
-
+
VirtualMachineRuntimeInfo runtimeInfo = getRuntimeInfo();
HostMO hostMo = new HostMO(_context, runtimeInfo.getHost());
String hostName = hostMo.getHostName();
String vmName = getVmName();
-
+
DatacenterMO dcMo = new DatacenterMO(_context, hostMo.getHyperHostDatacenter());
-
+
if(runtimeInfo.getPowerState() != VirtualMachinePowerState.poweredOff) {
String msg = "Unable to export VM because it is not at powerdOff state. vmName: " + vmName + ", host: " + hostName;
s_logger.error(msg);
throw new Exception(msg);
}
-
+
ManagedObjectReference morLease = _context.getService().exportVm(getMor());
if(morLease == null) {
s_logger.error("exportVm() failed");
throw new Exception("exportVm() failed");
}
-
+
HttpNfcLeaseMO leaseMo = new HttpNfcLeaseMO(_context, morLease);
HttpNfcLeaseState state = leaseMo.waitState(new HttpNfcLeaseState[] { HttpNfcLeaseState.ready, HttpNfcLeaseState.error });
-
+
try {
if(state == HttpNfcLeaseState.ready) {
final HttpNfcLeaseMO.ProgressReporter progressReporter = leaseMo.createProgressReporter();
@@ -1247,24 +1247,24 @@ public class VirtualMachineMO extends BaseMO {
HttpNfcLeaseInfo leaseInfo = leaseMo.getLeaseInfo();
final long totalBytes = leaseInfo.getTotalDiskCapacityInKB() * 1024;
long totalBytesDownloaded = 0;
-
+
HttpNfcLeaseDeviceUrl[] deviceUrls = leaseInfo.getDeviceUrl();
if(deviceUrls != null) {
- OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
- for (int i = 0; i < deviceUrls.length; i++) {
- String deviceId = deviceUrls[i].getKey();
- String deviceUrlStr = deviceUrls[i].getUrl();
+ OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
+ for (int i = 0; i < deviceUrls.length; i++) {
+ String deviceId = deviceUrls[i].getKey();
+ String deviceUrlStr = deviceUrls[i].getUrl();
String orgDiskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
String diskFileName = String.format("%s-disk%d%s", exportName, i, VmwareHelper.getFileExtension(orgDiskFileName, ".vmdk"));
String diskUrlStr = deviceUrlStr.replace("*", hostName);
diskUrlStr = HypervisorHostHelper.resolveHostNameInUrl(dcMo, diskUrlStr);
String diskLocalPath = exportDir + File.separator + diskFileName;
fileNames.add(diskLocalPath);
-
+
if(s_logger.isInfoEnabled()) {
s_logger.info("Download VMDK file for export. url: " + deviceUrlStr);
}
- long lengthOfDiskFile = _context.downloadVmdkFile(diskUrlStr, diskLocalPath, totalBytesDownloaded,
+ long lengthOfDiskFile = _context.downloadVmdkFile(diskUrlStr, diskLocalPath, totalBytesDownloaded,
new ActionDelegate () {
@Override
public void action(Long param) {
@@ -1275,33 +1275,33 @@ public class VirtualMachineMO extends BaseMO {
}
});
totalBytesDownloaded += lengthOfDiskFile;
-
+
OvfFile ovfFile = new OvfFile();
- ovfFile.setPath(diskFileName);
- ovfFile.setDeviceId(deviceId);
- ovfFile.setSize(lengthOfDiskFile);
- ovfFiles[i] = ovfFile;
+ ovfFile.setPath(diskFileName);
+ ovfFile.setDeviceId(deviceId);
+ ovfFile.setSize(lengthOfDiskFile);
+ ovfFiles[i] = ovfFile;
}
-
+
// write OVF descriptor file
- OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
- ovfDescParams.setOvfFiles(ovfFiles);
- OvfCreateDescriptorResult ovfCreateDescriptorResult = _context.getService().createDescriptor(morOvf, getMor(), ovfDescParams);
+ OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
+ ovfDescParams.setOvfFiles(ovfFiles);
+ OvfCreateDescriptorResult ovfCreateDescriptorResult = _context.getService().createDescriptor(morOvf, getMor(), ovfDescParams);
String ovfPath = exportDir + File.separator + exportName + ".ovf";
fileNames.add(ovfPath);
-
+
FileWriter out = new FileWriter(ovfPath);
- out.write(ovfCreateDescriptorResult.getOvfDescriptor());
+ out.write(ovfCreateDescriptorResult.getOvfDescriptor());
out.close();
-
+
// tar files into OVA
if(packToOva) {
// Important! we need to sync file system before we can safely use tar to work around a linux kernal bug(or feature)
s_logger.info("Sync file system before we package OVA...");
-
+
Script commandSync = new Script(true, "sync", 0, s_logger);
commandSync.execute();
-
+
Script command = new Script(false, "tar", 0, s_logger);
command.setWorkDir(exportDir);
command.add("-cf", exportName + ".ova");
@@ -1309,10 +1309,10 @@ public class VirtualMachineMO extends BaseMO {
for(String name: fileNames) {
command.add((new File(name).getName()));
}
-
+
s_logger.info("Package OVA with commmand: " + command.toString());
command.execute();
-
+
// to be safe, physically test existence of the target OVA file
if((new File(exportDir + File.separator + exportName + ".ova")).exists()) {
success = true;
@@ -1331,7 +1331,7 @@ public class VirtualMachineMO extends BaseMO {
new File(name).delete();
}
}
-
+
if(!success)
throw new Exception("Unable to finish the whole process to package as a OVA file");
}
@@ -1341,7 +1341,7 @@ public class VirtualMachineMO extends BaseMO {
leaseMo.completeLease();
}
}
-
+
// snapshot directory in format of: /vmfs/volumes//
@Deprecated
public void setSnapshotDirectory(String snapshotDir) throws Exception {
@@ -1349,15 +1349,15 @@ public class VirtualMachineMO extends BaseMO {
Pair dcInfo = getOwnerDatacenter();
String vmxUrl = _context.composeDatastoreBrowseUrl(dcInfo.second(), fileInfo.getVmPathName());
byte[] vmxContent = _context.getResourceContent(vmxUrl);
-
+
BufferedReader in = null;
BufferedWriter out = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
+
boolean replaced = false;
try {
in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(vmxContent)));
- out = new BufferedWriter(new OutputStreamWriter(bos));
+ out = new BufferedWriter(new OutputStreamWriter(bos));
String line;
while((line = in.readLine()) != null) {
if(line.startsWith("workingDir")) {
@@ -1369,7 +1369,7 @@ public class VirtualMachineMO extends BaseMO {
out.newLine();
}
}
-
+
if(!replaced) {
out.newLine();
out.write(String.format("workingDir=\"%s\"", snapshotDir));
@@ -1389,30 +1389,30 @@ public class VirtualMachineMO extends BaseMO {
// its disk backing info anyway.
// redoRegistration();
}
-
+
// destName does not contain extension name
- public void backupCurrentSnapshot(String deviceName, ManagedObjectReference morDestDs,
+ public void backupCurrentSnapshot(String deviceName, ManagedObjectReference morDestDs,
String destDsDirectory, String destName, boolean includeBase) throws Exception {
-
+
SnapshotDescriptor descriptor = getSnapshotDescriptor();
SnapshotInfo[] snapshotInfo = descriptor.getCurrentDiskChain();
if(snapshotInfo.length == 0) {
String msg = "No snapshot found in this VM";
throw new Exception(msg);
}
-
+
HostMO hostMo = getRunningHost();
DatacenterMO dcMo = getOwnerDatacenter().first();
List> mounts = hostMo.getDatastoreMountsOnHost();
VirtualMachineFileInfo vmFileInfo = getFileInfo();
-
- List> backupInfo = new ArrayList>();
-
+
+ List> backupInfo = new ArrayList>();
+
for(int i = 0; i < snapshotInfo.length; i++) {
if(!includeBase && i == snapshotInfo.length - 1) {
break;
}
-
+
SnapshotDescriptor.DiskInfo[] disks = snapshotInfo[i].getDisks();
if(disks != null) {
String destBaseFileName;
@@ -1420,10 +1420,10 @@ public class VirtualMachineMO extends BaseMO {
String destParentFileName;
for(SnapshotDescriptor.DiskInfo disk : disks) {
if(deviceName == null || deviceName.equals(disk.getDeviceName())) {
- String srcVmdkFullDsPath = getSnapshotDiskFileDatastorePath(vmFileInfo,
+ String srcVmdkFullDsPath = getSnapshotDiskFileDatastorePath(vmFileInfo,
mounts, disk.getDiskFileName());
Pair srcDsInfo = getOwnerDatastore(srcVmdkFullDsPath);
-
+
Pair vmdkInfo = getVmdkFileInfo(srcVmdkFullDsPath);
String srcVmdkBaseFilePath = DatastoreFile.getCompanionDatastorePath(
srcVmdkFullDsPath, vmdkInfo.first().getBaseFileName());
@@ -1436,19 +1436,19 @@ public class VirtualMachineMO extends BaseMO {
destBaseFileName = destName + (snapshotInfo.length - i - 1) + "-flat.vmdk";
destParentFileName = null;
}
-
+
s_logger.info("Copy VMDK base file " + srcVmdkBaseFilePath + " to " + destDsDirectory + "/" + destBaseFileName);
- srcDsInfo.first().copyDatastoreFile(srcVmdkBaseFilePath, dcMo.getMor(),
+ srcDsInfo.first().copyDatastoreFile(srcVmdkBaseFilePath, dcMo.getMor(),
morDestDs, destDsDirectory + "/" + destBaseFileName, dcMo.getMor(), true);
-
+
byte[] newVmdkContent = VmdkFileDescriptor.changeVmdkContentBaseInfo(
vmdkInfo.second(), destBaseFileName, destParentFileName);
- String vmdkUploadUrl = getContext().composeDatastoreBrowseUrl(dcMo.getName(),
+ String vmdkUploadUrl = getContext().composeDatastoreBrowseUrl(dcMo.getName(),
destDsDirectory + "/" + destFileName);
-
+
s_logger.info("Upload VMDK content file to " + destDsDirectory + "/" + destFileName);
getContext().uploadResourceContent(vmdkUploadUrl, newVmdkContent);
-
+
backupInfo.add(new Ternary(
destFileName, destBaseFileName, destParentFileName)
);
@@ -1456,21 +1456,21 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
byte[] vdiskInfo = VmwareHelper.composeDiskInfo(backupInfo, snapshotInfo.length, includeBase);
- String vdiskUploadUrl = getContext().composeDatastoreBrowseUrl(dcMo.getName(),
+ String vdiskUploadUrl = getContext().composeDatastoreBrowseUrl(dcMo.getName(),
destDsDirectory + "/" + destName + ".vdisk");
getContext().uploadResourceContent(vdiskUploadUrl, vdiskInfo);
}
-
+
public String[] getCurrentSnapshotDiskChainDatastorePaths(String diskDevice) throws Exception {
HostMO hostMo = getRunningHost();
List> mounts = hostMo.getDatastoreMountsOnHost();
VirtualMachineFileInfo vmFileInfo = getFileInfo();
-
+
SnapshotDescriptor descriptor = getSnapshotDescriptor();
SnapshotInfo[] snapshotInfo = descriptor.getCurrentDiskChain();
-
+
List diskDsFullPaths = new ArrayList();
for(int i = 0; i < snapshotInfo.length; i++) {
SnapshotDescriptor.DiskInfo[] disks = snapshotInfo[i].getDisks();
@@ -1478,7 +1478,7 @@ public class VirtualMachineMO extends BaseMO {
for(SnapshotDescriptor.DiskInfo disk: disks) {
String deviceNameInDisk = disk.getDeviceName();
if(diskDevice == null || diskDevice.equalsIgnoreCase(deviceNameInDisk)) {
- String vmdkFullDsPath = getSnapshotDiskFileDatastorePath(vmFileInfo,
+ String vmdkFullDsPath = getSnapshotDiskFileDatastorePath(vmFileInfo,
mounts, disk.getDiskFileName());
diskDsFullPaths.add(vmdkFullDsPath);
}
@@ -1487,37 +1487,37 @@ public class VirtualMachineMO extends BaseMO {
}
return diskDsFullPaths.toArray(new String[0]);
}
-
- public void cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice,
+
+ public void cloneFromCurrentSnapshot(String clonedVmName, int cpuSpeedMHz, int memoryMb, String diskDevice,
ManagedObjectReference morDs) throws Exception {
assert(morDs != null);
String[] disks = getCurrentSnapshotDiskChainDatastorePaths(diskDevice);
cloneFromDiskChain(clonedVmName, cpuSpeedMHz, memoryMb, disks, morDs);
}
-
- public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb,
+
+ public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb,
String[] disks, ManagedObjectReference morDs) throws Exception {
assert(disks != null);
assert(disks.length >= 1);
-
+
HostMO hostMo = getRunningHost();
VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
-
+
if(!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
throw new Exception("Unable to create a blank VM");
-
+
VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
if(clonedVmMo == null)
throw new Exception("Unable to find just-created blank VM");
-
+
boolean bSuccess = false;
try {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
-
+
VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, -1, disks, morDs, -1, 1);
-
+
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
@@ -1530,52 +1530,52 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
public void plugDevice(VirtualDevice device) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
-
+
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if(!configureVm(vmConfigSpec)) {
throw new Exception("Failed to add devices");
}
}
-
+
public void tearDownDevice(VirtualDevice device) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.remove);
-
+
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if(!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
-
+
public void tearDownDevices(Class>[] deviceClasses) throws Exception {
VirtualDevice[] devices = getMatchedDevices(deviceClasses);
if(devices.length > 0) {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
-
+
for(int i = 0; i < devices.length; i++) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(devices[i]);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
}
-
+
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if(!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
}
-
+
public void copyAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {
VirtualDevice[] disks = getAllDiskDevice();
DatacenterMO dcMo = getOwnerDatacenter().first();
@@ -1584,25 +1584,25 @@ public class VirtualMachineMO extends BaseMO {
List> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk)disk, followDiskChain);
for(Pair fileItem : vmdkFiles) {
DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
-
+
DatastoreFile srcFile = new DatastoreFile(fileItem.first());
DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
-
+
Pair vmdkDescriptor = null;
-
+
vmdkDescriptor = getVmdkFileInfo(fileItem.first());
-
+
s_logger.info("Copy VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
- srcDsMo.copyDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(),
+ srcDsMo.copyDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(),
destFile.getPath(), dcMo.getMor(), true);
-
+
if(vmdkDescriptor != null) {
String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
-
+
s_logger.info("Copy VM disk file " + baseFilePath + " to " + destFile.getPath());
- srcDsMo.copyDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(),
+ srcDsMo.copyDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(),
destFile.getPath(), dcMo.getMor(), true);
}
}
@@ -1620,40 +1620,40 @@ public class VirtualMachineMO extends BaseMO {
List> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk)disk, followDiskChain);
for(Pair fileItem : vmdkFiles) {
DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
-
+
DatastoreFile srcFile = new DatastoreFile(fileItem.first());
DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
-
+
Pair vmdkDescriptor = null;
vmdkDescriptor = getVmdkFileInfo(fileItem.first());
-
+
s_logger.info("Move VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
- srcDsMo.moveDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(),
+ srcDsMo.moveDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(),
destFile.getPath(), dcMo.getMor(), true);
-
+
if(vmdkDescriptor != null) {
String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
-
+
s_logger.info("Move VM disk file " + baseFilePath + " to " + destFile.getPath());
- srcDsMo.moveDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(),
+ srcDsMo.moveDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(),
destFile.getPath(), dcMo.getMor(), true);
}
}
}
}
}
-
+
public int getNextScsiDiskDeviceNumber() throws Exception {
int scsiControllerKey = getScsiDeviceControllerKey();
return getNextDeviceNumber(scsiControllerKey);
}
-
+
public int getScsiDeviceControllerKey() throws Exception {
VirtualDevice[] devices = (VirtualDevice [])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualLsiLogicController) {
@@ -1661,7 +1661,7 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
assert(false);
throw new Exception("SCSI Controller Not Found");
}
@@ -1669,7 +1669,7 @@ public class VirtualMachineMO extends BaseMO {
public int getScsiDeviceControllerKeyNoException() throws Exception {
VirtualDevice[] devices = (VirtualDevice [])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualLsiLogicController) {
@@ -1677,10 +1677,10 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return -1;
}
-
+
public void ensureScsiDeviceController() throws Exception {
int scsiControllerKey = getScsiDeviceControllerKeyNoException();
if(scsiControllerKey < 0) {
@@ -1701,54 +1701,54 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
public Pair getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
-
+
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath);
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
String srcBaseName = dsSrcFile.getFileBaseName();
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualDisk) {
s_logger.info("Test against disk device, controller key: " + device.getControllerKey() + ", unit number: " + device.getUnitNumber());
-
+
VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
do {
s_logger.info("Test against disk backing : " + diskBackingInfo.getFileName());
-
+
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
String backingBaseName = dsBackingFile.getFileBaseName();
if(matchExactly) {
if(backingBaseName .equalsIgnoreCase(srcBaseName)) {
String deviceNumbering = getDeviceBusName(devices, device);
-
+
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
return new Pair((VirtualDisk)device, deviceNumbering);
- }
+ }
} else {
if(backingBaseName.contains(srcBaseName)) {
String deviceNumbering = getDeviceBusName(devices, device);
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
return new Pair((VirtualDisk)device, deviceNumbering);
- }
+ }
}
-
+
diskBackingInfo = diskBackingInfo.getParent();
} while(diskBackingInfo != null);
- }
+ }
}
}
}
-
+
return null;
}
-
+
@Deprecated
public List> getDiskDatastorePathChain(VirtualDisk disk, boolean followChain) throws Exception {
VirtualDeviceBackingInfo backingInfo = disk.getBacking();
@@ -1763,18 +1763,18 @@ public class VirtualMachineMO extends BaseMO {
pathList.add(new Pair(diskBackingInfo.getFileName(), diskBackingInfo.getDatastore()));
return pathList;
}
-
+
Pair dcPair = getOwnerDatacenter();
VirtualMachineFileInfo vmFilesInfo = getFileInfo();
DatastoreFile snapshotDirFile = new DatastoreFile(vmFilesInfo.getSnapshotDirectory());
DatastoreFile vmxDirFile = new DatastoreFile(vmFilesInfo.getVmPathName());
-
+
do {
if(diskBackingInfo.getParent() != null) {
pathList.add(new Pair(diskBackingInfo.getFileName(), diskBackingInfo.getDatastore()));
diskBackingInfo = diskBackingInfo.getParent();
} else {
- // try getting parent info from VMDK file itself
+ // try getting parent info from VMDK file itself
byte[] content = null;
try {
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), diskBackingInfo.getFileName());
@@ -1782,7 +1782,7 @@ public class VirtualMachineMO extends BaseMO {
if(content == null || content.length == 0) {
break;
}
-
+
pathList.add(new Pair(diskBackingInfo.getFileName(), diskBackingInfo.getDatastore()));
} catch(Exception e) {
// if snapshot directory has been changed to place other than default. VMware has a bug
@@ -1790,23 +1790,23 @@ public class VirtualMachineMO extends BaseMO {
// in snapshot directory one more time
DatastoreFile currentFile = new DatastoreFile(diskBackingInfo.getFileName());
String vmdkFullDsPath = snapshotDirFile.getCompanionPath(currentFile.getFileName());
-
+
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), vmdkFullDsPath);
content = getContext().getResourceContent(url);
if(content == null || content.length == 0) {
break;
}
-
+
pathList.add(new Pair(vmdkFullDsPath, diskBackingInfo.getDatastore()));
}
-
+
VmdkFileDescriptor descriptor = new VmdkFileDescriptor();
descriptor.parse(content);
if(descriptor.getParentFileName() != null && !descriptor.getParentFileName().isEmpty()) {
// create a fake one
VirtualDiskFlatVer2BackingInfo parentDiskBackingInfo = new VirtualDiskFlatVer2BackingInfo();
parentDiskBackingInfo.setDatastore(diskBackingInfo.getDatastore());
-
+
String parentFileName = descriptor.getParentFileName();
if(parentFileName.startsWith("/")) {
int fileNameStartPos = parentFileName.lastIndexOf("/");
@@ -1815,16 +1815,16 @@ public class VirtualMachineMO extends BaseMO {
} else {
parentDiskBackingInfo.setFileName(snapshotDirFile.getCompanionPath(parentFileName));
}
- diskBackingInfo = parentDiskBackingInfo;
+ diskBackingInfo = parentDiskBackingInfo;
} else {
break;
}
}
} while(diskBackingInfo != null);
-
+
return pathList;
}
-
+
private String getDeviceBusName(VirtualDevice[] allDevices, VirtualDevice theDevice) throws Exception {
for(VirtualDevice device : allDevices) {
if(device.getKey() == theDevice.getControllerKey().intValue()) {
@@ -1839,7 +1839,7 @@ public class VirtualMachineMO extends BaseMO {
}
throw new Exception("Unable to find device controller");
}
-
+
public VirtualDisk[] getAllDiskDevice() throws Exception {
List deviceList = new ArrayList();
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
@@ -1850,7 +1850,7 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return deviceList.toArray(new VirtualDisk[0]);
}
@@ -1871,20 +1871,20 @@ public class VirtualMachineMO extends BaseMO {
} else if(disk.getBacking() instanceof VirtualDiskSparseVer2BackingInfo) {
diskMode = ((VirtualDiskSparseVer2BackingInfo)disk.getBacking()).getDiskMode();
}
-
+
if(diskMode.indexOf("independent") != -1) {
independentDisks.add(disk);
}
}
}
-
+
return independentDisks.toArray(new VirtualDisk[0]);
}
-
+
public int tryGetIDEDeviceControllerKey() throws Exception {
VirtualDevice[] devices = (VirtualDevice [])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualIDEController) {
@@ -1892,14 +1892,14 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return -1;
}
-
+
public int getIDEDeviceControllerKey() throws Exception {
VirtualDevice[] devices = (VirtualDevice [])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualIDEController) {
@@ -1907,16 +1907,16 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
assert(false);
throw new Exception("IDE Controller Not Found");
}
-
+
public int getNextIDEDeviceNumber() throws Exception {
int controllerKey = getIDEDeviceControllerKey();
return getNextDeviceNumber(controllerKey);
}
-
+
public VirtualDevice getIsoDevice() throws Exception {
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
@@ -1929,11 +1929,11 @@ public class VirtualMachineMO extends BaseMO {
}
return null;
}
-
+
public int getPCIDeviceControllerKey() throws Exception {
VirtualDevice[] devices = (VirtualDevice [])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
if(device instanceof VirtualPCIController) {
@@ -1941,20 +1941,20 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
assert(false);
throw new Exception("PCI Controller Not Found");
}
-
+
public int getNextPCIDeviceNumber() throws Exception {
int controllerKey = getPCIDeviceControllerKey();
return getNextDeviceNumber(controllerKey);
}
-
+
public int getNextDeviceNumber(int controllerKey) throws Exception {
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
int deviceNumber = -1;
if(devices != null && devices.length > 0) {
for(VirtualDevice device : devices) {
@@ -1967,11 +1967,11 @@ public class VirtualMachineMO extends BaseMO {
}
return ++deviceNumber;
}
-
+
public VirtualDevice[] getNicDevices() throws Exception {
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
List nics = new ArrayList();
if(devices != null) {
for(VirtualDevice device : devices) {
@@ -1980,14 +1980,14 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return nics.toArray(new VirtualDevice[0]);
}
-
+
public Pair getNicDeviceIndex(String networkNamePrefix) throws Exception {
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
List nics = new ArrayList();
if(devices != null) {
for(VirtualDevice device : devices) {
@@ -1996,7 +1996,7 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
Collections.sort(nics, new Comparator() {
@Override
public int compare(VirtualDevice arg0, VirtualDevice arg1) {
@@ -2009,7 +2009,7 @@ public class VirtualMachineMO extends BaseMO {
return 0;
}
});
-
+
int index = 0;
String attachedNetworkSummary;
String dvPortGroupName;
@@ -2042,12 +2042,12 @@ public class VirtualMachineMO extends BaseMO {
public VirtualDevice[] getMatchedDevices(Class>[] deviceClasses) throws Exception {
assert(deviceClasses != null);
-
+
List returnList = new ArrayList();
-
+
VirtualDevice[] devices = (VirtualDevice[])_context.getServiceUtil().
getDynamicProperty(_mor, "config.hardware.device");
-
+
if(devices != null) {
for(VirtualDevice device : devices) {
for(Class> clz : deviceClasses) {
@@ -2058,40 +2058,40 @@ public class VirtualMachineMO extends BaseMO {
}
}
}
-
+
return returnList.toArray(new VirtualDevice[0]);
}
-
+
public void mountToolsInstaller() throws Exception {
_context.getService().mountToolsInstaller(_mor);
}
-
+
public void unmountToolsInstaller() throws Exception {
_context.getService().unmountToolsInstaller(_mor);
}
-
+
public void redoRegistration(ManagedObjectReference morHost) throws Exception {
String vmName = getVmName();
VirtualMachineFileInfo vmFileInfo = getFileInfo();
boolean isTemplate = isTemplate();
-
+
HostMO hostMo;
if(morHost != null)
hostMo = new HostMO(getContext(), morHost);
else
hostMo = getRunningHost();
-
+
ManagedObjectReference morFolder = getParentMor();
ManagedObjectReference morPool = hostMo.getHyperHostOwnerResourcePool();
-
+
_context.getService().unregisterVM(_mor);
-
+
ManagedObjectReference morTask = _context.getService().registerVM_Task(
- morFolder,
+ morFolder,
vmFileInfo.getVmPathName(),
- vmName, false,
+ vmName, false,
morPool, hostMo.getMor());
-
+
String result = _context.getServiceUtil().waitForTask(morTask);
if (!result.equalsIgnoreCase("Sucess")) {
throw new Exception("Unable to register template due to " + TaskMO.getTaskFailureInfo(_context, morTask));
@@ -2099,7 +2099,7 @@ public class VirtualMachineMO extends BaseMO {
_context.waitForTaskProgressDone(morTask);
if(isTemplate) {
VirtualMachineMO vmNewRegistration = hostMo.findVmOnHyperHost(vmName);
- assert(vmNewRegistration != null);
+ assert(vmNewRegistration != null);
vmNewRegistration.markAsTemplate();
}
}
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareGuestOsMapper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareGuestOsMapper.java
index 7d26983fcbf..14331481513 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareGuestOsMapper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareGuestOsMapper.java
@@ -24,146 +24,150 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
public class VmwareGuestOsMapper {
private static Map s_mapper = new HashMap();
static {
- s_mapper.put("DOS", VirtualMachineGuestOsIdentifier.dosGuest);
- s_mapper.put("OS/2", VirtualMachineGuestOsIdentifier.os2Guest);
+ s_mapper.put("DOS", VirtualMachineGuestOsIdentifier.DOS_GUEST);
+ s_mapper.put("OS/2", VirtualMachineGuestOsIdentifier.OS_2_GUEST);
- s_mapper.put("Windows 3.1", VirtualMachineGuestOsIdentifier.win31Guest);
- s_mapper.put("Windows 95", VirtualMachineGuestOsIdentifier.win95Guest);
- s_mapper.put("Windows 98", VirtualMachineGuestOsIdentifier.win98Guest);
- s_mapper.put("Windows NT 4", VirtualMachineGuestOsIdentifier.winNTGuest);
- s_mapper.put("Windows XP (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
- s_mapper.put("Windows XP (64-bit)", VirtualMachineGuestOsIdentifier.winXPPro64Guest);
- s_mapper.put("Windows XP SP2 (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
- s_mapper.put("Windows XP SP3 (32-bit)", VirtualMachineGuestOsIdentifier.winXPProGuest);
- s_mapper.put("Windows Vista (32-bit)", VirtualMachineGuestOsIdentifier.winVistaGuest);
- s_mapper.put("Windows Vista (64-bit)", VirtualMachineGuestOsIdentifier.winVista64Guest);
- s_mapper.put("Windows 7 (32-bit)", VirtualMachineGuestOsIdentifier.windows7Guest);
- s_mapper.put("Windows 7 (64-bit)", VirtualMachineGuestOsIdentifier.windows7_64Guest);
+ s_mapper.put("Windows 3.1", VirtualMachineGuestOsIdentifier.WIN_31_GUEST);
+ s_mapper.put("Windows 95", VirtualMachineGuestOsIdentifier.WIN_95_GUEST);
+ s_mapper.put("Windows 98", VirtualMachineGuestOsIdentifier.WIN_98_GUEST);
+ s_mapper.put("Windows NT 4", VirtualMachineGuestOsIdentifier.WIN_NT_GUEST);
+ s_mapper.put("Windows XP (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
+ s_mapper.put("Windows XP (64-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_64_GUEST);
+ s_mapper.put("Windows XP SP2 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
+ s_mapper.put("Windows XP SP3 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_XP_PRO_GUEST);
+ s_mapper.put("Windows Vista (32-bit)", VirtualMachineGuestOsIdentifier.WIN_VISTA_GUEST);
+ s_mapper.put("Windows Vista (64-bit)", VirtualMachineGuestOsIdentifier.WIN_VISTA_64_GUEST);
+ s_mapper.put("Windows 7 (32-bit)", VirtualMachineGuestOsIdentifier.WINDOWS_7_GUEST);
+ s_mapper.put("Windows 7 (64-bit)", VirtualMachineGuestOsIdentifier.WINDOWS_7_64_GUEST);
- s_mapper.put("Windows 2000 Professional", VirtualMachineGuestOsIdentifier.win2000ProGuest);
- s_mapper.put("Windows 2000 Server", VirtualMachineGuestOsIdentifier.win2000ServGuest);
- s_mapper.put("Windows 2000 Server SP4 (32-bit)", VirtualMachineGuestOsIdentifier.win2000ServGuest);
- s_mapper.put("Windows 2000 Advanced Server", VirtualMachineGuestOsIdentifier.win2000AdvServGuest);
-
- s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetEnterpriseGuest);
- s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetEnterprise64Guest);
- s_mapper.put("Windows Server 2008 R2 (64-bit)", VirtualMachineGuestOsIdentifier.winLonghorn64Guest);
- s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetDatacenterGuest);
- s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetDatacenter64Guest);
- s_mapper.put("Windows Server 2003 Standard Edition(32-bit)", VirtualMachineGuestOsIdentifier.winNetStandardGuest);
- s_mapper.put("Windows Server 2003 Standard Edition(64-bit)", VirtualMachineGuestOsIdentifier.winNetStandard64Guest);
- s_mapper.put("Windows Server 2003 Web Edition", VirtualMachineGuestOsIdentifier.winNetWebGuest);
- s_mapper.put("Microsoft Small Bussiness Server 2003", VirtualMachineGuestOsIdentifier.winNetBusinessGuest);
-
- s_mapper.put("Windows Server 2008 (32-bit)", VirtualMachineGuestOsIdentifier.winLonghornGuest);
- s_mapper.put("Windows Server 2008 (64-bit)", VirtualMachineGuestOsIdentifier.winLonghorn64Guest);
-
- s_mapper.put("Open Enterprise Server", VirtualMachineGuestOsIdentifier.oesGuest);
-
- s_mapper.put("Asianux 3(32-bit)", VirtualMachineGuestOsIdentifier.asianux3Guest);
- s_mapper.put("Asianux 3(64-bit)", VirtualMachineGuestOsIdentifier.asianux3_64Guest);
-
- s_mapper.put("Debian GNU/Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.debian5_64Guest);
- s_mapper.put("Debian GNU/Linux 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.debian5Guest);
- s_mapper.put("Debian GNU/Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.debian4Guest);
- s_mapper.put("Debian GNU/Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.debian4_64Guest);
-
- s_mapper.put("Novell Netware 6.x", VirtualMachineGuestOsIdentifier.netware6Guest);
- s_mapper.put("Novell Netware 5.1", VirtualMachineGuestOsIdentifier.netware5Guest);
-
- s_mapper.put("Sun Solaris 10(32-bit)", VirtualMachineGuestOsIdentifier.solaris10Guest);
- s_mapper.put("Sun Solaris 10(64-bit)", VirtualMachineGuestOsIdentifier.solaris10_64Guest);
- s_mapper.put("Sun Solaris 9(Experimental)", VirtualMachineGuestOsIdentifier.solaris9Guest);
- s_mapper.put("Sun Solaris 8(Experimental)", VirtualMachineGuestOsIdentifier.solaris8Guest);
-
- s_mapper.put("FreeBSD (32-bit)", VirtualMachineGuestOsIdentifier.freebsdGuest);
- s_mapper.put("FreeBSD (64-bit)", VirtualMachineGuestOsIdentifier.freebsd64Guest);
-
- s_mapper.put("SCO OpenServer 5", VirtualMachineGuestOsIdentifier.otherGuest);
- s_mapper.put("SCO UnixWare 7", VirtualMachineGuestOsIdentifier.unixWare7Guest);
-
- s_mapper.put("SUSE Linux Enterprise 8(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
- s_mapper.put("SUSE Linux Enterprise 8(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
- s_mapper.put("SUSE Linux Enterprise 9(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
- s_mapper.put("SUSE Linux Enterprise 9(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
- s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
- s_mapper.put("SUSE Linux Enterprise 10(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
- s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
- s_mapper.put("Other SUSE Linux(32-bit)", VirtualMachineGuestOsIdentifier.suseGuest);
- s_mapper.put("Other SUSE Linux(64-bit)", VirtualMachineGuestOsIdentifier.suse64Guest);
-
- s_mapper.put("CentOS 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.0 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.1 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.1 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.2 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.2 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.3 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.3 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.4 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.4 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.5 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.5 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 5.6 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 5.6 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("CentOS 6.0 (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("CentOS 6.0 (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
- s_mapper.put("Other CentOS (32-bit)", VirtualMachineGuestOsIdentifier.centosGuest);
- s_mapper.put("Other CentOS (64-bit)", VirtualMachineGuestOsIdentifier.centos64Guest);
-
- s_mapper.put("Red Hat Enterprise Linux 2", VirtualMachineGuestOsIdentifier.rhel2Guest);
- s_mapper.put("Red Hat Enterprise Linux 3(32-bit)", VirtualMachineGuestOsIdentifier.rhel3Guest);
- s_mapper.put("Red Hat Enterprise Linux 3(64-bit)", VirtualMachineGuestOsIdentifier.rhel3_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
- s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.rhel4_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 5(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 6(32-bit)", VirtualMachineGuestOsIdentifier.rhel6Guest);
- s_mapper.put("Red Hat Enterprise Linux 6(64-bit)", VirtualMachineGuestOsIdentifier.rhel6_64Guest);
-
- s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
- s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
- s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
- s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.rhel4Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.0(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.0(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.1(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.1(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.2(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.2(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.3(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.3(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.4(32-bit)", VirtualMachineGuestOsIdentifier.rhel5Guest);
- s_mapper.put("Red Hat Enterprise Linux 5.4(64-bit)", VirtualMachineGuestOsIdentifier.rhel5_64Guest);
-
- s_mapper.put("Ubuntu 8.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 8.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Ubuntu 8.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 8.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Ubuntu 9.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 9.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Ubuntu 9.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 9.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Ubuntu 10.04 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 10.04 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Ubuntu 10.10 (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Ubuntu 10.10 (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
- s_mapper.put("Other Ubuntu (32-bit)", VirtualMachineGuestOsIdentifier.ubuntuGuest);
- s_mapper.put("Other Ubuntu (64-bit)", VirtualMachineGuestOsIdentifier.ubuntu64Guest);
+ s_mapper.put("Windows 2000 Professional", VirtualMachineGuestOsIdentifier.WIN_2000_PRO_GUEST);
+ s_mapper.put("Windows 2000 Server", VirtualMachineGuestOsIdentifier.WIN_2000_SERV_GUEST);
+ s_mapper.put("Windows 2000 Server SP4 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_2000_SERV_GUEST);
+ s_mapper.put("Windows 2000 Advanced Server", VirtualMachineGuestOsIdentifier.WIN_2000_ADV_SERV_GUEST);
- s_mapper.put("Other 2.6x Linux (32-bit)", VirtualMachineGuestOsIdentifier.other26xLinuxGuest);
- s_mapper.put("Other 2.6x Linux (64-bit)", VirtualMachineGuestOsIdentifier.other26xLinux64Guest);
- s_mapper.put("Other Linux (32-bit)", VirtualMachineGuestOsIdentifier.otherLinuxGuest);
- s_mapper.put("Other Linux (64-bit)", VirtualMachineGuestOsIdentifier.otherLinux64Guest);
-
- s_mapper.put("Other (32-bit)", VirtualMachineGuestOsIdentifier.otherGuest);
- s_mapper.put("Other (64-bit)", VirtualMachineGuestOsIdentifier.otherGuest64);
+ s_mapper.put("Windows Server 2003 Enterprise Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_ENTERPRISE_GUEST);
+ s_mapper.put("Windows Server 2003 Enterprise Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_ENTERPRISE_64_GUEST);
+ s_mapper.put("Windows Server 2008 R2 (64-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_64_GUEST);
+ s_mapper.put("Windows Server 2003 DataCenter Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_DATACENTER_GUEST);
+ s_mapper.put("Windows Server 2003 DataCenter Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_DATACENTER_64_GUEST);
+ s_mapper.put("Windows Server 2003 Standard Edition(32-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_STANDARD_GUEST);
+ s_mapper.put("Windows Server 2003 Standard Edition(64-bit)", VirtualMachineGuestOsIdentifier.WIN_NET_STANDARD_64_GUEST);
+ s_mapper.put("Windows Server 2003 Web Edition", VirtualMachineGuestOsIdentifier.WIN_NET_WEB_GUEST);
+ s_mapper.put("Microsoft Small Bussiness Server 2003", VirtualMachineGuestOsIdentifier.WIN_NET_BUSINESS_GUEST);
+
+ s_mapper.put("Windows Server 2008 (32-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_GUEST);
+ s_mapper.put("Windows Server 2008 (64-bit)", VirtualMachineGuestOsIdentifier.WIN_LONGHORN_64_GUEST);
+
+ s_mapper.put("Windows 8", VirtualMachineGuestOsIdentifier.WINDOWS_8_GUEST);
+ s_mapper.put("Windows 8 (64 bit)", VirtualMachineGuestOsIdentifier.WINDOWS_8_64_GUEST);
+ s_mapper.put("Windows 8 Server (64 bit)", VirtualMachineGuestOsIdentifier.WINDOWS_8_SERVER_64_GUEST);
+
+ s_mapper.put("Open Enterprise Server", VirtualMachineGuestOsIdentifier.OES_GUEST);
+
+ s_mapper.put("Asianux 3(32-bit)", VirtualMachineGuestOsIdentifier.ASIANUX_3_GUEST);
+ s_mapper.put("Asianux 3(64-bit)", VirtualMachineGuestOsIdentifier.ASIANUX_3_64_GUEST);
+
+ s_mapper.put("Debian GNU/Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_5_64_GUEST);
+ s_mapper.put("Debian GNU/Linux 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_5_GUEST);
+ s_mapper.put("Debian GNU/Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_4_GUEST);
+ s_mapper.put("Debian GNU/Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.DEBIAN_4_64_GUEST);
+
+ s_mapper.put("Novell Netware 6.x", VirtualMachineGuestOsIdentifier.NETWARE_6_GUEST);
+ s_mapper.put("Novell Netware 5.1", VirtualMachineGuestOsIdentifier.NETWARE_5_GUEST);
+
+ s_mapper.put("Sun Solaris 10(32-bit)", VirtualMachineGuestOsIdentifier.SOLARIS_10_GUEST);
+ s_mapper.put("Sun Solaris 10(64-bit)", VirtualMachineGuestOsIdentifier.SOLARIS_10_64_GUEST);
+ s_mapper.put("Sun Solaris 9(Experimental)", VirtualMachineGuestOsIdentifier.SOLARIS_9_GUEST);
+ s_mapper.put("Sun Solaris 8(Experimental)", VirtualMachineGuestOsIdentifier.SOLARIS_8_GUEST);
+
+ s_mapper.put("FreeBSD (32-bit)", VirtualMachineGuestOsIdentifier.FREEBSD_GUEST);
+ s_mapper.put("FreeBSD (64-bit)", VirtualMachineGuestOsIdentifier.FREEBSD_64_GUEST);
+
+ s_mapper.put("SCO OpenServer 5", VirtualMachineGuestOsIdentifier.OTHER_GUEST);
+ s_mapper.put("SCO UnixWare 7", VirtualMachineGuestOsIdentifier.UNIX_WARE_7_GUEST);
+
+ s_mapper.put("SUSE Linux Enterprise 8(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 8(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 9(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 9(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 10(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
+ s_mapper.put("SUSE Linux Enterprise 10(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
+ s_mapper.put("Other SUSE Linux(32-bit)", VirtualMachineGuestOsIdentifier.SUSE_GUEST);
+ s_mapper.put("Other SUSE Linux(64-bit)", VirtualMachineGuestOsIdentifier.SUSE_64_GUEST);
+
+ s_mapper.put("CentOS 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.0 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.0 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.1 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.1 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.2 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.2 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.3 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.3 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.4 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.4 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.5 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.5 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 5.6 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 5.6 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("CentOS 6.0 (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("CentOS 6.0 (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+ s_mapper.put("Other CentOS (32-bit)", VirtualMachineGuestOsIdentifier.CENTOS_GUEST);
+ s_mapper.put("Other CentOS (64-bit)", VirtualMachineGuestOsIdentifier.CENTOS_64_GUEST);
+
+ s_mapper.put("Red Hat Enterprise Linux 2", VirtualMachineGuestOsIdentifier.RHEL_2_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 3(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_3_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 3(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_3_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 4(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 6(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_6_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 6(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_6_64_GUEST);
+
+ s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 4.7 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 4.8 (32-bit)", VirtualMachineGuestOsIdentifier.RHEL_4_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.0(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.0(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.1(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.1(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.2(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.2(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.3(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.3(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.4(32-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_GUEST);
+ s_mapper.put("Red Hat Enterprise Linux 5.4(64-bit)", VirtualMachineGuestOsIdentifier.RHEL_5_64_GUEST);
+
+ s_mapper.put("Ubuntu 8.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 8.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Ubuntu 8.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 8.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Ubuntu 9.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 9.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Ubuntu 9.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 9.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Ubuntu 10.04 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 10.04 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Ubuntu 10.10 (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Ubuntu 10.10 (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+ s_mapper.put("Other Ubuntu (32-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_GUEST);
+ s_mapper.put("Other Ubuntu (64-bit)", VirtualMachineGuestOsIdentifier.UBUNTU_64_GUEST);
+
+ s_mapper.put("Other 2.6x Linux (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_26_X_LINUX_GUEST);
+ s_mapper.put("Other 2.6x Linux (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_26_X_LINUX_64_GUEST);
+ s_mapper.put("Other Linux (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_LINUX_GUEST);
+ s_mapper.put("Other Linux (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_LINUX_64_GUEST);
+
+ s_mapper.put("Other (32-bit)", VirtualMachineGuestOsIdentifier.OTHER_GUEST);
+ s_mapper.put("Other (64-bit)", VirtualMachineGuestOsIdentifier.OTHER_GUEST_64);
}
-
+
public static VirtualMachineGuestOsIdentifier getGuestOsIdentifier(String guestOsName) {
return s_mapper.get(guestOsName);
}
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index 47ff8e20004..8e6947fd072 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -69,38 +70,38 @@ import com.vmware.vim25.VirtualVmxnet3;
public class VmwareHelper {
private static final Logger s_logger = Logger.getLogger(VmwareHelper.class);
-
+
public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType,
String portGroupName, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
-
+
VirtualEthernetCard nic;
switch(deviceType) {
case E1000 :
nic = new VirtualE1000();
break;
-
+
case PCNet32 :
nic = new VirtualPCNet32();
break;
-
+
case Vmxnet2 :
nic = new VirtualVmxnet2();
break;
-
+
case Vmxnet3 :
nic = new VirtualVmxnet3();
break;
-
+
default :
assert(false);
nic = new VirtualE1000();
}
-
+
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(portGroupName);
nicBacking.setNetwork(morNetwork);
nic.setBacking(nicBacking);
-
+
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
connectInfo.setAllowGuestControl(true);
connectInfo.setConnected(conntected);
@@ -112,7 +113,7 @@ public class VmwareHelper {
nic.setKey(-contextNumber);
return nic;
}
-
+
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType,
String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
@@ -144,7 +145,7 @@ public class VmwareHelper {
final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
dvPortConnection.setSwitchUuid(dvSwitchUuid);
- dvPortConnection.setPortgroupKey(morNetwork.get_value());
+ dvPortConnection.setPortgroupKey(morNetwork.getValue());
dvPortBacking.setPort(dvPortConnection);
nic.setBacking(dvPortBacking);
nic.setKey(30);
@@ -162,13 +163,13 @@ public class VmwareHelper {
}
// vmdkDatastorePath: [datastore name] vmdkFilePath
- public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
+ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
int sizeInMb, ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
-
+
VirtualDisk disk = new VirtualDisk();
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
- backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
+ backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
backingInfo.setThinProvisioned(true);
backingInfo.setEagerlyScrub(false);
backingInfo.setDatastore(morDs);
@@ -180,7 +181,7 @@ public class VmwareHelper {
if(deviceNumber < 0)
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
disk.setControllerKey(controllerKey);
-
+
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
disk.setCapacityInKB(sizeInMb*1024);
@@ -189,19 +190,19 @@ public class VmwareHelper {
connectInfo.setConnected(true);
connectInfo.setStartConnected(true);
disk.setConnectable(connectInfo);
-
+
return disk;
}
-
+
// vmdkDatastorePath: [datastore name] vmdkFilePath, create delta disk based on disk from template
- public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
+ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePath,
int sizeInMb, ManagedObjectReference morDs, VirtualDisk templateDisk, int deviceNumber, int contextNumber) throws Exception {
-
+
assert(templateDisk != null);
VirtualDeviceBackingInfo parentBacking = templateDisk.getBacking();
assert(parentBacking != null);
-
- // TODO Not sure if we need to check if the disk in template and the new disk needs to share the
+
+ // TODO Not sure if we need to check if the disk in template and the new disk needs to share the
// same datastore
VirtualDisk disk = new VirtualDisk();
if(parentBacking instanceof VirtualDiskFlatVer1BackingInfo) {
@@ -242,13 +243,13 @@ public class VmwareHelper {
} else {
throw new Exception("Unsupported disk backing: " + parentBacking.getClass().getCanonicalName());
}
-
+
if(controllerKey < 0)
controllerKey = vmMo.getIDEDeviceControllerKey();
disk.setControllerKey(controllerKey);
if(deviceNumber < 0)
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
-
+
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
disk.setCapacityInKB(sizeInMb*1024);
@@ -259,94 +260,94 @@ public class VmwareHelper {
disk.setConnectable(connectInfo);
return disk;
}
-
+
// vmdkDatastorePath: [datastore name] vmdkFilePath
- public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePathChain[],
+ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey, String vmdkDatastorePathChain[],
ManagedObjectReference morDs, int deviceNumber, int contextNumber) throws Exception {
-
+
assert(vmdkDatastorePathChain != null);
assert(vmdkDatastorePathChain.length >= 1);
-
+
VirtualDisk disk = new VirtualDisk();
-
+
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePathChain[0]);
- backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
+ backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
if(vmdkDatastorePathChain.length > 1) {
String[] parentDisks = new String[vmdkDatastorePathChain.length - 1];
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
parentDisks[i] = vmdkDatastorePathChain[i + 1];
-
+
setParentBackingInfo(backingInfo, morDs, parentDisks);
}
-
+
disk.setBacking(backingInfo);
if(controllerKey < 0)
controllerKey = vmMo.getIDEDeviceControllerKey();
if(deviceNumber < 0)
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
-
+
disk.setControllerKey(controllerKey);
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
-
+
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
connectInfo.setConnected(true);
connectInfo.setStartConnected(true);
disk.setConnectable(connectInfo);
-
+
return disk;
}
-
- public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
- Pair[] vmdkDatastorePathChain,
+
+ public static VirtualDevice prepareDiskDevice(VirtualMachineMO vmMo, int controllerKey,
+ Pair[] vmdkDatastorePathChain,
int deviceNumber, int contextNumber) throws Exception {
-
+
assert(vmdkDatastorePathChain != null);
assert(vmdkDatastorePathChain.length >= 1);
-
+
VirtualDisk disk = new VirtualDisk();
-
+
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDatastore(vmdkDatastorePathChain[0].second());
backingInfo.setFileName(vmdkDatastorePathChain[0].first());
- backingInfo.setDiskMode(VirtualDiskMode.persistent.toString());
+ backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
if(vmdkDatastorePathChain.length > 1) {
Pair[] parentDisks = new Pair[vmdkDatastorePathChain.length - 1];
for(int i = 0; i < vmdkDatastorePathChain.length - 1; i++)
parentDisks[i] = vmdkDatastorePathChain[i + 1];
-
+
setParentBackingInfo(backingInfo, parentDisks);
}
-
+
disk.setBacking(backingInfo);
if(controllerKey < 0)
controllerKey = vmMo.getIDEDeviceControllerKey();
if(deviceNumber < 0)
deviceNumber = vmMo.getNextDeviceNumber(controllerKey);
-
+
disk.setControllerKey(controllerKey);
disk.setKey(-contextNumber);
disk.setUnitNumber(deviceNumber);
-
+
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
connectInfo.setConnected(true);
connectInfo.setStartConnected(true);
disk.setConnectable(connectInfo);
-
+
return disk;
}
-
- private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
+
+ private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
ManagedObjectReference morDs, String[] parentDatastorePathList) {
-
+
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
parentBacking.setDatastore(morDs);
- parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
-
+ parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
+
if(parentDatastorePathList.length > 1) {
String[] nextDatastorePathList = new String[parentDatastorePathList.length -1];
for(int i = 0; i < parentDatastorePathList.length -1; i++)
@@ -354,17 +355,17 @@ public class VmwareHelper {
setParentBackingInfo(parentBacking, morDs, nextDatastorePathList);
}
parentBacking.setFileName(parentDatastorePathList[0]);
-
+
backingInfo.setParent(parentBacking);
}
-
- private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
+
+ private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo,
Pair[] parentDatastorePathList) {
-
+
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
parentBacking.setDatastore(parentDatastorePathList[0].second());
- parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
-
+ parentBacking.setDiskMode(VirtualDiskMode.PERSISTENT.toString());
+
if(parentDatastorePathList.length > 1) {
Pair[] nextDatastorePathList = new Pair[parentDatastorePathList.length -1];
for(int i = 0; i < parentDatastorePathList.length -1; i++)
@@ -372,33 +373,33 @@ public class VmwareHelper {
setParentBackingInfo(parentBacking, nextDatastorePathList);
}
parentBacking.setFileName(parentDatastorePathList[0].first());
-
+
backingInfo.setParent(parentBacking);
}
-
+
public static Pair prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs,
boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
-
+
boolean newCdRom = false;
VirtualCdrom cdRom = (VirtualCdrom )vmMo.getIsoDevice();
if(cdRom == null) {
newCdRom = true;
cdRom = new VirtualCdrom();
-
+
assert(vmMo.getIDEDeviceControllerKey() >= 0);
cdRom.setControllerKey(vmMo.getIDEDeviceControllerKey());
if(deviceNumber < 0)
deviceNumber = vmMo.getNextIDEDeviceNumber();
- cdRom.setUnitNumber(deviceNumber);
+ cdRom.setUnitNumber(deviceNumber);
cdRom.setKey(-contextNumber);
}
-
+
VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
cInfo.setConnected(connect);
cInfo.setStartConnected(connectAtBoot);
cdRom.setConnectable(cInfo);
-
+
if(isoDatastorePath != null) {
VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
backingInfo.setFileName(isoDatastorePath);
@@ -409,32 +410,32 @@ public class VmwareHelper {
backingInfo.setDeviceName("");
cdRom.setBacking(backingInfo);
}
-
+
return new Pair(cdRom, newCdRom);
}
-
+
public static VirtualDisk getRootDisk(VirtualDisk[] disks) {
if(disks.length == 1)
return disks[0];
-
+
// TODO : for now, always return the first disk as root disk
return disks[0];
}
-
- public static ManagedObjectReference findSnapshotInTree(VirtualMachineSnapshotTree[] snapTree, String findName) {
+
+ public static ManagedObjectReference findSnapshotInTree(List snapTree, String findName) {
assert(findName != null);
-
+
ManagedObjectReference snapMor = null;
- if (snapTree == null)
+ if (snapTree == null)
return snapMor;
-
- for (int i = 0; i < snapTree.length && snapMor == null; i++) {
- VirtualMachineSnapshotTree node = snapTree[i];
+
+ for (int i = 0; i < snapTree.size() && snapMor == null; i++) {
+ VirtualMachineSnapshotTree node = snapTree.get(i);
if (node.getName().equals(findName)) {
snapMor = node.getSnapshot();
} else {
- VirtualMachineSnapshotTree[] childTree = node.getChildSnapshotList();
+ List childTree = node.getChildSnapshotList();
snapMor = findSnapshotInTree(childTree, findName);
}
}
@@ -442,94 +443,94 @@ public class VmwareHelper {
}
public static byte[] composeDiskInfo(List> diskInfo, int disksInChain, boolean includeBase) throws IOException {
-
+
BufferedWriter out = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
+
try {
- out = new BufferedWriter(new OutputStreamWriter(bos));
+ out = new BufferedWriter(new OutputStreamWriter(bos));
out.write("disksInChain=" + disksInChain);
out.newLine();
-
+
out.write("disksInBackup=" + diskInfo.size());
out.newLine();
-
+
out.write("baseDiskIncluded=" + includeBase);
out.newLine();
-
+
int seq = disksInChain - 1;
for(Ternary item : diskInfo) {
out.write(String.format("disk%d.fileName=%s", seq, item.first()));
out.newLine();
-
+
out.write(String.format("disk%d.baseFileName=%s", seq, item.second()));
out.newLine();
-
+
if(item.third() != null) {
out.write(String.format("disk%d.parentFileName=%s", seq, item.third()));
out.newLine();
}
seq--;
}
-
+
out.newLine();
} finally {
if(out != null)
out.close();
}
-
+
return bos.toByteArray();
}
-
- public static OptionValue[] composeVncOptions(OptionValue[] optionsToMerge,
+
+ public static OptionValue[] composeVncOptions(OptionValue[] optionsToMerge,
boolean enableVnc, String vncPassword, int vncPort, String keyboardLayout) {
-
+
int numOptions = 3;
boolean needKeyboardSetup = false;
if(keyboardLayout != null && !keyboardLayout.isEmpty()) {
numOptions++;
needKeyboardSetup = true;
}
-
+
if(optionsToMerge != null)
numOptions += optionsToMerge.length;
-
+
OptionValue[] options = new OptionValue[numOptions];
int i = 0;
if(optionsToMerge != null) {
for(int j = 0; j < optionsToMerge.length; j++)
options[i++] = optionsToMerge[j];
}
-
+
options[i] = new OptionValue();
options[i].setKey("RemoteDisplay.vnc.enabled");
options[i++].setValue(enableVnc ? "true" : "false");
-
+
options[i] = new OptionValue();
options[i].setKey("RemoteDisplay.vnc.password");
options[i++].setValue(vncPassword);
-
+
options[i] = new OptionValue();
options[i].setKey("RemoteDisplay.vnc.port");
options[i++].setValue("" + vncPort);
-
+
if(needKeyboardSetup) {
options[i] = new OptionValue();
options[i].setKey("RemoteDisplay.vnc.keymap");
options[i++].setValue(keyboardLayout);
}
-
+
return options;
}
-
+
public static void setBasicVmConfig(VirtualMachineConfigSpec vmConfig, int cpuCount, int cpuSpeedMHz, int cpuReservedMhz,
int memoryMB, int memoryReserveMB, String guestOsIdentifier, boolean limitCpuUse) {
-
+
// VM config basics
vmConfig.setMemoryMB((long)memoryMB);
vmConfig.setNumCPUs(cpuCount);
-
+
ResourceAllocationInfo cpuInfo = new ResourceAllocationInfo();
if (limitCpuUse) {
cpuInfo.setLimit((long)(cpuSpeedMHz * cpuCount));
@@ -539,52 +540,52 @@ public class VmwareHelper {
cpuInfo.setReservation((long)cpuReservedMhz);
vmConfig.setCpuAllocation(cpuInfo);
-
+
ResourceAllocationInfo memInfo = new ResourceAllocationInfo();
memInfo.setLimit((long)memoryMB);
memInfo.setReservation((long)memoryReserveMB);
vmConfig.setMemoryAllocation(memInfo);
-
+
vmConfig.setGuestId(guestOsIdentifier);
}
-
+
public static ManagedObjectReference getDiskDeviceDatastore(VirtualDisk diskDevice) throws Exception {
VirtualDeviceBackingInfo backingInfo = diskDevice.getBacking();
assert(backingInfo instanceof VirtualDiskFlatVer2BackingInfo);
return ((VirtualDiskFlatVer2BackingInfo)backingInfo).getDatastore();
}
-
+
public static Object getPropValue(ObjectContent oc, String name) {
- DynamicProperty[] props = oc.getPropSet();
-
+ List props = oc.getPropSet();
+
for(DynamicProperty prop : props) {
if(prop.getName().equalsIgnoreCase(name))
return prop.getVal();
}
-
+
return null;
}
-
+
public static String getFileExtension(String fileName, String defaultExtension) {
int pos = fileName.lastIndexOf('.');
if(pos < 0)
return defaultExtension;
-
- return fileName.substring(pos);
+
+ return fileName.substring(pos);
}
-
+
public static boolean isSameHost(String ipAddress, String destName) {
// TODO : may need to do DNS lookup to compare IP address exactly
return ipAddress.equals(destName);
}
-
+
public static void deleteVolumeVmdkFiles(DatastoreMO dsMo, String volumeName, DatacenterMO dcMo) throws Exception {
String volumeDatastorePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumeName);
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
-
+
volumeDatastorePath = String.format("[%s] %s-flat.vmdk", dsMo.getName(), volumeName);
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
-
+
volumeDatastorePath = String.format("[%s] %s-delta.vmdk", dsMo.getName(), volumeName);
dsMo.deleteFile(volumeDatastorePath, dcMo.getMor(), true);
}
@@ -592,38 +593,50 @@ public class VmwareHelper {
public static String getExceptionMessage(Throwable e) {
return getExceptionMessage(e, false);
}
-
+
public static String getExceptionMessage(Throwable e, boolean printStack) {
- if(e instanceof MethodFault) {
- final StringWriter writer = new StringWriter();
- writer.append("Exception: " + e.getClass().getName() + "\n");
- writer.append("message: " + ((MethodFault)e).getFaultString() + "\n");
-
- if(printStack) {
- writer.append("stack: ");
- e.printStackTrace(new PrintWriter(writer));
- }
- return writer.toString();
- }
-
+ //TODO: in vim 5.1, exceptions do not have a base exception class, MethodFault becomes a FaultInfo that we can only get
+ // from individual exception through getFaultInfo, so we have to use reflection here to get MethodFault information.
+ try{
+ Class cls = e.getClass();
+ Method mth = cls.getDeclaredMethod("getFaultInfo", null);
+ if ( mth != null ){
+ Object fault = mth.invoke(e, null);
+ if (fault instanceof MethodFault) {
+ final StringWriter writer = new StringWriter();
+ writer.append("Exception: " + fault.getClass().getName() + "\n");
+ writer.append("message: " + ((MethodFault)fault).getFaultMessage() + "\n");
+
+ if(printStack) {
+ writer.append("stack: ");
+ e.printStackTrace(new PrintWriter(writer));
+ }
+ return writer.toString();
+ }
+ }
+ }
+ catch (Exception ex){
+
+ }
+
return ExceptionUtil.toString(e, printStack);
}
-
+
public static VirtualMachineMO pickOneVmOnRunningHost(List vmList, boolean bFirstFit) throws Exception {
List candidates = new ArrayList();
-
+
for(VirtualMachineMO vmMo : vmList) {
HostMO hostMo = vmMo.getRunningHost();
if(hostMo.isHyperHostConnected())
candidates.add(vmMo);
}
-
+
if(candidates.size() == 0)
return null;
-
+
if(bFirstFit)
return candidates.get(0);
-
+
Random random = new Random();
return candidates.get(random.nextInt(candidates.size()));
}