Skip to content

Commit

Permalink
Added method to create file system with nfs share.
Browse files Browse the repository at this point in the history
Added method to modify file system and nfs share.
Updateed file system create model to accomodate nfs content with file system.
Added model to modify file system with nfs share.
Updated nfs share parameter model to accomodate adding comma separated list of hosts for different access types.
Updated file content response model to receive nfs share content and used size of file system.
Update nfs share content response model to receive comma separated list of hosts for different access types.
  • Loading branch information
sanketcoredge committed Apr 8, 2024
1 parent 3e09d89 commit 341e9e9
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 32 deletions.
196 changes: 196 additions & 0 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,202 @@ func (f *Filesystem) GetFilesystemIDFromResID(ctx context.Context, filesystemRes
return fileSystemResp.StorageResourceContent.Filesystem.ID, nil
}

// CreateFilesystemWithNFSShare - Create a new filesystem with NFS share on the array
func (f *Filesystem) CreateFilesystemWithNFSShare(ctx context.Context, name, storagepool, description, nasServer,
nfsShareName, path string, size uint64, tieringPolicy,
hostIOSize, supportedProtocol int, isThinEnabled, isDataReductionEnabled bool,
nfsShareDefaultAccess NFSShareDefaultAccess, noAccessHosts, roHosts, rwHosts, roRootHosts,
rwRootHosts string, exportOption int, hostIDs []string, accessType AccessType) (*types.Filesystem, error) {
log := util.GetRunIDLogger(ctx)
if name == "" {
return nil, errors.New("filesystem name should not be empty")
}

if len(name) > FsNameMaxLength {
return nil, fmt.Errorf("filesystem name %s should not exceed %d characters", name, FsNameMaxLength)
}

poolAPI := NewStoragePool(f.client)
pool, err := poolAPI.FindStoragePoolByID(ctx, storagepool)
if err != nil {
return nil, fmt.Errorf("unable to get PoolID (%s) Error:%v", storagepool, err)
}

storagePool := types.StoragePoolID{
PoolID: storagepool,
}

fileEventSettings := types.FileEventSettings{
IsCIFSEnabled: false, // Set to false to disable CIFS
IsNFSEnabled: true, // Set to true to enable NFS alone
}

nas := types.NasServerID{
NasServerID: nasServer,
}

fsParams := types.FsParameters{
StoragePool: &storagePool,
Size: size,
SupportedProtocol: supportedProtocol,
HostIOSize: hostIOSize,
NasServer: &nas,
FileEventSettings: fileEventSettings,
}

volAPI := NewVolume(f.client)
thinProvisioningLicenseInfoResp, err := volAPI.isFeatureLicensed(ctx, ThinProvisioning)
if err != nil {
return nil, fmt.Errorf("unable to get license info for feature: %s", ThinProvisioning)
}

dataReductionLicenseInfoResp, err := volAPI.isFeatureLicensed(ctx, DataReduction)
if err != nil {
return nil, fmt.Errorf("unable to get license info for feature: %s", DataReduction)
}

if thinProvisioningLicenseInfoResp.LicenseInfoContent.IsInstalled && thinProvisioningLicenseInfoResp.LicenseInfoContent.IsValid {
fsParams.IsThinEnabled = strconv.FormatBool(isThinEnabled)
} else if isThinEnabled == true {
return nil, fmt.Errorf("thin provisioning is not supported on array and hence cannot create Filesystem")
}

if dataReductionLicenseInfoResp.LicenseInfoContent.IsInstalled && dataReductionLicenseInfoResp.LicenseInfoContent.IsValid {
fsParams.IsDataReductionEnabled = strconv.FormatBool(isDataReductionEnabled)
} else if isDataReductionEnabled == true {
return nil, fmt.Errorf("data reduction is not supported on array and hence cannot create Filesystem")
}

if pool != nil && pool.StoragePoolContent.PoolFastVP.Status != 0 {
log.Debug("FastVP is enabled")
fastVPParameters := types.FastVPParameters{
TieringPolicy: tieringPolicy,
}
fsParams.FastVPParameters = &fastVPParameters
} else {
log.Debug("FastVP is not enabled")
if tieringPolicy != 0 {
return nil, fmt.Errorf("fastVP is not enabled and requested tiering policy is: %d ", tieringPolicy)
}
}

nfsShareParam := types.NFSShareParameters{
DefaultAccess: string(nfsShareDefaultAccess),
NoAccessHostsString: noAccessHosts,
ReadOnlyHostsString: roHosts,
ReadWriteHostsString: rwHosts,
ReadOnlyRootAccessHostsString: roRootHosts,
ReadWriteRootHostsString: rwRootHosts,
ExportOption: exportOption,
}

hostsIdsContent := []types.HostIDContent{}
for _, hostID := range hostIDs {
hostIDContent := types.HostIDContent{
ID: hostID,
}
hostsIdsContent = append(hostsIdsContent, hostIDContent)
}

if accessType == ReadOnlyAccessType {
nfsShareParam.ReadOnlyHosts = &hostsIdsContent
} else if accessType == ReadWriteAccessType {
nfsShareParam.ReadWriteHosts = &hostsIdsContent
} else if accessType == ReadOnlyRootAccessType {
nfsShareParam.ReadOnlyRootAccessHosts = &hostsIdsContent
} else if accessType == ReadWriteRootAccessType {
nfsShareParam.RootAccessHosts = &hostsIdsContent
}

nfsShareCreateReqParam := types.NFSShareCreateParam{
Name: name,
Path: path,
NFSShareParameters: &nfsShareParam,
}

nfsShares := []types.NFSShareCreateParam{nfsShareCreateReqParam}

fileReqParam := types.FsCreateParam{
Name: name,
Description: description,
FsParameters: &fsParams,
NFSShares: &nfsShares,
}

fileResp := &types.Filesystem{}
err = f.client.executeWithRetryAuthenticate(ctx,
http.MethodPost, fmt.Sprintf(api.UnityAPIStorageResourceActionURI, api.CreateFSAction), fileReqParam, fileResp)
if err != nil {
return nil, err
}

return fileResp, nil
}

