Skip to content

Commit d772df1

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
vm instance creation test2
1 parent 953c552 commit d772df1

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.storage.Storage;
2828
import com.cloud.storage.StoragePool;
2929
import com.cloud.storage.Volume;
30+
import com.cloud.storage.VolumeVO;
3031
import com.cloud.utils.Pair;
3132
import com.cloud.utils.exception.CloudRuntimeException;
3233
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
@@ -64,6 +65,7 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
6465

6566
@Inject private StoragePoolDetailsDao storagePoolDetailsDao;
6667
@Inject private PrimaryDataStoreDao storagePoolDao;
68+
@Inject private com.cloud.storage.dao.VolumeDao volumeDao;
6769
@Override
6870
public Map<String, String> getCapabilities() {
6971
s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called");
@@ -128,11 +130,23 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
128130
throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId());
129131
}
130132
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
131-
// For NFS, skip ONTAP REST API operations - CloudStack manages files natively
133+
// For managed NFS: create subdirectory via ONTAP REST API, store path in DB, return null
134+
// KVM will mount this subdirectory separately as: storage-ip:/vol/volumename/subdir -> /mnt/{volume-uuid}
132135
if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
133-
String volumeUuid = ((VolumeInfo) dataObject).getUuid();
134-
s_logger.info("createCloudStackVolumeForTypeVolume: NFS protocol detected - returning volume UUID for native file management: {}", volumeUuid);
135-
return volumeUuid;
136+
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);
137+
s_logger.info("createCloudStackVolumeForTypeVolume: NFS - creating subdirectory on ONTAP for volume: {}", ((VolumeInfo) dataObject).getName());
138+
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject);
139+
storageStrategy.createCloudStackVolume(cloudStackVolumeRequest); // Creates subdirectory on ONTAP via REST API
140+
// Store the subdirectory path for KVM to mount separately
141+
String subdirectoryPath = "/" + ((VolumeInfo) dataObject).getName();
142+
VolumeVO volume = volumeDao.findById(((VolumeInfo) dataObject).getId());
143+
volume.set_iScsiName(subdirectoryPath); // Used as MOUNT_POINT for NFS managed storage
144+
volume.setFolder(((VolumeInfo) dataObject).getUuid());
145+
volume.setPoolId(dataStore.getId());
146+
volume.setPath(null); // Path is null for managed storage - KVM creates files in mounted subdir
147+
volumeDao.update(volume.getId(), volume);
148+
s_logger.info("createCloudStackVolumeForTypeVolume: NFS subdirectory created, path stored: {}", subdirectoryPath);
149+
return null; // Return null - backend work done, KVM will handle file creation
136150
}
137151
// For iSCSI and other protocols, use ONTAP REST API
138152
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Utility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePo
6969
cloudStackVolumeRequest = new CloudStackVolume();
7070
FileInfo file = new FileInfo();
7171
//file.setName("test1"); // to be replaced with volume name // this should not be passed for dir
72-
//file.setName(volumeObject.getName()); // to check whether this needs to be sent or not
72+
file.setName(volumeObject.getName()); // to check whether this needs to be sent or not
7373
//file.setSize(Long.parseLong("10000"));
7474
//file.setSize(volumeObject.getSize());
7575
file.setUnixPermissions(755); // check if it is needed only for dir ? it is needed for dir

0 commit comments

Comments
 (0)