mirror of https://github.com/apache/cloudstack.git
Merge branch 'master' of ssh://git.cloud.com/var/lib/git/cloudstack-oss
This commit is contained in:
commit
b01a18a5ba
|
|
@ -39,6 +39,7 @@ import com.cloud.agent.api.to.StorageFilerTO;
|
|||
import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
|
||||
import com.cloud.hypervisor.vmware.mo.DatacenterMO;
|
||||
import com.cloud.hypervisor.vmware.mo.DatastoreMO;
|
||||
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
|
||||
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
|
||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
|
|
@ -122,11 +123,11 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
|
||||
VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true);
|
||||
|
||||
if (templateMo == null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getPoolUuid());
|
||||
|
||||
if (templateMo == null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid());
|
||||
assert (morDs != null);
|
||||
DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
|
||||
|
||||
|
|
@ -170,10 +171,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
VirtualMachineMO vmMo = null;
|
||||
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
morDs = hyperHost.findDatastore(cmd.getPool().getUuid());
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPool().getUuid());
|
||||
|
||||
try {
|
||||
vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
|
|
@ -340,79 +340,79 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath,
|
||||
secondaryStorageURL,
|
||||
hostService.getWorkerName(context, cmd, 0));
|
||||
} else {
|
||||
StorageFilerTO poolTO = cmd.getPool();
|
||||
} else {
|
||||
StorageFilerTO poolTO = cmd.getPool();
|
||||
|
||||
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolTO.getUuid());
|
||||
if (morDatastore == null) {
|
||||
morDatastore = hyperHost.mountDatastore(
|
||||
false,
|
||||
poolTO.getHost(), 0, poolTO.getPath(),
|
||||
poolTO.getUuid().replace("-", ""));
|
||||
|
||||
if (morDatastore == null) {
|
||||
throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
result = copyVolumeFromSecStorage(
|
||||
hyperHost, volumeId,
|
||||
new DatastoreMO(context, morDatastore),
|
||||
secondaryStorageURL, volumePath);
|
||||
}
|
||||
return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
ManagedObjectReference morDatastore = hyperHost.findDatastore(poolTO.getUuid());
|
||||
if (morDatastore == null) {
|
||||
morDatastore = hyperHost.mountDatastore(
|
||||
false,
|
||||
poolTO.getHost(), 0, poolTO.getPath(),
|
||||
poolTO.getUuid());
|
||||
|
||||
if (morDatastore == null) {
|
||||
throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
result = copyVolumeFromSecStorage(
|
||||
hyperHost, volumeId,
|
||||
new DatastoreMO(context, morDatastore),
|
||||
secondaryStorageURL, volumePath);
|
||||
}
|
||||
return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
String msg = "Unable to execute CopyVolumeCommand due to exception";
|
||||
s_logger.error(msg, e);
|
||||
return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) {
|
||||
|
||||
String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel();
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
|
||||
String backedUpSnapshotUuid = cmd.getSnapshotUuid();
|
||||
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
ManagedObjectReference morPrimaryDs = hyperHost.findDatastore(primaryStorageNameLabel);
|
||||
if (morPrimaryDs == null) {
|
||||
String msg = "Unable to find datastore: " + primaryStorageNameLabel;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
|
||||
details = createVolumeFromSnapshot(hyperHost, primaryDsMo,
|
||||
newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid);
|
||||
if (details == null) {
|
||||
success = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
s_logger.error("Unexpecpted exception ", e);
|
||||
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
String msg = "Unable to execute CopyVolumeCommand due to exception";
|
||||
s_logger.error(msg, e);
|
||||
return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) {
|
||||
|
||||
String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel();
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
|
||||
String backedUpSnapshotUuid = cmd.getSnapshotUuid();
|
||||
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
|
||||
ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel);
|
||||
if (morPrimaryDs == null) {
|
||||
String msg = "Unable to find datastore: " + primaryStorageNameLabel;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
|
||||
details = createVolumeFromSnapshot(hyperHost, primaryDsMo,
|
||||
newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid);
|
||||
if (details == null) {
|
||||
success = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
|
||||
s_logger.error("Unexpecpted exception ", e);
|
||||
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
|
||||
// templateName: name in secondary storage
|
||||
// templateUuid: will be used at hypervisor layer
|
||||
|
|
@ -783,7 +783,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
|
|||
String exportName = UUID.randomUUID().toString();
|
||||
|
||||
try {
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(poolId);
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolId);
|
||||
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find volumes's storage pool for copy volume operation";
|
||||
|
|
|
|||
|
|
@ -230,12 +230,13 @@ import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
|
|||
import com.vmware.vim25.VirtualMachinePowerState;
|
||||
import com.vmware.vim25.VirtualMachineRuntimeInfo;
|
||||
import com.vmware.vim25.VirtualSCSISharing;
|
||||
|
||||
public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService {
|
||||
private static final Logger s_logger = Logger.getLogger(VmwareResource.class);
|
||||
|
||||
protected String _name;
|
||||
|
||||
import com.xensource.xenapi.VLAN;
|
||||
|
||||
public class VmwareResource implements StoragePoolResource, ServerResource, VmwareHostService {
|
||||
private static final Logger s_logger = Logger.getLogger(VmwareResource.class);
|
||||
|
||||
protected String _name;
|
||||
|
||||
protected final long _ops_timeout = 900000; // 15 minutes time out to time
|
||||
protected final int _shutdown_waitMs = 300000; // wait up to 5 minutes for shutdown
|
||||
|
||||
|
|
@ -1638,7 +1639,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
if (vol.getType() != Volume.Type.ISO) {
|
||||
String poolUuid = vol.getPoolUuid();
|
||||
if(poolMors.get(poolUuid) == null) {
|
||||
ManagedObjectReference morDataStore = hyperHost.findDatastore(poolUuid);
|
||||
ManagedObjectReference morDataStore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolUuid);
|
||||
if (morDataStore == null) {
|
||||
String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid;
|
||||
s_logger.error(msg);
|
||||
|
|
@ -1646,52 +1647,60 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
poolMors.put(vol.getPoolUuid(), new Pair<ManagedObjectReference, DatastoreMO> (morDataStore, new DatastoreMO(context, morDataStore)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return poolMors;
|
||||
}
|
||||
|
||||
private String getVlanInfo(NicTO nicTo) {
|
||||
if (nicTo.getBroadcastType() == BroadcastDomainType.Native) {
|
||||
return Vlan.UNTAGGED;
|
||||
}
|
||||
|
||||
if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan) {
|
||||
if (nicTo.getBroadcastUri() != null) {
|
||||
return nicTo.getBroadcastUri().getHost();
|
||||
} else {
|
||||
s_logger.warn("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI");
|
||||
return Vlan.UNTAGGED;
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString());
|
||||
return Vlan.UNTAGGED;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return poolMors;
|
||||
}
|
||||
|
||||
private String getVlanInfo(NicTO nicTo, String defaultVlan) {
|
||||
if (nicTo.getBroadcastType() == BroadcastDomainType.Native) {
|
||||
return defaultVlan;
|
||||
}
|
||||
|
||||
if (nicTo.getBroadcastType() == BroadcastDomainType.Vlan) {
|
||||
if (nicTo.getBroadcastUri() != null) {
|
||||
return nicTo.getBroadcastUri().getHost();
|
||||
} else {
|
||||
s_logger.warn("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan);
|
||||
return defaultVlan;
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString() + ". Use vlan info from labeling: " + defaultVlan);
|
||||
return defaultVlan;
|
||||
}
|
||||
|
||||
private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo) throws Exception {
|
||||
|
||||
String switchName = getTargetSwitch(nicTo);
|
||||
Pair<String, String> switchName = getTargetSwitch(nicTo);
|
||||
String namePrefix = getNetworkNamePrefix(nicTo);
|
||||
|
||||
s_logger.info("Prepare network on vSwitch: " + switchName + " with name prefix: " + namePrefix);
|
||||
return HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo),
|
||||
s_logger.info("Prepare network on vSwitch: " + switchName.first() + " with name prefix: " + namePrefix);
|
||||
return HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
||||
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
|
||||
!namePrefix.startsWith("cloud.private"));
|
||||
}
|
||||
|
||||
private String getTargetSwitch(NicTO nicTo) throws Exception {
|
||||
if(nicTo.getName() != null && !nicTo.getName().isEmpty())
|
||||
return nicTo.getName();
|
||||
// return Pair<switch name, vlan tagging>
|
||||
private Pair<String, String> getTargetSwitch(NicTO nicTo) throws Exception {
|
||||
if(nicTo.getName() != null && !nicTo.getName().isEmpty()) {
|
||||
String[] tokens = nicTo.getName().split(",");
|
||||
|
||||
if(tokens.length == 2) {
|
||||
return new Pair<String, String>(tokens[0], tokens[1]);
|
||||
} else {
|
||||
return new Pair<String, String>(nicTo.getName(), Vlan.UNTAGGED);
|
||||
}
|
||||
}
|
||||
|
||||
if (nicTo.getType() == Networks.TrafficType.Guest) {
|
||||
return this._guestNetworkVSwitchName;
|
||||
return new Pair<String, String>(this._guestNetworkVSwitchName, Vlan.UNTAGGED);
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Control || nicTo.getType() == Networks.TrafficType.Management) {
|
||||
return this._privateNetworkVSwitchName;
|
||||
return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED);
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Public) {
|
||||
return this._publicNetworkVSwitchName;
|
||||
return new Pair<String, String>(this._publicNetworkVSwitchName, Vlan.UNTAGGED);
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Storage) {
|
||||
return this._privateNetworkVSwitchName;
|
||||
return new Pair<String, String>(this._privateNetworkVSwitchName, Vlan.UNTAGGED);
|
||||
} else if (nicTo.getType() == Networks.TrafficType.Vpn) {
|
||||
throw new Exception("Unsupported traffic type: " + nicTo.getType().toString());
|
||||
} else {
|
||||
|
|
@ -2294,127 +2303,128 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) {
|
||||
throw new Exception("Unsupported storage pool type " + pool.getType());
|
||||
}
|
||||
|
||||
ManagedObjectReference morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid());
|
||||
|
||||
assert (morDatastore != null);
|
||||
DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
|
||||
long capacity = summary.getCapacity();
|
||||
long available = summary.getFreeSpace();
|
||||
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
|
||||
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(DeleteStoragePoolCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource DeleteStoragePoolCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
StorageFilerTO pool = cmd.getPool();
|
||||
}
|
||||
|
||||
ManagedObjectReference morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(),
|
||||
pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
|
||||
|
||||
assert (morDatastore != null);
|
||||
DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
|
||||
long capacity = summary.getCapacity();
|
||||
long available = summary.getFreeSpace();
|
||||
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
|
||||
ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(DeleteStoragePoolCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource DeleteStoragePoolCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
StorageFilerTO pool = cmd.getPool();
|
||||
try {
|
||||
// We will leave datastore cleanup management to vCenter. Since for cluster VMFS datastore, it will always
|
||||
// be mounted by vCenter.
|
||||
|
||||
// VmwareHypervisorHost hyperHost = this.getHyperHost(getServiceContext());
|
||||
// hyperHost.unmountDatastore(pool.getUuid());
|
||||
Answer answer = new Answer(cmd, true, "success");
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "DeleteStoragePoolCommand (pool: " + pool.getHost() + ", path: " + pool.getPath() + ") failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(AttachVolumeCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource AttachVolumeCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
/*
|
||||
* AttachVolumeCommand { "attach":true,"vmName":"i-2-1-KY","pooltype":"NetworkFilesystem",
|
||||
* "volumeFolder":"/export/home/kelven/vmware-test/primary", "volumePath":"uuid",
|
||||
* "volumeName":"volume name","deviceId":1 }
|
||||
*/
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getPoolUuid());
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find the mounted datastore to execute AttachVolumeCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
|
||||
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), cmd.getVolumePath());
|
||||
|
||||
AttachVolumeAnswer answer = new AttachVolumeAnswer(cmd, cmd.getDeviceId());
|
||||
if (cmd.getAttach()) {
|
||||
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
|
||||
} else {
|
||||
vmMo.removeAllSnapshots();
|
||||
vmMo.detachDisk(datastoreVolumePath, false);
|
||||
}
|
||||
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new AttachVolumeAnswer(cmd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(AttachIsoCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource AttachIsoCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
String storeUrl = cmd.getStoreUrl();
|
||||
if (storeUrl == null) {
|
||||
if (!cmd.getIsoPath().equalsIgnoreCase("vmware-tools.iso")) {
|
||||
String msg = "ISO store root url is not found in AttachIsoCommand";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
} else {
|
||||
if (cmd.isAttach()) {
|
||||
vmMo.mountToolsInstaller();
|
||||
|
||||
// VmwareHypervisorHost hyperHost = this.getHyperHost(getServiceContext());
|
||||
// hyperHost.unmountDatastore(pool.getUuid());
|
||||
Answer answer = new Answer(cmd, true, "success");
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "DeleteStoragePoolCommand (pool: " + pool.getHost() + ", path: " + pool.getPath() + ") failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(AttachVolumeCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource AttachVolumeCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
/*
|
||||
* AttachVolumeCommand { "attach":true,"vmName":"i-2-1-KY","pooltype":"NetworkFilesystem",
|
||||
* "volumeFolder":"/export/home/kelven/vmware-test/primary", "volumePath":"uuid",
|
||||
* "volumeName":"volume name","deviceId":1 }
|
||||
*/
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid());
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find the mounted datastore to execute AttachVolumeCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
|
||||
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), cmd.getVolumePath());
|
||||
|
||||
AttachVolumeAnswer answer = new AttachVolumeAnswer(cmd, cmd.getDeviceId());
|
||||
if (cmd.getAttach()) {
|
||||
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
|
||||
} else {
|
||||
vmMo.removeAllSnapshots();
|
||||
vmMo.detachDisk(datastoreVolumePath, false);
|
||||
}
|
||||
|
||||
return answer;
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new AttachVolumeAnswer(cmd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(AttachIsoCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource AttachIsoCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
|
||||
if (vmMo == null) {
|
||||
String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
String storeUrl = cmd.getStoreUrl();
|
||||
if (storeUrl == null) {
|
||||
if (!cmd.getIsoPath().equalsIgnoreCase("vmware-tools.iso")) {
|
||||
String msg = "ISO store root url is not found in AttachIsoCommand";
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
} else {
|
||||
if (cmd.isAttach()) {
|
||||
vmMo.mountToolsInstaller();
|
||||
} else {
|
||||
vmMo.unmountToolsInstaller();
|
||||
}
|
||||
|
|
@ -2461,224 +2471,223 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
String msg = "AttachIsoCommand(detach) failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.warn(msg, e);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception {
|
||||
String storeName = getSecondaryDatastoreUUID(storeUrl);
|
||||
URI uri = new URI(storeUrl);
|
||||
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName);
|
||||
|
||||
if (morDatastore == null) {
|
||||
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
|
||||
}
|
||||
|
||||
return morDatastore;
|
||||
}
|
||||
|
||||
private static String getSecondaryDatastoreUUID(String storeUrl) {
|
||||
return UUID.nameUUIDFromBytes(storeUrl.getBytes()).toString();
|
||||
}
|
||||
|
||||
protected Answer execute(ValidateSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ValidateSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
// the command is no longer available
|
||||
String expectedSnapshotBackupUuid = null;
|
||||
String actualSnapshotBackupUuid = null;
|
||||
String actualSnapshotUuid = null;
|
||||
return new ValidateSnapshotAnswer(cmd, false, "ValidateSnapshotCommand is not supported for vmware yet", expectedSnapshotBackupUuid, actualSnapshotBackupUuid, actualSnapshotUuid);
|
||||
}
|
||||
|
||||
protected Answer execute(ManageSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ManageSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
long snapshotId = cmd.getSnapshotId();
|
||||
|
||||
/*
|
||||
* "ManageSnapshotCommand",
|
||||
* "{\"_commandSwitch\":\"-c\",\"_volumePath\":\"i-2-3-KY-ROOT\",\"_snapshotName\":\"i-2-3-KY_i-2-3-KY-ROOT_20101102203827\",\"_snapshotId\":1,\"_vmName\":\"i-2-3-KY\"}"
|
||||
*/
|
||||
boolean success = false;
|
||||
String cmdSwitch = cmd.getCommandSwitch();
|
||||
String snapshotOp = "Unsupported snapshot command." + cmdSwitch;
|
||||
if (cmdSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
|
||||
snapshotOp = "create";
|
||||
} else if (cmdSwitch.equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) {
|
||||
snapshotOp = "destroy";
|
||||
}
|
||||
|
||||
String details = "ManageSnapshotCommand operation: " + snapshotOp + " Failed for snapshotId: " + snapshotId;
|
||||
String snapshotUUID = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception {
|
||||
String storeName = getSecondaryDatastoreUUID(storeUrl);
|
||||
URI uri = new URI(storeUrl);
|
||||
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""));
|
||||
|
||||
if (morDatastore == null)
|
||||
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
|
||||
|
||||
return morDatastore;
|
||||
}
|
||||
|
||||
private static String getSecondaryDatastoreUUID(String storeUrl) {
|
||||
return UUID.nameUUIDFromBytes(storeUrl.getBytes()).toString();
|
||||
}
|
||||
|
||||
protected Answer execute(ValidateSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ValidateSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
// the command is no longer available
|
||||
String expectedSnapshotBackupUuid = null;
|
||||
String actualSnapshotBackupUuid = null;
|
||||
String actualSnapshotUuid = null;
|
||||
return new ValidateSnapshotAnswer(cmd, false, "ValidateSnapshotCommand is not supported for vmware yet", expectedSnapshotBackupUuid, actualSnapshotBackupUuid, actualSnapshotUuid);
|
||||
}
|
||||
|
||||
protected Answer execute(ManageSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ManageSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
long snapshotId = cmd.getSnapshotId();
|
||||
|
||||
/*
|
||||
* "ManageSnapshotCommand",
|
||||
* "{\"_commandSwitch\":\"-c\",\"_volumePath\":\"i-2-3-KY-ROOT\",\"_snapshotName\":\"i-2-3-KY_i-2-3-KY-ROOT_20101102203827\",\"_snapshotId\":1,\"_vmName\":\"i-2-3-KY\"}"
|
||||
*/
|
||||
boolean success = false;
|
||||
String cmdSwitch = cmd.getCommandSwitch();
|
||||
String snapshotOp = "Unsupported snapshot command." + cmdSwitch;
|
||||
if (cmdSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) {
|
||||
snapshotOp = "create";
|
||||
} else if (cmdSwitch.equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) {
|
||||
snapshotOp = "destroy";
|
||||
}
|
||||
|
||||
String details = "ManageSnapshotCommand operation: " + snapshotOp + " Failed for snapshotId: " + snapshotId;
|
||||
String snapshotUUID = null;
|
||||
|
||||
// snapshot operation (create or destroy) is handled inside BackupSnapshotCommand(), we just fake
|
||||
// a success return here
|
||||
snapshotUUID = UUID.randomUUID().toString();
|
||||
success = true;
|
||||
details = null;
|
||||
|
||||
return new ManageSnapshotAnswer(cmd, snapshotId, snapshotUUID, success, details);
|
||||
}
|
||||
|
||||
protected Answer execute(BackupSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "BackupSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new BackupSnapshotAnswer(cmd, false, details, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Answer execute(CreateVolumeFromSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString();
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
details = "CreateVolumeFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
|
||||
protected Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "CreatePrivateTemplateFromVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(final UpgradeSnapshotCommand cmd) {
|
||||
return new Answer(cmd, true, "success");
|
||||
}
|
||||
|
||||
protected Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreatePrivateTemplateFromSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "CreatePrivateTemplateFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(GetStorageStatsCommand cmd) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Executing resource GetStorageStatsCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getStorageId());
|
||||
|
||||
if (morDs != null) {
|
||||
DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
|
||||
DatastoreSummary summary = datastoreMo.getSummary();
|
||||
assert (summary != null);
|
||||
|
||||
long capacity = summary.getCapacity();
|
||||
long free = summary.getFreeSpace();
|
||||
long used = capacity - free;
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Datastore summary info, storageId: " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ", capacity: " + capacity
|
||||
+ ", free: " + free + ", used: " + used);
|
||||
}
|
||||
|
||||
if (summary.getCapacity() <= 0) {
|
||||
s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
|
||||
}
|
||||
|
||||
return new GetStorageStatsAnswer(cmd, capacity, used);
|
||||
} else {
|
||||
String msg = "Could not find datastore for GetStorageStatsCommand storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype();
|
||||
|
||||
s_logger.error(msg);
|
||||
return new GetStorageStatsAnswer(cmd, msg);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "Unable to execute GetStorageStatsCommand(storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ") due to "
|
||||
+ VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new GetStorageStatsAnswer(cmd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(GetVncPortCommand cmd) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Executing resource GetVncPortCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
|
||||
return new ManageSnapshotAnswer(cmd, snapshotId, snapshotUUID, success, details);
|
||||
}
|
||||
|
||||
protected Answer execute(BackupSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "BackupSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new BackupSnapshotAnswer(cmd, false, details, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Answer execute(CreateVolumeFromSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
String details = null;
|
||||
boolean success = false;
|
||||
String newVolumeName = UUID.randomUUID().toString();
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
details = "CreateVolumeFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
}
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
|
||||
}
|
||||
|
||||
protected Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "CreatePrivateTemplateFromVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(final UpgradeSnapshotCommand cmd) {
|
||||
return new Answer(cmd, true, "success");
|
||||
}
|
||||
|
||||
protected Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource CreatePrivateTemplateFromSnapshotCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return mgr.getStorageManager().execute(this, cmd);
|
||||
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String details = "CreatePrivateTemplateFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(details, e);
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(GetStorageStatsCommand cmd) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Executing resource GetStorageStatsCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId());
|
||||
|
||||
if (morDs != null) {
|
||||
DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
|
||||
DatastoreSummary summary = datastoreMo.getSummary();
|
||||
assert (summary != null);
|
||||
|
||||
long capacity = summary.getCapacity();
|
||||
long free = summary.getFreeSpace();
|
||||
long used = capacity - free;
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Datastore summary info, storageId: " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ", capacity: " + capacity
|
||||
+ ", free: " + free + ", used: " + used);
|
||||
}
|
||||
|
||||
if (summary.getCapacity() <= 0) {
|
||||
s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
|
||||
}
|
||||
|
||||
return new GetStorageStatsAnswer(cmd, capacity, used);
|
||||
} else {
|
||||
String msg = "Could not find datastore for GetStorageStatsCommand storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype();
|
||||
|
||||
s_logger.error(msg);
|
||||
return new GetStorageStatsAnswer(cmd, msg);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "Unable to execute GetStorageStatsCommand(storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ") due to "
|
||||
+ VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new GetStorageStatsAnswer(cmd, msg);
|
||||
}
|
||||
}
|
||||
|
||||
protected Answer execute(GetVncPortCommand cmd) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Executing resource GetVncPortCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
assert(hyperHost instanceof HostMO);
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
|
@ -2747,74 +2756,74 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
protected Answer execute(ModifySshKeysCommand cmd) {
|
||||
//do not log the command contents for this command. do NOT log the ssh keys
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ModifySshKeysCommand.");
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(PoolEjectCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource PoolEjectCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
return new Answer(cmd, false, "PoolEjectCommand is not available for vmware");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return (PrimaryStorageDownloadAnswer) mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new PrimaryStorageDownloadAnswer(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer execute(DestroyCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource DestroyCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
/*
|
||||
* DestroyCommand content example
|
||||
*
|
||||
* {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
|
||||
* "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } }
|
||||
*
|
||||
* {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem",
|
||||
* "poolId":0,"deviceId":0 } }
|
||||
*/
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
VolumeTO vol = cmd.getVolume();
|
||||
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(vol.getPoolUuid());
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find datastore based on volume mount point " + cmd.getVolume().getMountPoint();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
//do not log the command contents for this command. do NOT log the ssh keys
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ModifySshKeysCommand.");
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
protected Answer execute(PoolEjectCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource PoolEjectCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
return new Answer(cmd, false, "PoolEjectCommand is not available for vmware");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
return (PrimaryStorageDownloadAnswer) mgr.getStorageManager().execute(this, cmd);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
|
||||
invalidateServiceContext();
|
||||
}
|
||||
|
||||
String msg = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e);
|
||||
s_logger.error(msg, e);
|
||||
return new PrimaryStorageDownloadAnswer(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer execute(DestroyCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource DestroyCommand: " + _gson.toJson(cmd));
|
||||
}
|
||||
|
||||
/*
|
||||
* DestroyCommand content example
|
||||
*
|
||||
* {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType":
|
||||
* "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } }
|
||||
*
|
||||
* {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary",
|
||||
* "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem",
|
||||
* "poolId":0,"deviceId":0 } }
|
||||
*/
|
||||
|
||||
try {
|
||||
VmwareContext context = getServiceContext();
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
VolumeTO vol = cmd.getVolume();
|
||||
|
||||
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, vol.getPoolUuid());
|
||||
if (morDs == null) {
|
||||
String msg = "Unable to find datastore based on volume mount point " + cmd.getVolume().getMountPoint();
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(context, morDs);
|
||||
|
||||
ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
|
||||
|
|
@ -2971,18 +2980,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
VmwareHypervisorHost hyperHost = getHyperHost(context);
|
||||
DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
|
||||
|
||||
VmwareManager vmwareMgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||
|
||||
ManagedObjectReference morDatastore = hyperHost.findDatastore(pool.getUuid());
|
||||
if (morDatastore == null) {
|
||||
throw new Exception("Unable to find datastore in vSphere");
|
||||
}
|
||||
DatastoreMO dsMo = new DatastoreMO(context, morDatastore);
|
||||
|
||||
if (cmd.getDiskCharacteristics().getType() == Volume.Type.ROOT) {
|
||||
if (cmd.getTemplateUrl() == null) {
|
||||
// create a root volume for blank VM
|
||||
String dummyVmName = getWorkerName(context, cmd, 0);
|
||||
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
|
||||
if (morDatastore == null)
|
||||
throw new Exception("Unable to find datastore in vSphere");
|
||||
|
||||
DatastoreMO dsMo = new DatastoreMO(context, morDatastore);
|
||||
|
||||
if (cmd.getDiskCharacteristics().getType() == Volume.Type.ROOT) {
|
||||
if (cmd.getTemplateUrl() == null) {
|
||||
// create a root volume for blank VM
|
||||
String dummyVmName = getWorkerName(context, cmd, 0);
|
||||
VirtualMachineMO vmMo = null;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ public class DownloadManagerImpl implements DownloadManager {
|
|||
}
|
||||
byte[] md5sum = digest.digest();
|
||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
checksum = bigInt.toString(16);
|
||||
checksum = String.format("%032x",bigInt.toString(16));
|
||||
return checksum;
|
||||
}catch(IOException e) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -513,7 +513,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
Long vlanId = null;
|
||||
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId);
|
||||
if (maps != null && !maps.isEmpty()) {
|
||||
vlanId = maps.get(0).getVlanDbId();
|
||||
//check if the ips from this vlan are associated with this network
|
||||
List<IPAddressVO> ips = _ipAddressDao.listByVlanId(maps.get(0).getVlanDbId());
|
||||
if (ips != null && !ips.isEmpty() && ips.get(0).getAssociatedWithNetworkId() == network.getId()) {
|
||||
vlanId = maps.get(0).getVlanDbId();
|
||||
}
|
||||
}
|
||||
|
||||
ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, network.getId(), true, false, null, false);
|
||||
|
|
|
|||
|
|
@ -311,10 +311,20 @@ body.login {
|
|||
background: transparent url(../images/sprites.png) -563px -747px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
margin: 7px 0 0;
|
||||
width: 68px;
|
||||
margin: 7px 238px 0 -1px;
|
||||
text-align: center;
|
||||
width: 69px;
|
||||
height: 25px;
|
||||
display: block;
|
||||
color: #FFFFFF;
|
||||
font-weight: bold;
|
||||
float: left;
|
||||
text-indent: -1px;
|
||||
/*+text-shadow:0px 1px 2px #000000;*/
|
||||
-moz-text-shadow: 0px 1px 2px #000000;
|
||||
-webkit-text-shadow: 0px 1px 2px #000000;
|
||||
-o-text-shadow: 0px 1px 2px #000000;
|
||||
text-shadow: 0px 1px 2px #000000;
|
||||
}
|
||||
|
||||
.login .fields input[type=submit]:hover {
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 174 KiB |
|
|
@ -52,7 +52,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Submit (login) -->
|
||||
<input type="submit" value="" />
|
||||
<input type="submit" value="<fmt:message key="label.login"/>" />
|
||||
|
||||
<!-- Select language -->
|
||||
<div class="select-language">
|
||||
|
|
|
|||
|
|
@ -43,42 +43,50 @@ import com.vmware.vim25.VirtualMachineConfigSpec;
|
|||
import com.vmware.vim25.VirtualMachineFileInfo;
|
||||
import com.vmware.vim25.VirtualMachineVideoCard;
|
||||
import com.vmware.vim25.VirtualSCSISharing;
|
||||
|
||||
public class HypervisorHostHelper {
|
||||
private static final Logger s_logger = Logger.getLogger(HypervisorHostHelper.class);
|
||||
private static final int DEFAULT_LOCK_TIMEOUT_SECONDS = 600;
|
||||
|
||||
// make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED constant here
|
||||
private static final String UNTAGGED_VLAN_NAME = "untagged";
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context,
|
||||
ObjectContent[] ocs, String name) {
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty prop = oc.getPropSet(0);
|
||||
assert(prop != null);
|
||||
if(prop.getVal().toString().equals(name))
|
||||
return new VirtualMachineMO(context, oc.getObj());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
public class HypervisorHostHelper {
|
||||
private static final Logger s_logger = Logger.getLogger(HypervisorHostHelper.class);
|
||||
private static final int DEFAULT_LOCK_TIMEOUT_SECONDS = 600;
|
||||
|
||||
// make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED constant here
|
||||
private static final String UNTAGGED_VLAN_NAME = "untagged";
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context,
|
||||
ObjectContent[] ocs, String name) {
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty prop = oc.getPropSet(0);
|
||||
assert(prop != null);
|
||||
if(prop.getVal().toString().equals(name))
|
||||
return new VirtualMachineMO(context, oc.getObj());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DatastoreMO getHyperHostDatastoreMO(VmwareHypervisorHost hyperHost, String datastoreName) throws Exception {
|
||||
ObjectContent[] ocs = hyperHost.getDatastorePropertiesOnHyperHost(new String[] { "name"} );
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getVal().toString().equals(datastoreName))
|
||||
return new DatastoreMO(hyperHost.getContext(), oc.getObj());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
public static ManagedObjectReference findDatastoreWithBackwardsCompatibility(VmwareHypervisorHost hyperHost, String uuidName) throws Exception {
|
||||
ManagedObjectReference morDs = hyperHost.findDatastore(uuidName.replace("-", ""));
|
||||
if(morDs == null)
|
||||
morDs = hyperHost.findDatastore(uuidName);
|
||||
|
||||
return morDs;
|
||||
}
|
||||
|
||||
public static DatastoreMO getHyperHostDatastoreMO(VmwareHypervisorHost hyperHost, String datastoreName) throws Exception {
|
||||
ObjectContent[] ocs = hyperHost.getDatastorePropertiesOnHyperHost(new String[] { "name"} );
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
DynamicProperty[] objProps = oc.getPropSet();
|
||||
if(objProps != null) {
|
||||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getVal().toString().equals(datastoreName))
|
||||
return new DatastoreMO(hyperHost.getContext(), oc.getObj());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getPublicNetworkNamePrefix(String vlanId) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue