Skip to content

Commit da30064

Browse files
author
Fabrício Duarte
committed
Merge branch 'vmware-nfs-with-different-versions' into '4.20.0.0-scclouds'
Montar _storage_ NFS no VMware com versão 4.1 ou 3 Closes #2782 See merge request scclouds/scclouds!1300
2 parents 0a4de4e + afc4297 commit da30064

11 files changed

Lines changed: 74 additions & 51 deletions

File tree

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public interface VmwareManager {
8181

8282
Pair<String, Long> getSecondaryStorageStoreUrlAndId(long dcId);
8383

84+
String getSecondaryStorageNfsVersion(Long storageId);
85+
8486
List<Pair<String, Long>> getSecondaryStorageStoresUrlAndIdList(long dcId);
8587

8688
File getSystemVMKeyFile();

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import javax.naming.ConfigurationException;
4444
import javax.persistence.EntityExistsException;
4545

46+
import com.cloud.agent.api.to.NfsTO;
4647
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
4748
import com.cloud.hypervisor.vmware.util.VmwareClient;
49+
import com.cloud.storage.DataStoreRole;
4850
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
4951
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
5052
import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcVmsCmd;
@@ -589,6 +591,15 @@ public Pair<String, Long> getSecondaryStorageStoreUrlAndId(long dcId) {
589591
return new Pair<>(secUrl, secId);
590592
}
591593

594+
@Override
595+
public String getSecondaryStorageNfsVersion(Long storageId) {
596+
DataStore dataStore = _dataStoreMgr.getDataStore(storageId, DataStoreRole.Image);
597+
if (dataStore != null && dataStore.getTO() instanceof NfsTO) {
598+
return ((NfsTO) dataStore.getTO()).getNfsVersion();
599+
}
600+
return null;
601+
}
602+
592603
@Override
593604
public List<Pair<String, Long>> getSecondaryStorageStoresUrlAndIdList(long dcId) {
594605
List<Pair<String, Long>> urlIdList = new ArrayList<>();

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
470470

471471
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolTO.getUuid());
472472
if (morDatastore == null) {
473-
morDatastore = hyperHost.mountDatastore(false, poolTO.getHost(), 0, poolTO.getPath(), poolTO.getUuid().replace("-", ""), true);
473+
morDatastore = hyperHost.mountDatastore(false, poolTO.getHost(), 0, poolTO.getPath(), poolTO.getUuid().replace("-", ""), true, cmd.getNfsVersion());
474474

475475
if (morDatastore == null) {
476476
throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath());

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,18 +2400,7 @@ protected StartAnswer execute(StartCommand cmd) {
24002400
if (vmSpec.getType() != VirtualMachine.Type.User) {
24012401
// attach ISO (for patching of system VM)
24022402
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
2403-
String secStoreUrl = secStoreUrlAndId.first();
2404-
if (secStoreUrl == null) {
2405-
String msg = String.format("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used",
2406-
_dcId, Math.round(CapacityManager.SecondaryStorageCapacityThreshold.value() * 100));
2407-
throw new Exception(msg);
2408-
}
2409-
2410-
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl);
2411-
if (morSecDs == null) {
2412-
String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc "+ _dcId;
2413-
throw new Exception(msg);
2414-
}
2403+
ManagedObjectReference morSecDs = mountSecondaryStorage(mgr, secStoreUrlAndId);
24152404
DatastoreMO secDsMo = new DatastoreMO(hyperHost.getContext(), morSecDs);
24162405

24172406
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
@@ -2880,7 +2869,7 @@ private Integer configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vm
28802869
}
28812870
NfsTO nfsImageStore = (NfsTO) imageStore;
28822871
String isoPath = nfsImageStore.getUrl() + File.separator + iso.getPath();
2883-
Pair<String, ManagedObjectReference> isoDatastoreInfo = getIsoDatastoreInfo(hyperHost, isoPath);
2872+
Pair<String, ManagedObjectReference> isoDatastoreInfo = getIsoDatastoreInfo(hyperHost, isoPath, ((NfsTO) imageStore).getNfsVersion());
28842873
assert (isoDatastoreInfo != null);
28852874
assert (isoDatastoreInfo.second() != null);
28862875

@@ -4232,7 +4221,7 @@ private VirtualMachineMO takeVmFromOtherHyperHost(VmwareHypervisorHost hyperHost
42324221

42334222
// isoUrl sample content :
42344223
// nfs://192.168.10.231/export/home/kelven/vmware-test/secondary/template/tmpl/2/200//200-2-80f7ee58-6eff-3a2d-bcb0-59663edf6d26.iso
4235-
private Pair<String, ManagedObjectReference> getIsoDatastoreInfo(VmwareHypervisorHost hyperHost, String isoUrl) throws Exception {
4224+
private Pair<String, ManagedObjectReference> getIsoDatastoreInfo(VmwareHypervisorHost hyperHost, String isoUrl, String nfsVersion) throws Exception {
42364225

42374226
assert (isoUrl != null);
42384227
int isoFileNameStartPos = isoUrl.lastIndexOf("/");
@@ -4251,7 +4240,7 @@ private Pair<String, ManagedObjectReference> getIsoDatastoreInfo(VmwareHyperviso
42514240
String storeUrl = isoUrl.substring(0, templateRootPos - 1);
42524241
String isoPath = isoUrl.substring(templateRootPos, isoFileNameStartPos);
42534242

4254-
ManagedObjectReference morDs = prepareSecondaryDatastoreOnHost(storeUrl);
4243+
ManagedObjectReference morDs = prepareSecondaryDatastoreOnHost(storeUrl, nfsVersion);
42554244
DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs);
42564245

42574246
return new Pair<String, ManagedObjectReference>(String.format("[%s] %s%s", dsMo.getName(), isoPath, isoFileName), morDs);
@@ -4749,25 +4738,31 @@ protected Answer execute(PrepareForMigrationCommand cmd) {
47494738

47504739
List<Pair<String, Long>> secStoreUrlAndIdList = mgr.getSecondaryStorageStoresUrlAndIdList(Long.parseLong(_dcId));
47514740
for (Pair<String, Long> secStoreUrlAndId : secStoreUrlAndIdList) {
4752-
String secStoreUrl = secStoreUrlAndId.first();
4753-
if (secStoreUrl == null) {
4754-
String msg = String.format("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used",
4755-
_dcId, Math.round(CapacityManager.SecondaryStorageCapacityThreshold.value() * 100));
4756-
throw new Exception(msg);
4757-
}
4758-
4759-
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl);
4760-
if (morSecDs == null) {
4761-
String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc "+ _dcId;
4762-
throw new Exception(msg);
4763-
}
4741+
mountSecondaryStorage(mgr, secStoreUrlAndId);
47644742
}
47654743
return new PrepareForMigrationAnswer(cmd);
47664744
} catch (Throwable e) {
47674745
return new PrepareForMigrationAnswer(cmd, createLogMessageException(e, cmd));
47684746
}
47694747
}
47704748

4749+
private ManagedObjectReference mountSecondaryStorage(VmwareManager mgr, Pair<String, Long> secStoreUrlAndId) throws Exception {
4750+
String secStoreUrl = secStoreUrlAndId.first();
4751+
if (secStoreUrl == null) {
4752+
String msg = String.format("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used",
4753+
_dcId, Math.round(CapacityManager.SecondaryStorageCapacityThreshold.value() * 100));
4754+
throw new Exception(msg);
4755+
}
4756+
String secondaryStorageNfsVersion = mgr.getSecondaryStorageNfsVersion(secStoreUrlAndId.second());
4757+
4758+
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost(secStoreUrl, secondaryStorageNfsVersion);
4759+
if (morSecDs == null) {
4760+
String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc "+ _dcId;
4761+
throw new Exception(msg);
4762+
}
4763+
return morSecDs;
4764+
}
4765+
47714766
protected Answer execute(MigrateVmToPoolCommand cmd) {
47724767
final String vmName = cmd.getVmName();
47734768

@@ -5355,6 +5350,10 @@ protected Answer execute(ModifyTargetsCommand cmd) {
53555350

53565351
protected Answer execute(ModifyStoragePoolCommand cmd) {
53575352
try {
5353+
Map<String, String> details = cmd.getDetails();
5354+
if (details.containsKey(ApiConstants.NFS_MOUNT_OPTIONS) && details.get(ApiConstants.NFS_MOUNT_OPTIONS).split("nfsvers=").length > 1) {
5355+
storageNfsVersion = details.get(ApiConstants.NFS_MOUNT_OPTIONS).split("nfsvers=")[1].split(",")[0];
5356+
}
53585357
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
53595358
StorageFilerTO pool = cmd.getPool();
53605359

@@ -5365,7 +5364,7 @@ protected Answer execute(ModifyStoragePoolCommand cmd) {
53655364
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
53665365

53675366
if (morDatastore == null) {
5368-
morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true);
5367+
morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true, storageNfsVersion);
53695368
}
53705369

53715370
assert (morDatastore != null);
@@ -5445,7 +5444,7 @@ protected Answer execute(GetStoragePoolCapabilitiesCommand cmd) {
54455444
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
54465445

54475446
if (morDatastore == null) {
5448-
morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true);
5447+
morDatastore = hyperHost.mountDatastore((pool.getType() == StoragePoolType.VMFS || pool.getType() == StoragePoolType.PreSetup || pool.getType() == StoragePoolType.DatastoreCluster), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""), true, null);
54495448
}
54505449

54515450
assert (morDatastore != null);
@@ -5565,7 +5564,10 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) {
55655564
}
55665565
}
55675566

5568-
ManagedObjectReference morSecondaryDs = prepareSecondaryDatastoreOnHost(storeUrl);
5567+
VmwareManager mgr = hyperHost.getContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
5568+
Pair<String, Long> secStoreUrlAndId = mgr.getSecondaryStorageStoreUrlAndId(Long.parseLong(_dcId));
5569+
ManagedObjectReference morSecondaryDs = mountSecondaryStorage(mgr, secStoreUrlAndId);
5570+
55695571
String isoPath = cmd.getIsoPath();
55705572
if (!isoPath.startsWith(storeUrl)) {
55715573
assert (false);
@@ -5605,24 +5607,24 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) {
56055607
}
56065608
}
56075609

5608-
public synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception {
5610+
public synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl, String nfsVersion) throws Exception {
56095611
String storeName = getSecondaryDatastoreUUID(storeUrl);
56105612
URI uri = new URI(storeUrl);
56115613

56125614
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
5613-
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false);
5615+
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false, nfsVersion);
56145616

56155617
if (morDatastore == null)
56165618
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
56175619

56185620
return morDatastore;
56195621
}
56205622

