Skip to content

Commit 4cddf58

Browse files
added provision for attach and detach share (#926)
* added provision for attach and detach share * fixed comments --------- Co-authored-by: anup-deka <[email protected]>
1 parent 4c42b35 commit 4cddf58

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

nfs_actions.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
type NfsActionsService interface {
1313
Resize(ctx context.Context, nfsShareId string, size uint64, region string) (*NfsAction, *Response, error)
1414
Snapshot(ctx context.Context, nfsShareId string, nfsSnapshotName string, region string) (*NfsAction, *Response, error)
15+
Attach(ctx context.Context, nfsShareId string, vpcID string, region string) (*NfsAction, *Response, error)
16+
Detach(ctx context.Context, nfsShareId string, vpcID string, region string) (*NfsAction, *Response, error)
1517
}
1618

1719
// NfsActionsServiceOp handles communication with the NFS action related
@@ -57,6 +59,16 @@ type NfsSnapshotParams struct {
5759
Name string `json:"name"`
5860
}
5961

62+
// NfsAttachParams represents parameters for attaching an NFS share to a VPC
63+
type NfsAttachParams struct {
64+
VpcID string `json:"vpc_id"`
65+
}
66+
67+
// NfsDetachParams represents parameters for detaching an NFS share from a VPC
68+
type NfsDetachParams struct {
69+
VpcID string `json:"vpc_id"`
70+
}
71+
6072
// Resize an NFS share
6173
func (s *NfsActionsServiceOp) Resize(ctx context.Context, nfsShareId string, size uint64, region string) (*NfsAction, *Response, error) {
6274
request := &NfsActionRequest{
@@ -83,6 +95,32 @@ func (s *NfsActionsServiceOp) Snapshot(ctx context.Context, nfsShareId, nfsSnaps
8395
return s.doAction(ctx, nfsShareId, request)
8496
}
8597

98+
// Attach an NFS share
99+
func (s *NfsActionsServiceOp) Attach(ctx context.Context, nfsShareId, vpcID, region string) (*NfsAction, *Response, error) {
100+
request := &NfsActionRequest{
101+
Type: "attach",
102+
Region: region,
103+
Params: &NfsAttachParams{
104+
VpcID: vpcID,
105+
},
106+
}
107+
108+
return s.doAction(ctx, nfsShareId, request)
109+
}
110+
111+
// Detach an NFS share
112+
func (s *NfsActionsServiceOp) Detach(ctx context.Context, nfsShareId, vpcID, region string) (*NfsAction, *Response, error) {
113+
request := &NfsActionRequest{
114+
Type: "detach",
115+
Region: region,
116+
Params: &NfsAttachParams{
117+
VpcID: vpcID,
118+
},
119+
}
120+
121+
return s.doAction(ctx, nfsShareId, request)
122+
}
123+
86124
func (s *NfsActionsServiceOp) doAction(ctx context.Context, nfsShareId string, request *NfsActionRequest) (*NfsAction, *Response, error) {
87125
if request == nil {
88126
return nil, nil, NewArgError("request", "request can't be nil")

nfs_actions_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,43 @@ func TestNfsSnapshot(t *testing.T) {
4848
assert.Equal(t, "in-progress", action.Status)
4949
assert.Equal(t, "snapshot", action.Type)
5050
}
51+
52+
func TestNfsAttach(t *testing.T) {
53+
setup()
54+
defer teardown()
55+
56+
mux.HandleFunc("/v2/nfs/my-nfs-id/actions", func(w http.ResponseWriter, r *http.Request) {
57+
assert.Equal(t, http.MethodPost, r.Method)
58+
w.WriteHeader(http.StatusCreated)
59+
fmt.Fprint(w, `{"action": {"id": 1, "status": "in-progress", "type": "attach", "resource_type": "network_file_share", "resource_id": "my-nfs-id", "region_slug": "atl1", "started_at": "2025-10-14T11:55:31.615157397Z"}}`)
60+
})
61+
62+
action, resp, err := client.NfsActions.Attach(context.Background(), "my-nfs-id", "my-vpc-id", "atl1")
63+
assert.NoError(t, err)
64+
assert.NotNil(t, resp)
65+
assert.Equal(t, "my-nfs-id", action.ResourceID)
66+
assert.Equal(t, "atl1", action.RegionSlug)
67+
assert.Equal(t, "network_file_share", action.ResourceType)
68+
assert.Equal(t, "in-progress", action.Status)
69+
assert.Equal(t, "attach", action.Type)
70+
}
71+
72+
func TestNfsDetach(t *testing.T) {
73+
setup()
74+
defer teardown()
75+
76+
mux.HandleFunc("/v2/nfs/my-nfs-id/actions", func(w http.ResponseWriter, r *http.Request) {
77+
assert.Equal(t, http.MethodPost, r.Method)
78+
w.WriteHeader(http.StatusCreated)
79+
fmt.Fprint(w, `{"action": {"id": 1, "status": "in-progress", "type": "detach", "resource_type": "network_file_share", "resource_id": "my-nfs-id", "region_slug": "atl1", "started_at": "2025-10-14T11:55:31.615157397Z"}}`)
80+
})
81+
82+
action, resp, err := client.NfsActions.Detach(context.Background(), "my-nfs-id", "my-vpc-id", "atl1")
83+
assert.NoError(t, err)
84+
assert.NotNil(t, resp)
85+
assert.Equal(t, "my-nfs-id", action.ResourceID)
86+
assert.Equal(t, "atl1", action.RegionSlug)
87+
assert.Equal(t, "network_file_share", action.ResourceType)
88+
assert.Equal(t, "in-progress", action.Status)
89+
assert.Equal(t, "detach", action.Type)
90+
}

0 commit comments

Comments
 (0)