mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-04 00:02:37 +01:00
CLOUDSTACK-3886: check in for review request https://reviews.apache.org/r/13008/
This commit is contained in:
parent
36d8a5631d
commit
9a2148ffc3
@ -884,6 +884,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
if (work == null || work.getStep() != Step.Prepare) {
|
||||
throw new ConcurrentOperationException("Work steps have been changed: " + work);
|
||||
}
|
||||
|
||||
_workDao.updateStep(work, Step.Starting);
|
||||
|
||||
_agentMgr.send(destHostId, cmds);
|
||||
|
||||
@ -237,7 +237,6 @@ public class CloudOrchestrator implements OrchestrationService {
|
||||
//load vm instance and offerings and call virtualMachineManagerImpl
|
||||
VMInstanceVO vm = _vmDao.findByUuid(id);
|
||||
|
||||
|
||||
Pair<DiskOffering, Long> rootDiskOffering = new Pair<DiskOffering, Long>(null, null);
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
|
||||
rootDiskOffering.first(offering);
|
||||
|
||||
@ -271,6 +271,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
|
||||
// Determine the VM's OS description
|
||||
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
|
||||
to.setOs(guestOS.getDisplayName());
|
||||
to.setHostName(vm.getHostName());
|
||||
return to;
|
||||
}
|
||||
|
||||
|
||||
@ -161,6 +161,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
||||
int _portsPerDvPortGroup = 256;
|
||||
boolean _nexusVSwitchActive;
|
||||
boolean _fullCloneFlag;
|
||||
boolean _instanceNameFlag;
|
||||
String _serviceConsoleName;
|
||||
String _managemetPortGroupName;
|
||||
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
|
||||
@ -231,6 +232,14 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
||||
} else {
|
||||
_fullCloneFlag = Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
value = _configDao.getValue(Config.SetVmInternalNameUsingDisplayName.key());
|
||||
if (value == null) {
|
||||
_instanceNameFlag = false;
|
||||
} else {
|
||||
_instanceNameFlag = Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
_portsPerDvPortGroup = NumbersUtil.parseInt(_configDao.getValue(Config.VmwarePortsPerDVPortGroup.key()), _portsPerDvPortGroup);
|
||||
|
||||
_serviceConsoleName = _configDao.getValue(Config.VmwareServiceConsole.key());
|
||||
@ -505,6 +514,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
|
||||
@Override
|
||||
public void setupResourceStartupParams(Map<String, Object> params) {
|
||||
params.put("vmware.create.full.clone", _fullCloneFlag);
|
||||
params.put("vm.instancename.flag", _instanceNameFlag);
|
||||
params.put("service.console.name", _serviceConsoleName);
|
||||
params.put("management.portgroup.name", _managemetPortGroupName);
|
||||
params.put("vmware.reserve.cpu", _reserveCpu);
|
||||
|
||||
@ -314,47 +314,46 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
||||
String prevBackupUuid = cmd.getPrevBackupUuid();
|
||||
VirtualMachineMO workerVm=null;
|
||||
String workerVMName = null;
|
||||
String volumePath = cmd.getVolumePath();
|
||||
ManagedObjectReference morDs = null;
|
||||
DatastoreMO dsMo=null;
|
||||
String volumePath = cmd.getVolumePath();
|
||||
ManagedObjectReference morDs = null;
|
||||
DatastoreMO dsMo=null;
|
||||
|
||||
// By default assume failure
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String snapshotBackupUuid = null;
|
||||
// By default assume failure
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String snapshotBackupUuid = null;
|
||||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
VirtualMachineMO vmMo = null;
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPool().getUuid());
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
VirtualMachineMO vmMo = null;
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPool().getUuid());
|
||||
|
||||
try {
|
||||
vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
|
||||
}
|
||||
try {
|
||||
vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
|
||||
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
|
||||
if(vmMo == null) {
|
||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
|
||||
if(vmMo == null) {
|
||||
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
|
||||
|
||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||
|
||||
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
|
||||
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier.OTHER_GUEST.value(), morDs, false)) {
|
||||
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
vmMo = hyperHost.findVmOnHyperHost(workerVMName);
|
||||
if (vmMo == null) {
|
||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||
}
|
||||
workerVm = vmMo;
|
||||
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
|
||||
if (!hyperHost.createBlankVm(workerVMName, null, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier.OTHER_GUEST.value(), morDs, false)) {
|
||||
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
vmMo = hyperHost.findVmOnHyperHost(workerVMName);
|
||||
if (vmMo == null) {
|
||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||
}
|
||||
workerVm = vmMo;
|
||||
|
||||
// attach volume to worker VM
|
||||
// attach volume to worker VM
|
||||
String datastoreVolumePath = getVolumePathInDatastore(dsMo, volumePath + ".vmdk");
|
||||
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
|
||||
}
|
||||
|
||||
@ -365,6 +365,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
protected VmwareTrafficLabel _publicTrafficInfo = new VmwareTrafficLabel(TrafficType.Public);
|
||||
protected int _portsPerDvPortGroup;
|
||||
protected boolean _fullCloneFlag = false;
|
||||
protected boolean _instanceNameFlag = false;
|
||||
|
||||
protected boolean _reserveCpu = false;
|
||||
|
||||
@ -2572,8 +2573,18 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
}
|
||||
|
||||
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
|
||||
String vmName = vmSpec.getName();
|
||||
|
||||
String vmInternalCSName = null;
|
||||
String vmNameOnVcenter = null;
|
||||
if (vmSpec.getHostName() != null) {
|
||||
vmInternalCSName = vmSpec.getName();
|
||||
if (_instanceNameFlag == true)
|
||||
vmNameOnVcenter = vmSpec.getHostName();
|
||||
else
|
||||
vmNameOnVcenter = vmSpec.getName();
|
||||
} else {
|
||||
vmNameOnVcenter = vmInternalCSName = vmSpec.getName();
|
||||
}
|
||||
// Thus, vmInternalCSName always holds i-x-y, the cloudstack generated internal VM name.
|
||||
State state = State.Stopped;
|
||||
VmwareContext context = getServiceContext();
|
||||
try {
|
||||
@ -2581,12 +2592,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
|
||||
// mark VM as starting state so that sync() can know not to report stopped too early
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Starting);
|
||||
_vms.put(vmInternalCSName, State.Starting);
|
||||
}
|
||||
|
||||
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.valueOf(vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER));
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("VM " + vmName + " will be started with NIC device type: " + nicDeviceType);
|
||||
s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType);
|
||||
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
DiskTO[] disks = validateDisks(vmSpec.getDisks());
|
||||
@ -2600,9 +2611,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
|
||||
if (vmMo != null) {
|
||||
s_logger.info("VM " + vmName + " already exists, tear down devices for reconfiguration");
|
||||
s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration");
|
||||
if (getVmState(vmMo) != State.Stopped)
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class });
|
||||
@ -2611,13 +2622,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
|
||||
assert (morDc != null);
|
||||
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
|
||||
vmMo = hyperHost.findVmOnPeerHyperHost(vmInternalCSName);
|
||||
if (vmMo != null) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Found vm " + vmName + " at other host, relocate to " + hyperHost.getHyperHostName());
|
||||
s_logger.info("Found vm " + vmInternalCSName + " at other host, relocate to " + hyperHost.getHyperHostName());
|
||||
}
|
||||
|
||||
takeVmFromOtherHyperHost(hyperHost, vmName);
|
||||
takeVmFromOtherHyperHost(hyperHost, vmInternalCSName);
|
||||
|
||||
if (getVmState(vmMo) != State.Stopped)
|
||||
vmMo.safePowerOff(_shutdown_waitMs);
|
||||
@ -2634,16 +2645,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
}
|
||||
|
||||
assert (vmSpec.getMinSpeed() != null) && (rootDiskDataStoreDetails != null);
|
||||
if (!hyperHost.createBlankVm(vmName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
|
||||
if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
|
||||
vmSpec.getMinSpeed(), vmSpec.getLimitCpuUse(),(int)(vmSpec.getMaxRam()/(1024*1024)), ramMb,
|
||||
translateGuestOsIdentifier(vmSpec.getArch(), vmSpec.getOs()).value(), rootDiskDataStoreDetails.first(), false)) {
|
||||
throw new Exception("Failed to create VM. vmName: " + vmName);
|
||||
throw new Exception("Failed to create VM. vmName: " + vmInternalCSName);
|
||||
}
|
||||
}
|
||||
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
|
||||
if (vmMo == null) {
|
||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + vmName);
|
||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + vmInternalCSName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2931,10 +2942,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
String keyboardLayout = null;
|
||||
if(vmSpec.getDetails() != null)
|
||||
keyboardLayout = vmSpec.getDetails().get(VmDetailConstants.KEYBOARD);
|
||||
vmConfigSpec.getExtraConfig().addAll(Arrays.asList(configureVnc(extraOptions.toArray(new OptionValue[0]), hyperHost, vmName, vmSpec.getVncPassword(), keyboardLayout)));
|
||||
vmConfigSpec.getExtraConfig().addAll(Arrays.asList(configureVnc(extraOptions.toArray(new OptionValue[0]), hyperHost, vmInternalCSName, vmSpec.getVncPassword(), keyboardLayout)));
|
||||
|
||||
if (!vmMo.configureVm(vmConfigSpec)) {
|
||||
throw new Exception("Failed to configure VM before start. vmName: " + vmName);
|
||||
throw new Exception("Failed to configure VM before start. vmName: " + vmInternalCSName);
|
||||
}
|
||||
|
||||
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMask));
|
||||
@ -3049,7 +3060,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
}
|
||||
|
||||
if (!vmMo.powerOn()) {
|
||||
throw new Exception("Failed to start VM. vmName: " + vmName);
|
||||
throw new Exception("Failed to start VM. vmName: " + vmInternalCSName + " with hostname " + vmNameOnVcenter);
|
||||
}
|
||||
|
||||
state = State.Running;
|
||||
@ -3066,9 +3077,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
if (state != State.Stopped) {
|
||||
_vms.put(vmName, state);
|
||||
_vms.put(vmInternalCSName, state);
|
||||
} else {
|
||||
_vms.remove(vmName);
|
||||
_vms.remove(vmInternalCSName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3497,6 +3508,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
try {
|
||||
HashMap<String, State> newStates = getVmStates();
|
||||
|
||||
// getVmNames should return all i-x-y values.
|
||||
List<String> requestedVmNames = cmd.getVmNames();
|
||||
List<String> vmNames = new ArrayList<String>();
|
||||
|
||||
@ -3558,6 +3570,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
s_logger.info("Executing resource StopCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
// In the stop command, we're passed in the name of the VM as seen by cloudstack,
|
||||
// i.e., i-x-y. This is the internal VM name.
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
try {
|
||||
@ -5387,7 +5401,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
|
||||
ManagedObjectReference morPool = hyperHost.getHyperHostOwnerResourcePool();
|
||||
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
|
||||
//createVMLinkedClone(vmTemplate, dcMo, dsMo, vmdkName, morDatastore, morPool);
|
||||
if (!_fullCloneFlag) {
|
||||
createVMLinkedClone(vmTemplate, dcMo, dsMo, vmdkName, morDatastore, morPool);
|
||||
} else {
|
||||
@ -5516,14 +5529,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
for(ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
String name = null;
|
||||
String vmName = null;
|
||||
String internalName = null;
|
||||
boolean template = false;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
|
||||
GregorianCalendar bootTime = null;
|
||||
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getName().equals("name"))
|
||||
name = prop.getVal().toString();
|
||||
if (prop.getName().equals("name"))
|
||||
vmName = prop.getVal().toString();
|
||||
else if(prop.getName().equals("config.template"))
|
||||
template = (Boolean)prop.getVal();
|
||||
else if(prop.getName().equals("runtime.powerState"))
|
||||
@ -5532,6 +5546,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
bootTime = (GregorianCalendar)prop.getVal();
|
||||
}
|
||||
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
internalName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
||||
String name = null;
|
||||
if (internalName != null) {
|
||||
name = internalName;
|
||||
} else {
|
||||
name = vmName;
|
||||
}
|
||||
if(!template && name.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
|
||||
boolean recycle = false;
|
||||
|
||||
@ -5544,7 +5568,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
if(recycle) {
|
||||
s_logger.info("Recycle pending worker VM: " + name);
|
||||
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
vmMo.powerOff();
|
||||
vmMo.destroy();
|
||||
}
|
||||
@ -5963,6 +5986,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
|
||||
private HashMap<String, State> getVmStates() throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
// CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. This was earlier stored in name. Now, name can be either the hostname or
|
||||
// the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template" });
|
||||
|
||||
HashMap<String, State> newStates = new HashMap<String, State>();
|
||||
@ -5973,20 +5998,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
|
||||
boolean isTemplate = false;
|
||||
String name = null;
|
||||
String VMInternalCSName = null;
|
||||
VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
|
||||
for (DynamicProperty objProp : objProps) {
|
||||
if (objProp.getName().equals("config.template")) {
|
||||
if (objProp.getVal().toString().equalsIgnoreCase("true")) {
|
||||
isTemplate = true;
|
||||
}
|
||||
} else if (objProp.getName().equals("name")) {
|
||||
name = (String) objProp.getVal();
|
||||
} else if (objProp.getName().equals("runtime.powerState")) {
|
||||
powerState = (VirtualMachinePowerState) objProp.getVal();
|
||||
} else if (objProp.getName().equals("name")) {
|
||||
name = (String) objProp.getVal();
|
||||
} else {
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
VMInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if (VMInternalCSName != null)
|
||||
name = VMInternalCSName;
|
||||
|
||||
if (!isTemplate) {
|
||||
newStates.put(name, convertState(powerState));
|
||||
@ -6025,16 +6056,26 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
String name = null;
|
||||
String numberCPUs = null;
|
||||
String maxCpuUsage = null;
|
||||
|
||||
String vmNameOnVcenter = null;
|
||||
String vmInternalCSName = null;
|
||||
for (DynamicProperty objProp : objProps) {
|
||||
if (objProp.getName().equals("name")) {
|
||||
name = objProp.getVal().toString();
|
||||
vmNameOnVcenter = objProp.getVal().toString();
|
||||
} else if (objProp.getName().equals("summary.config.numCpu")) {
|
||||
numberCPUs = objProp.getVal().toString();
|
||||
} else if (objProp.getName().equals("summary.quickStats.overallCpuUsage")) {
|
||||
maxCpuUsage = objProp.getVal().toString();
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
||||
if (vmInternalCSName != null) {
|
||||
name = vmInternalCSName;
|
||||
} else {
|
||||
name = vmNameOnVcenter;
|
||||
}
|
||||
|
||||
if (!vmNames.contains(name)) {
|
||||
continue;
|
||||
@ -6343,6 +6384,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
} else {
|
||||
_fullCloneFlag = false;
|
||||
}
|
||||
|
||||
value = params.get("vm.instancename.flag").toString();
|
||||
if (value != null && value.equalsIgnoreCase("true")) {
|
||||
_instanceNameFlag = true;
|
||||
} else {
|
||||
_instanceNameFlag = false;
|
||||
}
|
||||
|
||||
value = (String)params.get("scripts.timeout");
|
||||
int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
@ -104,11 +104,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
Integer shutdownWaitMs,
|
||||
PremiumSecondaryStorageResource storageResource) {
|
||||
this.hostService = hostService;
|
||||
this._fullCloneFlag = fullCloneFlag;
|
||||
_fullCloneFlag = fullCloneFlag;
|
||||
this.mountService = mountService;
|
||||
this._timeout = timeout;
|
||||
_timeout = timeout;
|
||||
this.resource = resource;
|
||||
this._shutdown_waitMs = shutdownWaitMs;
|
||||
_shutdown_waitMs = shutdownWaitMs;
|
||||
_gson = GsonHelper.getGsonLogger();
|
||||
}
|
||||
|
||||
@ -317,8 +317,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
PrimaryDataStoreTO srcStore = (PrimaryDataStoreTO)template.getDataStore();
|
||||
|
||||
try {
|
||||
VmwareContext context = this.hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(context, null);
|
||||
VmwareContext context = hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
|
||||
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
|
||||
VirtualMachineMO vmMo = null;
|
||||
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid());
|
||||
@ -396,7 +396,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
this.hostService.invalidateServiceContext(null);
|
||||
hostService.invalidateServiceContext(null);
|
||||
}
|
||||
|
||||
String msg = "clone volume from base image failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
@ -1050,6 +1050,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
workerVMName = hostService.getWorkerName(context, cmd, 0);
|
||||
|
||||
vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, workerVMName);
|
||||
|
||||
if (vmMo == null) {
|
||||
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
|
||||
}
|
||||
@ -1069,7 +1070,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
hostService.getWorkerName(context, cmd, 1));
|
||||
|
||||
success = (snapshotBackupUuid != null);
|
||||
|
||||
if (!success) {
|
||||
details = "Failed to backUp the snapshot with uuid: " + snapshotUuid + " to secondary storage.";
|
||||
return new CopyCmdAnswer(details);
|
||||
@ -1132,7 +1132,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
VolumeObjectTO volumeTO = (VolumeObjectTO)disk.getData();
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(this.hostService.getServiceContext(null), null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null);
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + vmName;
|
||||
@ -1143,7 +1143,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
ManagedObjectReference morDs = null;
|
||||
|
||||
if (isAttach && isManaged) {
|
||||
morDs = this.hostService.handleDatastoreAndVmdkAttach(cmd, iScsiName, storageHost, storagePort,
|
||||
morDs = hostService.handleDatastoreAndVmdkAttach(cmd, iScsiName, storageHost, storagePort,
|
||||
initiatorUsername, initiatorPassword, targetUsername, targetPassword);
|
||||
}
|
||||
else {
|
||||
@ -1169,7 +1169,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
vmMo.detachDisk(datastoreVolumePath, false);
|
||||
|
||||
if (isManaged) {
|
||||
this.hostService.handleDatastoreAndVmdkDetach(iScsiName, storageHost, storagePort);
|
||||
hostService.handleDatastoreAndVmdkDetach(iScsiName, storageHost, storagePort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1177,7 +1177,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
this.hostService.invalidateServiceContext(null);
|
||||
hostService.invalidateServiceContext(null);
|
||||
}
|
||||
|
||||
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
@ -1194,7 +1194,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
String storeName = getSecondaryDatastoreUUID(storeUrl);
|
||||
URI uri = new URI(storeUrl);
|
||||
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(this.hostService.getServiceContext(null), null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null);
|
||||
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""));
|
||||
|
||||
if (morDatastore == null) {
|
||||
@ -1206,7 +1206,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
|
||||
private Answer attachIso(DiskTO disk, boolean isAttach, String vmName) {
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(this.hostService.getServiceContext(null), null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null);
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + vmName;
|
||||
@ -1254,7 +1254,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
|
||||
// TODO, check if iso is already attached, or if there is a previous
|
||||
// attachment
|
||||
DatastoreMO secondaryDsMo = new DatastoreMO(this.hostService.getServiceContext(null), morSecondaryDs);
|
||||
DatastoreMO secondaryDsMo = new DatastoreMO(hostService.getServiceContext(null), morSecondaryDs);
|
||||
String storeName = secondaryDsMo.getName();
|
||||
String isoDatastorePath = String.format("[%s] %s/%s", storeName, isoStorePathFromRoot, isoFileName);
|
||||
|
||||
@ -1268,7 +1268,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
this.hostService.invalidateServiceContext(null);
|
||||
hostService.invalidateServiceContext(null);
|
||||
}
|
||||
|
||||
if(isAttach) {
|
||||
@ -1299,8 +1299,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
|
||||
|
||||
try {
|
||||
VmwareContext context = this.hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(context, null);
|
||||
VmwareContext context = hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
|
||||
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
|
||||
|
||||
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid());
|
||||
@ -1312,8 +1312,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
// create data volume
|
||||
VirtualMachineMO vmMo = null;
|
||||
String volumeUuid = UUID.randomUUID().toString().replace("-", "");
|
||||
String volumeDatastorePath = dsMo.getDatastorePath(volumeUuid + ".vmdk");
|
||||
|
||||
String volumeDatastorePath = dsMo.getDatastorePath(volumeUuid + ".vmdk");
|
||||
String dummyVmName = this.hostService.getWorkerName(context, cmd, 0);
|
||||
try {
|
||||
s_logger.info("Create worker VM " + dummyVmName);
|
||||
@ -1344,7 +1344,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
this.hostService.invalidateServiceContext(null);
|
||||
hostService.invalidateServiceContext(null);
|
||||
}
|
||||
|
||||
String msg = "create volume failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
@ -1382,8 +1382,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
*/
|
||||
|
||||
try {
|
||||
VmwareContext context = this.hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = this.hostService.getHyperHost(context, null);
|
||||
VmwareContext context = hostService.getServiceContext(null);
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
|
||||
VolumeObjectTO vol = (VolumeObjectTO)cmd.getData();
|
||||
PrimaryDataStoreTO store = (PrimaryDataStoreTO)vol.getDataStore();
|
||||
|
||||
@ -1422,7 +1422,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
for (NetworkDetails netDetails : networks) {
|
||||
if (netDetails.getGCTag() != null && netDetails.getGCTag().equalsIgnoreCase("true")) {
|
||||
if (netDetails.getVMMorsOnNetwork() == null || netDetails.getVMMorsOnNetwork().length == 1) {
|
||||
this.resource.cleanupNetwork(hostMo, netDetails);
|
||||
resource.cleanupNetwork(hostMo, netDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1503,7 +1503,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
this.hostService.invalidateServiceContext(null);
|
||||
hostService.invalidateServiceContext(null);
|
||||
}
|
||||
|
||||
String msg = "delete volume failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
|
||||
@ -259,7 +259,8 @@ public enum Config {
|
||||
EnableEC2API("Advanced", ManagementServer.class, Boolean.class, "enable.ec2.api", "false", "enable EC2 API on CloudStack", null),
|
||||
EnableS3API("Advanced", ManagementServer.class, Boolean.class, "enable.s3.api", "false", "enable Amazon S3 API on CloudStack", null),
|
||||
RecreateSystemVmEnabled("Advanced", ManagementServer.class, Boolean.class, "recreate.systemvm.enabled", "false", "If true, will recreate system vm root disk whenever starting system vm", "true,false"),
|
||||
SetVmInternalNameUsingDisplayName("Advanced", ManagementServer.class, Boolean.class, "vm.instancename.flag", "false", "If true, will append guest VM's display Name (if set) to its internal instance name", "true,false"),
|
||||
SetVmInternalNameUsingDisplayName("Advanced", ManagementServer.class, Boolean.class, "vm.instancename.flag", "false",
|
||||
"If set to true, will set guest VM's name as it appears on the hypervisor, to its hostname", "true,false"),
|
||||
IncorrectLoginAttemptsAllowed("Advanced", ManagementServer.class, Integer.class, "incorrect.login.attempts.allowed", "5", "Incorrect login attempts allowed before the user is disabled", null),
|
||||
// Ovm
|
||||
OvmPublicNetwork("Hidden", ManagementServer.class, String.class, "ovm.public.network.device", null, "Specify the public bridge on host for public network", null),
|
||||
|
||||
@ -299,11 +299,6 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
|
||||
return;
|
||||
}
|
||||
|
||||
if(vm.getHypervisorType() == HypervisorType.VMware) {
|
||||
s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!investigate) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM does not require investigation so I'm marking it as Stopped: " + vm.toString());
|
||||
@ -342,6 +337,11 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
|
||||
}
|
||||
}
|
||||
|
||||
if(vm.getHypervisorType() == HypervisorType.VMware) {
|
||||
s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
|
||||
return;
|
||||
}
|
||||
|
||||
List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
|
||||
int maxRetries = 0;
|
||||
for (HaWorkVO item : items) {
|
||||
|
||||
@ -1538,14 +1538,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
new UserVmStateListener(_usageEventDao, _networkDao, _nicDao));
|
||||
|
||||
value = _configDao.getValue(Config.SetVmInternalNameUsingDisplayName.key());
|
||||
|
||||
if(value == null) {
|
||||
_instanceNameFlag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_instanceNameFlag = Boolean.parseBoolean(value);
|
||||
}
|
||||
_instanceNameFlag = (value == null)?false:Boolean.parseBoolean(value);
|
||||
|
||||
_scaleRetry = NumbersUtil.parseInt(configs.get(Config.ScaleRetry.key()), 2);
|
||||
|
||||
@ -2716,58 +2709,59 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
|
||||
long id = _vmDao.getNextInSequence(Long.class, "id");
|
||||
|
||||
String instanceName;
|
||||
if (_instanceNameFlag && displayName != null) {
|
||||
// Check if the displayName conforms to RFC standards.
|
||||
checkNameForRFCCompliance(displayName);
|
||||
instanceName = VirtualMachineName.getVmName(id, owner.getId(), displayName);
|
||||
if (instanceName.length() > MAX_VM_NAME_LEN) {
|
||||
throw new InvalidParameterValueException("Specified display name " + displayName + " causes VM name to exceed 80 characters in length");
|
||||
}
|
||||
// Search whether there is already an instance with the same instance name
|
||||
// that is not in the destroyed or expunging state.
|
||||
VMInstanceVO vm = _vmInstanceDao.findVMByInstanceName(instanceName);
|
||||
if (vm != null && vm.getState() != VirtualMachine.State.Expunging) {
|
||||
throw new InvalidParameterValueException("There already exists a VM by the display name supplied");
|
||||
}
|
||||
} else {
|
||||
instanceName = VirtualMachineName.getVmName(id, owner.getId(), _instance);
|
||||
if (hostName != null) {
|
||||
// Check is hostName is RFC compliant
|
||||
checkNameForRFCCompliance(hostName);
|
||||
}
|
||||
|
||||
String instanceName = null;
|
||||
String uuidName = UUID.randomUUID().toString();
|
||||
|
||||
// verify hostname information
|
||||
if (hostName == null) {
|
||||
hostName = uuidName;
|
||||
} else {
|
||||
//1) check is hostName is RFC compliant
|
||||
checkNameForRFCCompliance(hostName);
|
||||
// 2) hostName has to be unique in the network domain
|
||||
Map<String, List<Long>> ntwkDomains = new HashMap<String, List<Long>>();
|
||||
for (NetworkVO network : networkList) {
|
||||
String ntwkDomain = network.getNetworkDomain();
|
||||
if (!ntwkDomains.containsKey(ntwkDomain)) {
|
||||
List<Long> ntwkIds = new ArrayList<Long>();
|
||||
ntwkIds.add(network.getId());
|
||||
ntwkDomains.put(ntwkDomain, ntwkIds);
|
||||
if (_instanceNameFlag && hypervisor.equals(HypervisorType.VMware)) {
|
||||
if (hostName == null) {
|
||||
if (displayName != null) {
|
||||
hostName = displayName;
|
||||
} else {
|
||||
List<Long> ntwkIds = ntwkDomains.get(ntwkDomain);
|
||||
ntwkIds.add(network.getId());
|
||||
ntwkDomains.put(ntwkDomain, ntwkIds);
|
||||
hostName = uuidName;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hostName == null) {
|
||||
hostName = uuidName;
|
||||
}
|
||||
}
|
||||
|
||||
for (String ntwkDomain : ntwkDomains.keySet()) {
|
||||
for (Long ntwkId : ntwkDomains.get(ntwkDomain)) {
|
||||
// * get all vms hostNames in the network
|
||||
List<String> hostNames = _vmInstanceDao
|
||||
.listDistinctHostNames(ntwkId);
|
||||
// * verify that there are no duplicates
|
||||
if (hostNames.contains(hostName)) {
|
||||
throw new InvalidParameterValueException("The vm with hostName " + hostName
|
||||
+ " already exists in the network domain: " + ntwkDomain + "; network="
|
||||
+ _networkModel.getNetwork(ntwkId));
|
||||
}
|
||||
instanceName = VirtualMachineName.getVmName(id, owner.getId(), _instance);
|
||||
|
||||
// Check if VM with instanceName already exists.
|
||||
VMInstanceVO vmObj = _vmInstanceDao.findVMByInstanceName(instanceName);
|
||||
if (vmObj != null && vmObj.getState() != VirtualMachine.State.Expunging) {
|
||||
throw new InvalidParameterValueException("There already exists a VM by the display name supplied");
|
||||
}
|
||||
|
||||
// Check that hostName is unique in the network domain
|
||||
Map<String, List<Long>> ntwkDomains = new HashMap<String, List<Long>>();
|
||||
for (NetworkVO network : networkList) {
|
||||
String ntwkDomain = network.getNetworkDomain();
|
||||
if (!ntwkDomains.containsKey(ntwkDomain)) {
|
||||
List<Long> ntwkIds = new ArrayList<Long>();
|
||||
ntwkIds.add(network.getId());
|
||||
ntwkDomains.put(ntwkDomain, ntwkIds);
|
||||
} else {
|
||||
List<Long> ntwkIds = ntwkDomains.get(ntwkDomain);
|
||||
ntwkIds.add(network.getId());
|
||||
ntwkDomains.put(ntwkDomain, ntwkIds);
|
||||
}
|
||||
}
|
||||
|
||||
for (String ntwkDomain : ntwkDomains.keySet()) {
|
||||
for (Long ntwkId : ntwkDomains.get(ntwkDomain)) {
|
||||
// * get all vms hostNames in the network
|
||||
List<String> hostNames = _vmInstanceDao.listDistinctHostNames(ntwkId);
|
||||
// * verify that there are no duplicates
|
||||
if (hostNames.contains(hostName)) {
|
||||
throw new InvalidParameterValueException("The vm with hostName " + hostName
|
||||
+ " already exists in the network domain: " + ntwkDomain + "; network="
|
||||
+ _networkModel.getNetwork(ntwkId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ CREATE TABLE `cloud`.`load_balancer_healthcheck_policies` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.instancename.flag', 'false', 'Append guest VM display Name (if set) to the internal name of the VM');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.instancename.flag', 'false', 'If set to true, will set guest VM\'s name as it appears on the hypervisor, to its hostname');
|
||||
|
||||
UPDATE `cloud`.`guest_os` SET category_id=10 where id=59;
|
||||
INSERT IGNORE INTO `cloud`.`guest_os` (id, uuid, category_id, display_name) VALUES (165, UUID(), 6, 'Windows 8 (32-bit)');
|
||||
|
||||
@ -270,7 +270,7 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createBlankVm(String vmName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
public boolean createBlankVm(String vmName, String vmInternalCSName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
@ -278,7 +278,7 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
||||
+ ", cpuSpeedMhz: " + cpuSpeedMHz + ", cpuReservedMHz: " + cpuReservedMHz + ", limitCpu: " + limitCpuUse + ", memoryMB: " + memoryMB
|
||||
+ ", guestOS: " + guestOsIdentifier + ", datastore: " + morDs.getValue() + ", snapshotDirToParent: " + snapshotDirToParent);
|
||||
|
||||
boolean result = HypervisorHostHelper.createBlankVm(this, vmName, cpuCount, cpuSpeedMHz, cpuReservedMHz, limitCpuUse,
|
||||
boolean result = HypervisorHostHelper.createBlankVm(this, vmName, vmInternalCSName, cpuCount, cpuSpeedMHz, cpuReservedMHz, limitCpuUse,
|
||||
memoryMB, memoryReserveMB, guestOsIdentifier, morDs, snapshotDirToParent);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
|
||||
@ -22,4 +22,5 @@ public interface CustomFieldConstants {
|
||||
public final static String CLOUD_GC_DVP = "cloud.gc.dvp";
|
||||
public final static String CLOUD_NIC_MASK = "cloud.nic.mask";
|
||||
public final static String CLOUD_ZONE = "cloud.zone";
|
||||
public final static String CLOUD_VM_INTERNAL_NAME = "cloud.vm.internal.name";
|
||||
}
|
||||
|
||||
@ -17,15 +17,19 @@
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xerces.impl.xs.identity.Selector.Matcher;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.vim25.AboutInfo;
|
||||
import com.vmware.vim25.AlreadyExistsFaultMsg;
|
||||
@ -57,6 +61,7 @@ import com.vmware.vim25.PropertyFilterSpec;
|
||||
import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.VirtualMachineConfigSpec;
|
||||
import com.vmware.vim25.VirtualMachinePowerState;
|
||||
import com.vmware.vim25.VirtualNicManagerNetConfig;
|
||||
import com.vmware.vim25.NasDatastoreInfo;
|
||||
|
||||
@ -65,6 +70,7 @@ import java.util.Arrays;
|
||||
public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
private static final Logger s_logger = Logger.getLogger(HostMO.class);
|
||||
Map<String, VirtualMachineMO> _vmCache = new HashMap<String, VirtualMachineMO>();
|
||||
//Map<String, String> _vmInternalNameMapCache = new HashMap<String, String>();
|
||||
|
||||
public HostMO (VmwareContext context, ManagedObjectReference morHost) {
|
||||
super(context, morHost);
|
||||
@ -465,19 +471,34 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized VirtualMachineMO findVmOnHyperHost(String name) throws Exception {
|
||||
public synchronized VirtualMachineMO findVmOnHyperHost(String vmName) throws Exception {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("find VM " + name + " on host");
|
||||
s_logger.debug("find VM " + vmName + " on host");
|
||||
|
||||
VirtualMachineMO vmMo = _vmCache.get(name);
|
||||
VirtualMachineMO vmMo = _vmCache.get(vmName);
|
||||
if(vmMo != null) {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("VM " + name + " found in host cache");
|
||||
s_logger.debug("VM " + vmName + " found in host cache");
|
||||
return vmMo;
|
||||
}
|
||||
|
||||
s_logger.info("VM " + vmName + " not found in host cache");
|
||||
loadVmCache();
|
||||
return _vmCache.get(name);
|
||||
|
||||
return _vmCache.get(vmName);
|
||||
}
|
||||
|
||||
private boolean isUserVMInternalCSName(String vmInternalCSName) {
|
||||
// CS generated internal names for user VMs are always of the format i-x-y.
|
||||
|
||||
String internalCSUserVMNamingPattern = "^[i][-][0-9]+[-][0-9]+[-]";
|
||||
Pattern p = Pattern.compile(internalCSUserVMNamingPattern);
|
||||
java.util.regex.Matcher m = p.matcher(vmInternalCSName);
|
||||
if (m.find()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadVmCache() throws Exception {
|
||||
@ -486,15 +507,35 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
|
||||
_vmCache.clear();
|
||||
|
||||
// name is the name of the VM as it appears in vCenter. The CLOUD_VM_INTERNAL_NAME custom
|
||||
// field value contains the name of the VM as it is maintained internally by cloudstack (i-x-y).
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
String vmName = oc.getPropSet().get(0).getVal().toString();
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if (props != null) {
|
||||
String vmVcenterName = null;
|
||||
String vmInternalCSName = null;
|
||||
for (DynamicProperty prop : props) {
|
||||
if (prop.getName().equals("name")) {
|
||||
vmVcenterName = prop.getVal().toString();
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(_context, oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
String vmName = null;
|
||||
if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName)) {
|
||||
vmName = vmInternalCSName;
|
||||
} else {
|
||||
vmName = vmVcenterName;
|
||||
}
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("put " + vmName + " into host cache");
|
||||
if(s_logger.isTraceEnabled())
|
||||
s_logger.trace("put " + vmName + " into host cache");
|
||||
|
||||
_vmCache.put(vmName, new VirtualMachineMO(_context, oc.getObj()));
|
||||
_vmCache.put(vmName, new VirtualMachineMO(_context, oc.getObj()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -530,33 +571,38 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
} else {
|
||||
s_logger.error("VMware createVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getVmVncPortsOnHost() throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(
|
||||
new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]" }
|
||||
);
|
||||
new String[] { "name", "config.extraConfig[\"RemoteDisplay.vnc.port\"]" }
|
||||
);
|
||||
|
||||
HashMap<String, Integer> portInfo = new HashMap<String, Integer>();
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
String name = null;
|
||||
String vmName = null;
|
||||
String value = null;
|
||||
String vmInternalCSName = null;
|
||||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getName().equals("name")) {
|
||||
name = (String)objProp.getVal();
|
||||
} else {
|
||||
OptionValue optValue = (OptionValue)objProp.getVal();
|
||||
value = (String)optValue.getValue();
|
||||
}
|
||||
}
|
||||
vmName = (String)objProp.getVal();
|
||||
} else {
|
||||
OptionValue optValue = (OptionValue)objProp.getVal();
|
||||
value = (String)optValue.getValue();
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(_context, oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName))
|
||||
vmName = vmInternalCSName;
|
||||
|
||||
if(name != null && value != null) {
|
||||
portInfo.put(name, Integer.parseInt(value));
|
||||
if(vmName != null && value != null) {
|
||||
portInfo.put(vmName, Integer.parseInt(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -689,7 +735,7 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createBlankVm(String vmName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
public boolean createBlankVm(String vmName, String vmInternalCSName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
@ -697,7 +743,7 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
+ ", cpuSpeedMhz: " + cpuSpeedMHz + ", cpuReservedMHz: " + cpuReservedMHz + ", limitCpu: " + limitCpuUse + ", memoryMB: " + memoryMB
|
||||
+ ", guestOS: " + guestOsIdentifier + ", datastore: " + morDs.getValue() + ", snapshotDirToParent: " + snapshotDirToParent);
|
||||
|
||||
boolean result = HypervisorHostHelper.createBlankVm(this, vmName, cpuCount, cpuSpeedMHz, cpuReservedMHz, limitCpuUse,
|
||||
boolean result = HypervisorHostHelper.createBlankVm(this, vmName, vmInternalCSName, cpuCount, cpuSpeedMHz, cpuReservedMHz, limitCpuUse,
|
||||
memoryMB, memoryReserveMB, guestOsIdentifier, morDs, snapshotDirToParent);
|
||||
|
||||
if(s_logger.isTraceEnabled())
|
||||
|
||||
@ -46,6 +46,7 @@ import com.vmware.vim25.HttpNfcLeaseState;
|
||||
import com.vmware.vim25.LongPolicy;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
import com.vmware.vim25.OptionValue;
|
||||
import com.vmware.vim25.OvfCreateImportSpecParams;
|
||||
import com.vmware.vim25.OvfCreateImportSpecResult;
|
||||
import com.vmware.vim25.OvfFileItem;
|
||||
@ -94,10 +95,27 @@ public class HypervisorHostHelper {
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty prop = oc.getPropSet().get(0);
|
||||
assert(prop != null);
|
||||
if(prop.getVal().toString().equals(name))
|
||||
return new VirtualMachineMO(context, oc.getObj());
|
||||
String vmNameInvCenter = null;
|
||||
String vmInternalCSName = null;
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getName().equals("name")) {
|
||||
vmNameInvCenter = (String)objProp.getVal();
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(context, oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
try {
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to retrieve custom field value for internal VM name");
|
||||
}
|
||||
if ( (vmNameInvCenter != null && name.equalsIgnoreCase(vmNameInvCenter))
|
||||
|| (vmInternalCSName != null && name.equalsIgnoreCase(vmInternalCSName)) ) {
|
||||
return vmMo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -1122,7 +1140,7 @@ public class HypervisorHostHelper {
|
||||
return morNetwork;
|
||||
}
|
||||
|
||||
public static boolean createBlankVm(VmwareHypervisorHost host, String vmName,
|
||||
public static boolean createBlankVm(VmwareHypervisorHost host, String vmName, String vmInternalCSName,
|
||||
int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB, String guestOsIdentifier,
|
||||
ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
|
||||
|
||||
@ -1132,6 +1150,9 @@ public class HypervisorHostHelper {
|
||||
// VM config basics
|
||||
VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
|
||||
vmConfig.setName(vmName);
|
||||
if (vmInternalCSName == null)
|
||||
vmInternalCSName = vmName;
|
||||
|
||||
VmwareHelper.setBasicVmConfig(vmConfig, cpuCount, cpuSpeedMHz, cpuReservedMHz, memoryMB, memoryReserveMB, guestOsIdentifier, limitCpuUse);
|
||||
|
||||
// Scsi controller
|
||||
@ -1159,16 +1180,25 @@ public class HypervisorHostHelper {
|
||||
vmConfig.getDeviceChange().add(scsiControllerSpec);
|
||||
vmConfig.getDeviceChange().add(videoDeviceSpec);
|
||||
if(host.createVm(vmConfig)) {
|
||||
// Here, when attempting to find the VM, we need to use the name
|
||||
// with which we created it. This is the only such place where
|
||||
// we need to do this. At all other places, we always use the
|
||||
// VM's internal cloudstack generated name. Here, we cannot use
|
||||
// the internal name because we can set the internal name into the
|
||||
// VM's custom field CLOUD_VM_INTERNAL_NAME only after we create
|
||||
// the VM.
|
||||
VirtualMachineMO vmMo = host.findVmOnHyperHost(vmName);
|
||||
assert(vmMo != null);
|
||||
|
||||
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME, vmInternalCSName);
|
||||
|
||||
int ideControllerKey = -1;
|
||||
while(ideControllerKey < 0) {
|
||||
ideControllerKey = vmMo.tryGetIDEDeviceControllerKey();
|
||||
if(ideControllerKey >= 0)
|
||||
break;
|
||||
|
||||
s_logger.info("Waiting for IDE controller be ready in VM: " + vmName);
|
||||
s_logger.info("Waiting for IDE controller be ready in VM: " + vmInternalCSName);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
@ -1566,7 +1566,7 @@ public class VirtualMachineMO extends BaseMO {
|
||||
HostMO hostMo = getRunningHost();
|
||||
VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
|
||||
|
||||
if(!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
|
||||
if(!hostMo.createBlankVm(clonedVmName, null, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
|
||||
throw new Exception("Unable to create a blank VM");
|
||||
|
||||
VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
|
||||
|
||||
@ -46,7 +46,7 @@ public interface VmwareHypervisorHost {
|
||||
VirtualMachineMO findVmOnPeerHyperHost(String name) throws Exception;
|
||||
|
||||
boolean createVm(VirtualMachineConfigSpec vmSpec) throws Exception;
|
||||
boolean createBlankVm(String vmName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
boolean createBlankVm(String vmName, String vmInternalCSName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB,
|
||||
String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception;
|
||||
void importVmFromOVF(String ovfFilePath, String vmName, DatastoreMO dsMo, String diskOption) throws Exception;
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
|
||||
public class VmwareMOTest {
|
||||
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
/*
|
||||
VmwareContext context = TestVmwareContextFactory.create("10.223.80.29", "Administrator", "Suite219");
|
||||
|
||||
DatacenterMO dcMo = new DatacenterMO(context, "vsphere5");
|
||||
HostMO hostMo = new HostMO(context, dcMo.findHost("10.223.80.27"));
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(context, dcMo.findDatastore("Storage1"));
|
||||
hostMo.importVmFromOVF("/tmp/ubuntu-12.04.1-desktop-i386-nest-13.02.04.ovf", "Test123", dsMo, "thin");
|
||||
|
||||
|
||||
VirtualMachineMO vmMo = dcMo.findVm("i-2-3-VM");
|
||||
Thread.sleep(10*60000);
|
||||
vmMo.removeAllSnapshots();
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user