Skip to content

Commit 7a3f170

Browse files
authored
Merge pull request #365 from microsoft/users/amgawde/graceful_shutdn
[moc-sdk-for-go] Implement Graceful Shutdown Option for VM Stop Operation
2 parents fa03e2d + a9e080a commit 7a3f170

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/Azure/go-autorest/autorest/date v0.3.0
1111
github.com/google/go-cmp v0.7.0
1212
github.com/google/uuid v1.6.0
13-
github.com/microsoft/moc v0.38.1
13+
github.com/microsoft/moc v0.39.0
1414
google.golang.org/grpc v1.76.0
1515
k8s.io/klog v1.0.0
1616
sigs.k8s.io/controller-runtime v0.20.4
@@ -65,12 +65,12 @@ require (
6565
golang.org/x/crypto v0.40.0 // indirect
6666
golang.org/x/net v0.42.0 // indirect
6767
golang.org/x/oauth2 v0.30.0 // indirect
68-
golang.org/x/sync v0.17.0 // indirect
68+
golang.org/x/sync v0.18.0 // indirect
6969
golang.org/x/term v0.31.0 // indirect
70-
golang.org/x/text v0.30.0 // indirect
70+
golang.org/x/text v0.31.0 // indirect
7171
golang.org/x/time v0.7.0 // indirect
7272
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
73-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
73+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
7474
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
7575
gopkg.in/inf.v0 v0.9.1 // indirect
7676
gopkg.in/ini.v1 v1.67.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
123123
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
124124
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
125125
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
126-
github.com/microsoft/moc v0.38.1 h1:W81M+Yu7gmBvX/g6bp7yfxm1MIfV0eeo78C/CJF/UzQ=
127-
github.com/microsoft/moc v0.38.1/go.mod h1:lF4GKU8OLgqWmOCmu7qLXc/CAqY1Svr5TNsSRLqbt+U=
126+
github.com/microsoft/moc v0.39.0 h1:5EzseQBZp6dpRQkruLZMb2Y8rlTCOjP6YTfDwvqs1tk=
127+
github.com/microsoft/moc v0.39.0/go.mod h1:BOxQDnRiny+EcGVYCkL03fbaT64Uxa3ZoStXWBjixic=
128128
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
129129
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
130130
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -243,8 +243,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
243243
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
244244
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
245245
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
246-
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
247-
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
246+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
247+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
248248
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
249249
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
250250
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
@@ -255,8 +255,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
255255
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
256256
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
257257
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
258-
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
259-
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
258+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
259+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
260260
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
261261
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
262262
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -268,8 +268,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
268268
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
269269
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
270270
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
271-
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
272-
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
271+
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
272+
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
273273
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
274274
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
275275
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -278,8 +278,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw
278278
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
279279
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
280280
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
281-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 h1:M1rk8KBnUsBDg1oPGHNCxG4vc1f49epmTO7xscSajMk=
282-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
281+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba h1:UKgtfRM7Yh93Sya0Fo8ZzhDP4qBckrrxEr2oF5UIVb8=
282+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
283283
google.golang.org/grpc v1.76.0 h1:UnVkv1+uMLYXoIz6o7chp59WfQUYA2ex/BXQ9rHZu7A=
284284
google.golang.org/grpc v1.76.0/go.mod h1:Ju12QI8M6iQJtbcsV+awF5a4hfJMLi4X0JLo94ULZ6c=
285285
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

services/compute/virtualmachine/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Service interface {
2323
Query(context.Context, string, string) (*[]compute.VirtualMachine, error)
2424
Start(context.Context, string, string) error
2525
Stop(context.Context, string, string) error
26+
StopGraceful(context.Context, string, string) error
2627
Pause(context.Context, string, string) error
2728
Save(context.Context, string, string) error
2829
RepairGuestAgent(context.Context, string, string) error
@@ -91,6 +92,12 @@ func (c *VirtualMachineClient) Stop(ctx context.Context, group string, name stri
9192
return
9293
}
9394

95+
// Stop the Virtual Machine gracefully
96+
func (c *VirtualMachineClient) StopGraceful(ctx context.Context, group string, name string) (err error) {
97+
err = c.internal.StopGraceful(ctx, group, name)
98+
return
99+
}
100+
94101
// Restart the Virtual Machine
95102
func (c *VirtualMachineClient) Restart(ctx context.Context, group string, name string) (err error) {
96103
err = c.internal.Stop(ctx, group, name)

services/compute/virtualmachine/wssd.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ func (c *client) Stop(ctx context.Context, group, name string) (err error) {
136136
return
137137
}
138138

139+
// StopGraceful
140+
func (c *client) StopGraceful(ctx context.Context, group, name string) (err error) {
141+
request, err := c.getVirtualMachineOperationRequest(ctx, wssdcloudproto.ProviderAccessOperation_VirtualMachine_Stop_Graceful, group, name)
142+
if err != nil {
143+
return
144+
}
145+
146+
_, err = c.VirtualMachineAgentClient.Operate(ctx, request)
147+
return
148+
}
149+
139150
// Start
140151
func (c *client) Start(ctx context.Context, group, name string) (err error) {
141152
request, err := c.getVirtualMachineOperationRequest(ctx, wssdcloudproto.ProviderAccessOperation_VirtualMachine_Start, group, name)

services/security/role/role.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ func getMocProviderAction(action *security.Action) (wssdcloudcommon.ProviderAcce
174174
return wssdcloudcommon.ProviderAccessOperation_VirtualMachine_Save, nil
175175
case security.VirtualMachine_RemoveIsoDiskAccess:
176176
return wssdcloudcommon.ProviderAccessOperation_VirtualMachine_Remove_Iso_Disk, nil
177+
case security.VirtualMachine_StopGracefulAccess:
178+
return wssdcloudcommon.ProviderAccessOperation_VirtualMachine_Stop_Graceful, nil
177179
case security.Cluster_CreateAccess:
178180
return wssdcloudcommon.ProviderAccessOperation_Cluster_Create, nil
179181
case security.Cluster_UpdateAccess:

services/security/security.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ const (
222222
VirtualMachine_PauseAccess ProviderAccessOperation = "virtualmachine_pause"
223223
VirtualMachine_SaveAccess ProviderAccessOperation = "virtualmachine_save"
224224
VirtualMachine_RemoveIsoDiskAccess ProviderAccessOperation = "virtualmachine_removeisodisk"
225+
VirtualMachine_StopGracefulAccess ProviderAccessOperation = "virtualmachine_stopgraceful"
225226

226227
Cluster_CreateAccess ProviderAccessOperation = "cluster_create"
227228
Cluster_UpdateAccess ProviderAccessOperation = "cluster_update"

0 commit comments

Comments
 (0)