5621-
public synchronized ManagedObjectReference prepareSecondaryDatastoreOnSpecificHost(String storeUrl, VmwareHypervisorHost hyperHost) throws Exception {
5623+
public synchronized ManagedObjectReference prepareSecondaryDatastoreOnSpecificHost(String storeUrl, VmwareHypervisorHost hyperHost, String nfsVersion) throws Exception {
56225624
String storeName = getSecondaryDatastoreUUID(storeUrl);
56235625
URI uri = new URI(storeUrl);
56245626

5625-
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false);
5627+
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false, nfsVersion);
56265628

56275629
if (morDatastore == null)
56285630
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
@@ -7527,7 +7529,7 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
75277529
_dcId, Math.round(CapacityManager.SecondaryStorageCapacityThreshold.value() * 100));
75287530
throw new Exception(msg);
75297531
}
7530-
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost(secStoreUrl, targetHyperHost);
7532+
ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost(secStoreUrl, targetHyperHost, mgr.getSecondaryStorageNfsVersion(secStoreUrlAndId.second()));
75317533
if (morSecDs == null) {
75327534
throw new Exception(String.format("Failed to prepare secondary storage on host, NFS secondary or cache store url: %s in dc %s", secStoreUrl, _dcId));
75337535
}
@@ -7637,7 +7639,7 @@ private String getMountedDatastoreName(VmwareHypervisorHost sourceHyperHost, Str
76377639
// If datastore is NFS and target datastore is not already mounted on source host then mount the datastore.
76387640
if (filerTo.getType().equals(StoragePoolType.NetworkFilesystem)) {
76397641
if (morVolumeDatastoreAtSource == null) {
7640-
morVolumeDatastoreAtSource = sourceHyperHost.mountDatastore(false, volumeDatastoreHost, volumeDatastorePort, volumeDatastorePath, volumeDatastoreName, false);
7642+
morVolumeDatastoreAtSource = sourceHyperHost.mountDatastore(false, volumeDatastoreHost, volumeDatastorePort, volumeDatastorePath, volumeDatastoreName, false, storageNfsVersion);
76417643
if (morVolumeDatastoreAtSource == null) {
76427644
throw new Exception("Unable to mount NFS datastore " + volumeDatastoreHost + ":/" + volumeDatastorePath + " on host: " + sourceHyperHost.getHyperHostName());
76437645
}

plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
10461046
if (morDatastore == null) {
10471047
URI uri = new URI(destStore.getUrl());
10481048

1049-
morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), destStore.getUuid().replace("-", ""), true);
1049+
morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), destStore.getUuid().replace("-", ""), true, _nfsVersion);
10501050

