Skip to content

Commit 5d8d3ec

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
vm instance creation test13
1 parent f79e57a commit 5d8d3ec

File tree

3 files changed

+66
-46
lines changed

3 files changed

+66
-46
lines changed

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

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public class OntapPrimaryDatastoreDriver implements PrimaryDataStoreDriver {
7070
public Map<String, String> getCapabilities() {
7171
s_logger.trace("OntapPrimaryDatastoreDriver: getCapabilities: Called");
7272
Map<String, String> mapCapabilities = new HashMap<>();
73-
74-
mapCapabilities.put(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString(), Boolean.TRUE.toString());
75-
mapCapabilities.put(DataStoreCapabilities.CAN_CREATE_VOLUME_FROM_SNAPSHOT.toString(), Boolean.TRUE.toString());
73+
// RAW managed initial implementation: snapshot features not yet supported
74+
mapCapabilities.put(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString(), Boolean.FALSE.toString());
75+
mapCapabilities.put(DataStoreCapabilities.CAN_CREATE_VOLUME_FROM_SNAPSHOT.toString(), Boolean.FALSE.toString());
7676

7777
return mapCapabilities;
7878
}
@@ -130,36 +130,26 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
130130
throw new CloudRuntimeException("createCloudStackVolume : Storage Pool not found for id: " + dataStore.getId());
131131
}
132132
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
133+
134+
// For iSCSI and other protocols, use ONTAP REST API
135+
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);
133136
// For managed NFS: Use flat structure (no subdirectories) like other managed storage providers
134137
// KVM expects volumes to be in the root of the NFS mount with unique names
135138
if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
136139
VolumeVO volume = volumeDao.findById(((VolumeInfo) dataObject).getId());
137-
// CRITICAL: Set poolType at VOLUME level
138-
// This tells KVM to use LibvirtStorageAdaptor (NFS) instead of IscsiAdmStorageAdaptor
139140
volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
140-
// Use UUID only (KVM's default behavior for managed NFS)
141-
// KVM's getPhysicalDisk() is hardcoded to use UUID, not custom paths
142141
String volumeUuid = ((VolumeInfo) dataObject).getUuid();
143-
// Set path to UUID (KVM will use this)
144-
volume.setPath(volumeUuid);
145-
volume.setFolder(""); // No folder for flat structure
142+
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject);
143+
CloudStackVolume created = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest);
144+
String rawFileName = created.getCloudstackVolName(); // <uuid>.raw
145+
volume.setPath(rawFileName);
146+
volume.setFormat(Storage.ImageFormat.RAW);
146147
volume.setPoolId(dataStore.getId());
147148
volumeDao.update(volume.getId(), volume);
148-
s_logger.info("=== ONTAP Managed NFS Volume (Flat Structure - UUID only) ===");
149-
s_logger.info("Volume Name: {}", ((VolumeInfo) dataObject).getName());
150-
s_logger.info("Volume UUID: {}", volumeUuid);
151-
s_logger.info("Volume Path: {} (UUID-based, KVM default)", volumeUuid);
152-
s_logger.info("Volume PoolType: {}", volume.getPoolType());
153-
s_logger.info("Returning null - hypervisor will create: /mnt/<pool>/{}.qcow2", volumeUuid);
154-
s_logger.info("Note: KVM's LibvirtStoragePool.getPhysicalDisk() is hardcoded to use UUID");
155-
s_logger.info("================================================");
156-
// CRITICAL: Return null to tell CloudStack to trigger KVM volume creation!
157-
// If we return a path, CloudStack thinks volume is already created and skips KVM
158-
// This causes DATA volumes to never be created
159-
return null;
149+
s_logger.info("ONTAP RAW managed NFS volume created: uuid={} path={} format=RAW", volumeUuid, rawFileName);
150+
return rawFileName;
160151
}
161-
// For iSCSI and other protocols, use ONTAP REST API
162-
StorageStrategy storageStrategy = getStrategyByStoragePoolDetails(details);
152+
163153
s_logger.info("createCloudStackVolumeForTypeVolume: Connection to Ontap SVM [{}] successful, preparing CloudStackVolumeRequest", details.get(Constants.SVM_NAME));
164154
CloudStackVolume cloudStackVolumeRequest = Utility.createCloudStackVolumeRequestByProtocol(storagePool, details, (VolumeInfo) dataObject);
165155
CloudStackVolume cloudStackVolume = storageStrategy.createCloudStackVolume(cloudStackVolumeRequest);
@@ -174,7 +164,34 @@ private String createCloudStackVolumeForTypeVolume(DataStore dataStore, DataObje
174164

175165
@Override
176166
public void deleteAsync(DataStore store, DataObject data, AsyncCompletionCallback<CommandResult> callback) {
177-
167+
CommandResult commandResult = new CommandResult();
168+
try {
169+
if (store == null || data == null) {
170+
throw new CloudRuntimeException("deleteAsync: store or data is null");
171+
}
172+
if (data.getType() == DataObjectType.VOLUME) {
173+
StoragePoolVO storagePool = storagePoolDao.findById(store.getId());
174+
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(store.getId());
175+
if (ProtocolType.NFS.name().equalsIgnoreCase(details.get(Constants.PROTOCOL))) {
176+
VolumeVO volume = volumeDao.findById(data.getId());
177+
if (volume != null && volume.getPath() != null) {
178+
StorageStrategy strategy = getStrategyByStoragePoolDetails(details);
179+
if (strategy instanceof org.apache.cloudstack.storage.service.UnifiedNASStrategy) {
180+
boolean deleted = ((org.apache.cloudstack.storage.service.UnifiedNASStrategy) strategy)
181+
.deleteManagedFile(details.get(Constants.VOLUME_UUID), volume.getPath());
182+
if (!deleted) {
183+
throw new CloudRuntimeException("Failed to delete RAW file " + volume.getPath());
184+
}
185+
s_logger.info("Deleted RAW managed file {} for volume id {}", volume.getPath(), volume.getId());
186+
}
187+
}
188+
}
189+
}
190+
} catch (Exception e) {
191+
commandResult.setResult(e.getMessage());
192+
} finally {
193+
callback.complete(commandResult);
194+
}
178195
}
179196

180197
@Override
@@ -248,7 +265,7 @@ public void handleQualityOfServiceForVolumeMigration(VolumeInfo volumeInfo, Qual
248265

249266
@Override
250267
public boolean canProvideStorageStats() {
251-
return true;
268+
return false;
252269
}
253270

254271
@Override
@@ -258,7 +275,7 @@ public Pair<Long, Long> getStorageStats(StoragePool storagePool) {
258275

259276
@Override
260277
public boolean canProvideVolumeStats() {
261-
return true;
278+
return false; // Not yet implemented for RAW managed NFS
262279
}
263280

264281
@Override

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,29 @@ public void setOntapStorage(OntapStorage ontapStorage) {
7676

7777
@Override
7878
public CloudStackVolume createCloudStackVolume(CloudStackVolume cloudstackVolume) {
79-
s_logger.info("createCloudStackVolume: Create cloudstack volume " + cloudstackVolume);
79+
s_logger.info("createCloudStackVolume: Creating RAW managed file for CloudStack volume: " + cloudstackVolume.getCloudstackVolName());
8080
try {
81-
boolean success = createFile(cloudstackVolume.getVolume().getUuid(), cloudstackVolume.getCloudstackVolName(), cloudstackVolume.getFile());
81+
FileInfo fileInfo = cloudstackVolume.getFile();
82+
fileInfo.setPath(cloudstackVolume.getCloudstackVolName());
83+
fileInfo.setType(FileInfo.TypeEnum.FILE);
84+
fileInfo.setUnixPermissions(644);
85+
boolean success = createFile(cloudstackVolume.getVolume().getUuid(), cloudstackVolume.getCloudstackVolName(), fileInfo);
8286
if (!success) {
83-
throw new CloudRuntimeException("Failed to create directory on ONTAP: " + cloudstackVolume.getCloudstackVolName());
87+
throw new CloudRuntimeException("Failed to create RAW file on ONTAP: " + cloudstackVolume.getCloudstackVolName());
8488
}
85-
s_logger.debug("Successfully created file in ONTAP under volume with path {} or name {}", cloudstackVolume.getVolume().getUuid(), cloudstackVolume.getCloudstackVolName());
86-
FileInfo responseFile = cloudstackVolume.getFile();
87-
responseFile.setPath(cloudstackVolume.getCloudstackVolName());
89+
s_logger.debug("RAW file created in FlexVol UUID={} filename={}", cloudstackVolume.getVolume().getUuid(), cloudstackVolume.getCloudstackVolName());
90+
return cloudstackVolume;
8891
} catch (Exception e) {
89-
s_logger.error("Exception occurred while creating file or dir: {}. Exception: {}", cloudstackVolume.getCloudstackVolName(), e.getMessage());
90-
throw new CloudRuntimeException("Failed to create file: " + e.getMessage());
92+
s_logger.error("Exception occurred while creating RAW file {}. Exception: {}", cloudstackVolume.getCloudstackVolName(), e.getMessage());
93+
throw new CloudRuntimeException("Failed to create RAW file: " + e.getMessage());
9194
}
92-
return cloudstackVolume;
95+
}
96+
97+
/**
98+
* Public wrapper for deleting managed RAW file.
99+
*/
100+
public boolean deleteManagedFile(String volumeUuid, String fileName) {
101+
return deleteFile(volumeUuid, fileName);
93102
}
94103

95104
@Override

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,17 @@ public static CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePo
6565
ProtocolType protocolType = ProtocolType.valueOf(protocol);
6666
switch (protocolType) {
6767
case NFS:
68-
// For managed NFS: create subdirectory with readable name combining volume name and UUID
69-
// Format: "ROOT-15_9c2e59a8-ee14-4f80-9db4-e279a12e0d7b"
70-
// Hypervisor will create volume files inside this subdirectory with format-specific extensions
68+
// RAW managed NFS: create a regular file <uuid>.raw via ONTAP API
7169
cloudStackVolumeRequest = new CloudStackVolume();
7270
FileInfo file = new FileInfo();
73-
file.setUnixPermissions(755);
74-
file.setType(FileInfo.TypeEnum.DIRECTORY);
75-
71+
file.setUnixPermissions(644);
72+
file.setType(FileInfo.TypeEnum.FILE);
7673
Volume poolVolume = new Volume();
7774
poolVolume.setName(details.get(Constants.VOLUME_NAME));
7875
poolVolume.setUuid(details.get(Constants.VOLUME_UUID));
7976
cloudStackVolumeRequest.setVolume(poolVolume);
8077
cloudStackVolumeRequest.setFile(file);
81-
// Use "name_uuid" format for readable subdirectory name
82-
String readableSubdirName = volumeObject.getName() + "_" + volumeObject.getUuid();
83-
cloudStackVolumeRequest.setCloudstackVolName(readableSubdirName);
84-
cloudStackVolumeRequest.setCloudstackVolUUID(volumeObject.getUuid());
78+
cloudStackVolumeRequest.setCloudstackVolName(volumeObject.getUuid() + ".raw");
8579
break;
8680
case ISCSI:
8781
cloudStackVolumeRequest = new CloudStackVolume();

0 commit comments

Comments
 (0)