// ModifyFilesystemWithNFSShare Modify filesystem to expand
func (f *Filesystem) ModifyFilesystemWithNFSShare(ctx context.Context, filesystemID, nfsShareID string, newSize uint64,
nfsShareDefaultAccess NFSShareDefaultAccess, noAccessHosts, roHosts, rwHosts, roRootHosts,
rwRootHosts string, exportOption int, hostIDs []string, accessType AccessType) error {
log := util.GetRunIDLogger(ctx)
filesystem, err := f.FindFilesystemByID(ctx, filesystemID)
if err != nil {
return fmt.Errorf("unable to find filesystem Id %s. Error: %v", filesystemID, err)
}
if filesystem.FileContent.SizeTotal == newSize {
log.Infof("New Volume size (%d) is same as existing Volume size (%d).", newSize, filesystem.FileContent.SizeTotal)
} else if filesystem.FileContent.SizeTotal > newSize {
return fmt.Errorf("requested new capacity smaller than existing capacity")
}
fsExpandParams := types.FsExpandParameters{
Size: newSize,
}

nfsShareParam := types.NFSShareParameters{
DefaultAccess: string(nfsShareDefaultAccess),
NoAccessHostsString: noAccessHosts,
ReadOnlyHostsString: roHosts,
ReadWriteHostsString: rwHosts,
ReadOnlyRootAccessHostsString: roRootHosts,
ReadWriteRootHostsString: rwRootHosts,
ExportOption: exportOption,
}

hostsIdsContent := []types.HostIDContent{}
for _, hostID := range hostIDs {
hostIDContent := types.HostIDContent{
ID: hostID,
}
hostsIdsContent = append(hostsIdsContent, hostIDContent)
}

if accessType == ReadOnlyAccessType {
nfsShareParam.ReadOnlyHosts = &hostsIdsContent
} else if accessType == ReadWriteAccessType {
nfsShareParam.ReadWriteHosts = &hostsIdsContent
} else if accessType == ReadOnlyRootAccessType {
nfsShareParam.ReadOnlyRootAccessHosts = &hostsIdsContent
} else if accessType == ReadWriteRootAccessType {
nfsShareParam.RootAccessHosts = &hostsIdsContent
}

nfsShare := types.StorageResourceParam{
ID: nfsShareID,
}

nfsShareModifyContent := types.NFSShareModifyContent{
NFSShare: &nfsShare,
NFSShareParameters: &nfsShareParam,
}
nfsSharesModifyContent := []types.NFSShareModifyContent{nfsShareModifyContent}

fsExpandReqParam := types.FsModifyWithNFSShareParam{
FsParameters: &fsExpandParams,
NFSSharesModifyContent: &nfsSharesModifyContent,
}

return f.client.executeWithRetryAuthenticate(ctx, http.MethodPost, fmt.Sprintf(api.UnityModifyFilesystemURI, filesystem.FileContent.StorageResource.ID), fsExpandReqParam, nil)
}

