use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method createNtpShare.
/**
* create NetApp share with right permissions
*
* @param StorageSystem mount path of the fileshare
* @param args containing input/out arguments of filedevice
* @param smbFileShare smbFileshare object
* @param forceGroup Name of the group the fileshare belongs.
* @return
*/
private Boolean createNtpShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare, String forceGroup) throws NetAppException {
String shareId = null;
String portGroup = findVfilerName(args.getFs());
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
shareId = smbFileShare.getPath();
_log.info("NetAppFileStorageDevice doShare for {} with id {}", shareId, args.getFileObjId());
if (!nApi.doShare(shareId, smbFileShare.getName(), smbFileShare.getDescription(), smbFileShare.getMaxUsers(), smbFileShare.getPermission(), forceGroup)) {
_log.info("NetAppFileStorageDevice doShare for {} with id {} - failed", shareId, args.getFileObjId());
return false;
} else {
// share creation is successful,no need to set permission,clear the default one.
List<CifsAcl> existingAcls = new ArrayList<CifsAcl>();
CifsAcl defaultAcl = new CifsAcl();
// By default NetApp share get everyone full access.
defaultAcl.setUserName("everyone");
defaultAcl.setAccess(CifsAccess.full);
existingAcls.add(defaultAcl);
nApi.deleteCIFSShareAcl(smbFileShare.getName(), existingAcls);
smbFileShare.setNativeId(shareId);
if (null != args.getFileObj()) {
nApi.setQtreemode(args.getFsPath(), NTFS_QTREE_SETTING);
}
smbFileShare.setNetBIOSName(nApi.getNetBiosName());
_log.info("NetAppFileStorageDevice doShare for {} with id {} - complete", shareId, args.getFileObjId());
return true;
}
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doCreateQuotaDirectory.
// New Qtree methods
@Override
public BiosCommandResult doCreateQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args, QuotaDirectory qtree) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doCreateQuotaDirectory - start");
// Using NetApp terminology here
String volName = args.getFsName();
String qtreeName = args.getQuotaDirectoryName();
Boolean oplocks = qtree.getOpLock();
String securityStyle = qtree.getSecurityStyle();
Long size = qtree.getSize();
if (null == volName) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == qtreeName) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed: Qtree name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (!validQuotaDirectoryPath(volName, qtreeName)) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed: Qtree name or path is too long");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_PATH_TOO_LONG);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
String portGroup = findVfilerName(args.getFs());
_log.info("NetAppFileStorageDevice::NetAppFileStorageDevice - For FS: {}, vFiler: {}", volName, portGroup);
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
nApi.createQtree(qtreeName, volName, oplocks, securityStyle, size, portGroup);
result = BiosCommandResult.createSuccessfulResult();
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed with a NetAppException", e);
_log.info("NetAppFileStorageDevice::doCreateQuotaDirectory e.getLocalizedMessage(): {}", e.getLocalizedMessage());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
List<ExportRule> allExports = args.getExistingDBExportRules();
String subDir = args.getSubDirectory();
boolean allDirs = args.isAllDir();
FileShare fs = args.getFs();
String exportPath;
String subDirExportPath = "";
subDir = args.getSubDirectory();
if (!args.getFileOperation()) {
exportPath = args.getSnapshotPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getSnapshotPath() + "/" + subDir;
}
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getFs().getPath() + "/" + subDir;
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
_log.info("Number of existing exports found {}", allExports.size());
try {
if (allDirs) {
Set<String> allPaths = new HashSet<String>();
// ALL EXPORTS
_log.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
for (ExportRule rule : allExports) {
allPaths.add(rule.getExportPath());
}
for (String path : allPaths) {
_log.info("deleting export path : {} ", path);
nApi.deleteNFSExport(path);
}
} else if (subDir != null && !subDir.isEmpty()) {
// Filter for a specific Sub Directory export
_log.info("Deleting all subdir exports rules at ViPR and sub directory export at device {}", subDir);
for (ExportRule rule : allExports) {
if (rule.getExportPath().endsWith("/" + subDir)) {
nApi.deleteNFSExport(subDirExportPath);
break;
}
}
} else {
// Filter for No SUBDIR - main export rules with no sub dirs
_log.info("Deleting all export rules from DB and export at device not included sub dirs");
nApi.deleteNFSExport(exportPath);
}
} catch (NetAppException e) {
_log.info("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("NetAppFileStorageDevice exportFS {} - complete", args.getFsId());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method rollbackShareACLs.
private BiosCommandResult rollbackShareACLs(StorageSystem storage, FileDeviceInputOutput args, List<ShareACL> existingList) {
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
try {
// We can have multiple ace added/modified in one put call ,some of them can fail due to some reason.
// In case of failure, to make it consistent in vipr db and NetApp share, delete all currently
// added and modified ace and revert it to old acl.
_log.info("NetAppFileStorageDevice::Rolling back update ACL by trying delete ACL for share {}", args.getShareName());
List<ShareACL> aclsToClear = new ArrayList<ShareACL>();
aclsToClear.addAll(args.getShareAclsToAdd());
aclsToClear.addAll(args.getShareAclsToModify());
forceDeleteShareAcl(nApi, args.getShareName(), aclsToClear);
_log.info("NetAppFileStorageDevice::Adding back old ACL to Share {}", args.getShareName());
forceAddShareAcl(nApi, args.getShareName(), existingList);
result = BiosCommandResult.createSuccessfulResult();
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::Roll Back of ACL failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToUpdateCIFSShareAcl();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doSnapshotFS.
@Override
public BiosCommandResult doSnapshotFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doSnapshotFS - start");
if (null == args.getFsName()) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == args.getSnapshotName()) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed: Snapshot name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
boolean failedStatus = false;
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
if (!nApi.createSnapshot(args.getFsName(), args.getSnapshotName())) {
failedStatus = true;
}
if (failedStatus == true) {
_log.error("NetAppFileStorageDevice doSnapshotFS {} - failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(genDetailedMessage("doSnapshotFS", args.getFsName()));
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("doSnapshotFS - Snapshot, {} was successfully created for filesystem, {} ", args.getSnapshotName(), args.getFsName());
// Set snapshot Path and MountPath information
args.setSnapshotMountPath(getSnapshotMountPath(args.getFsMountPath(), args.getSnapshotName()));
args.setSnapshotPath(getSnapshotPath(args.getFsPath(), args.getSnapshotName()));
args.setSnapNativeId(args.getSnapshotName());
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
Aggregations