10511051
if (morDatastore == null) {
10521052
throw new Exception("Unable to mount storage pool on host. storeUrl: " + uri.getHost() + ":/" + uri.getPath());
@@ -2286,12 +2286,12 @@ private String getSecondaryDatastoreUUID(String storeUrl) {
22862286
return uuid;
22872287
}
22882288

2289-
private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception {
2289+
private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl, String nfsVersion) throws Exception {
22902290
String storeName = getSecondaryDatastoreUUID(storeUrl);
22912291
URI uri = new URI(storeUrl);
22922292

22932293
VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null);
2294-
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false);
2294+
ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", ""), false, nfsVersion);
22952295

22962296
if (morDatastore == null) {
22972297
throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl);
@@ -2338,7 +2338,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f
23382338
}
23392339
}
23402340

2341-
ManagedObjectReference morSecondaryDs = prepareSecondaryDatastoreOnHost(storeUrl);
2341+
ManagedObjectReference morSecondaryDs = prepareSecondaryDatastoreOnHost(storeUrl, _nfsVersion);
23422342
String isoPath = nfsImageStore.getUrl() + File.separator + iso.getPath();
23432343
if (!isoPath.startsWith(storeUrl)) {
23442344
assert (false);
@@ -2640,7 +2640,7 @@ private ManagedObjectReference prepareManagedDatastore(VmwareContext context, Vm
26402640
HostMO host = new HostMO(context, lstHosts.get(0).first());
26412641
HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
26422642

2643-
return hostDatastoreSystem.createNfsDatastore(storageHost, storagePort, iScsiName, diskUuid);
2643+
return hostDatastoreSystem.createNfsDatastore(storageHost, storagePort, iScsiName, diskUuid, _nfsVersion);
26442644
} else {
26452645
return getVmfsDatastore(context, hyperHost, VmwareResource.getDatastoreName(iScsiName), storageHost, storagePort,
26462646
trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ protected void checkNFSMountOptionsForCreate(Map<String, String> details, Hyperv
889889
if (!details.containsKey(ApiConstants.NFS_MOUNT_OPTIONS)) {
890890
return;
891891
}
892-
if (!hypervisorType.equals(HypervisorType.KVM) && !hypervisorType.equals(HypervisorType.Simulator)) {
892+
if (!hypervisorType.equals(HypervisorType.KVM) && !hypervisorType.equals(HypervisorType.VMware) && !hypervisorType.equals(HypervisorType.Simulator)) {
893893
throw new InvalidParameterValueException("NFS options can not be set for the hypervisor type " + hypervisorType);
894894
}
895895
if (!"nfs".equals(scheme)) {

ui/src/views/infra/AddPrimaryStorage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
<div
182182
v-if="form.protocol === 'nfs' &&
183183
((form.scope === 'zone' && (form.hypervisor === 'KVM' || form.hypervisor === 'Simulator')) ||
184-
(form.scope === 'cluster' && (hypervisorType === 'KVM' || hypervisorType === 'Simulator')))">
184+
(form.scope === 'cluster' && (hypervisorType === 'KVM' || hypervisorType === 'Simulator' || hypervisorType === 'VMware')))">
185185
<a-form-item name="nfsMountOpts" ref="nfsMountOpts">
186186
<template #label>
187187
<tooltip-label :title="$t('label.nfsmountopts')" :tooltip="$t('message.nfs.mount.options.description')"/>

0 commit comments

Comments
 (0)