// CreateFilesystem - Create a new filesystem on the array
func (f *Filesystem) CreateFilesystem(ctx context.Context, name, storagepool, description, nasServer string, size uint64, tieringPolicy, hostIOSize, supportedProtocol int, isThinEnabled, isDataReductionEnabled bool) (*types.Filesystem, error) {
log := util.GetRunIDLogger(ctx)
Expand Down
29 changes: 21 additions & 8 deletions types/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ type LunParameters struct {

// FsCreateParam Struct to capture the Filesystem create Params
type FsCreateParam struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
FsParameters *FsParameters `json:"fsParameters"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
FsParameters *FsParameters `json:"fsParameters"`
NFSShares *[]NFSShareCreateParam `json:"nfsShareCreate,omitempty"`
}

// FsParameters Struct to capture the File system properties
Expand Down Expand Up @@ -105,6 +106,12 @@ type FsExpandModifyParam struct {
FsParameters *FsExpandParameters `json:"fsParameters"`
}

// FsModifyWithNFSShareParam Struct to expand Filesystem
type FsModifyWithNFSShareParam struct {
FsParameters *FsExpandParameters `json:"fsParameters"`
NFSSharesModifyContent *[]NFSShareModifyContent `json:"nfsShareModify,omitempty"`
}

// FsModifyParameters Struct to modify Filesystem parameters
type FsModifyParameters struct {
NFSShares *[]NFSShareCreateParam `json:"nfsShareCreate,omitempty"`
Expand Down Expand Up @@ -153,11 +160,17 @@ type NFSShareModifyContent struct {

// NFSShareParameters Struct to capture NFS Share properties
type NFSShareParameters struct {
DefaultAccess string `json:"defaultAccess,omitempty"`
ReadOnlyHosts *[]HostIDContent `json:"readOnlyHosts,omitempty"`
ReadWriteHosts *[]HostIDContent `json:"readWriteHosts,omitempty"`
ReadOnlyRootAccessHosts *[]HostIDContent `json:"readOnlyRootAccessHosts,omitempty"`
RootAccessHosts *[]HostIDContent `json:"rootAccessHosts,omitempty"`
DefaultAccess string `json:"defaultAccess,omitempty"`
ReadOnlyHosts *[]HostIDContent `json:"readOnlyHosts,omitempty"`
ReadWriteHosts *[]HostIDContent `json:"readWriteHosts,omitempty"`
ReadOnlyRootAccessHosts *[]HostIDContent `json:"readOnlyRootAccessHosts,omitempty"`
RootAccessHosts *[]HostIDContent `json:"rootAccessHosts,omitempty"`
NoAccessHostsString string `json:"noAccessHostsString,omitempty"`
ReadOnlyHostsString string `json:"readOnlyHostsString,omitempty"`
ReadWriteHostsString string `json:"readWriteHostsString,omitempty"`
ReadOnlyRootAccessHostsString string `json:"readOnlyRootHostsString,omitempty"`
ReadWriteRootHostsString string `json:"readWriteRootHostsString,omitempty"`
ExportOption int `json:"exportOption,omitempty"`
}

// FileEventSettings Struct to capture File event settings
Expand Down
57 changes: 33 additions & 24 deletions types/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,23 @@ type Filesystem struct {

// FileContent struct to capture filesystem parameters
type FileContent struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
SizeTotal uint64 `json:"sizeTotal,omitempty"`
Description string `json:"description,omitempty"`
Type int `json:"type,omitempty"`
Format int `json:"format,omitempty"`
HostIOSize int64 `json:"hostIOSize,omitempty"`
TieringPolicy uint64 `json:"tieringPolicy,omitempty"`
IsThinEnabled bool `json:"isThinEnabled"`
IsDataReductionEnabled bool `json:"isDataReductionEnabled"`
Pool Pool `json:"pool,omitempty"`
NASServer Pool `json:"nasServer,omitempty"`
StorageResource Pool `json:"storageResource,omitempty"`
NFSShare []Share `json:"nfsShare,omitempty"`
CIFSShare []Pool `json:"cifsShare,omitempty"`
Health HealthContent `json:"health,omitempty"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
SizeTotal uint64 `json:"sizeTotal,omitempty"`
SizeUsed uint64 `json:"sizeUsed,omitempty"`
Description string `json:"description,omitempty"`
Type int `json:"type,omitempty"`
Format int `json:"format,omitempty"`
HostIOSize int64 `json:"hostIOSize,omitempty"`
TieringPolicy uint64 `json:"tieringPolicy,omitempty"`
IsThinEnabled bool `json:"isThinEnabled"`
IsDataReductionEnabled bool `json:"isDataReductionEnabled"`
Pool Pool `json:"pool,omitempty"`
NASServer Pool `json:"nasServer,omitempty"`
StorageResource Pool `json:"storageResource,omitempty"`
NFSShare []NFSShareContent `json:"nfsShare,omitempty"`
CIFSShare []Pool `json:"cifsShare,omitempty"`
Health HealthContent `json:"health,omitempty"`
}

// Share object to capture NFS Share object from FileContent
Expand All @@ -315,14 +316,22 @@ type NFSShare struct {

// NFSShareContent struct to capture NFS Share parameters
type NFSShareContent struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Filesystem Pool `json:"filesystem,omitempty"`
ReadOnlyHosts []HostContent `json:"readOnlyHosts,omitempty"`
ReadWriteHosts []HostContent `json:"readWriteHosts,omitempty"`
ReadOnlyRootAccessHosts []HostContent `json:"readOnlyRootAccessHosts,omitempty"`
RootAccessHosts []HostContent `json:"rootAccessHosts,omitempty"`
ExportPaths []string `json:"exportPaths,omitempty"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
ParentSnap StorageResource `json:"snap,omitempty"`
Filesystem Pool `json:"filesystem,omitempty"`
ReadOnlyHosts []HostContent `json:"readOnlyHosts,omitempty"`
ReadWriteHosts []HostContent `json:"readWriteHosts,omitempty"`
ReadOnlyRootAccessHosts []HostContent `json:"readOnlyRootAccessHosts,omitempty"`
RootAccessHosts []HostContent `json:"rootAccessHosts,omitempty"`
ExportPaths []string `json:"exportPaths,omitempty"`
NoAccessHostsString string `json:"noAccessHostsString,omitempty"`
ReadOnlyHostsString string `json:"readOnlyHostsString,omitempty"`
ReadWriteHostsString string `json:"readWriteHostsString,omitempty"`
ReadOnlyRootAccessHostsString string `json:"readOnlyRootHostsString,omitempty"`
ReadWriteRootHostsString string `json:"readWriteRootHostsString,omitempty"`
ExportOption int `json:"exportOption,omitempty"`
}

// NASServer struct to capture NAS Server object
Expand Down

0 comments on commit 341e9e9

Please sign in to comment.