forked from baidubce/bce-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
857 lines (767 loc) · 26.6 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
/*
* Copyright 2017 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
// client.go - define the client for BOS service
// Package bcc defines the BCC services of BCE. The supported APIs are all defined in sub-package
package bcc
import (
"encoding/json"
"github.com/baidubce/bce-sdk-go/auth"
"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
)
const DEFAULT_SERVICE_DOMAIN = "bcc." + bce.DEFAULT_REGION + ".baidubce.com"
// Client of BCC service is a kind of BceClient, so derived from BceClient
type Client struct {
*bce.BceClient
}
// NewClient make the BCC service client with default configuration.
// Use `cli.Config.xxx` to access the config or change it to non-default value.
func NewClient(ak, sk, endPoint string) (*Client, error) {
credentials, err := auth.NewBceCredentials(ak, sk)
if err != nil {
return nil, err
}
if endPoint == "" {
endPoint = DEFAULT_SERVICE_DOMAIN
}
defaultSignOptions := &auth.SignOptions{
HeadersToSign: auth.DEFAULT_HEADERS_TO_SIGN,
ExpireSeconds: auth.DEFAULT_EXPIRE_SECONDS}
defaultConf := &bce.BceClientConfiguration{
Endpoint: endPoint,
Region: bce.DEFAULT_REGION,
UserAgent: bce.DEFAULT_USER_AGENT,
Credentials: credentials,
SignOption: defaultSignOptions,
Retry: bce.DEFAULT_RETRY_POLICY,
ConnectionTimeoutInMillis: bce.DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS}
v1Signer := &auth.BceV1Signer{}
client := &Client{bce.NewBceClient(defaultConf, v1Signer)}
return client, nil
}
// CreateInstance - create an instance with the specific parameters
//
// PARAMS:
// - args: the arguments to create instance
// RETURNS:
// - *api.CreateInstanceResult: the result of create Instance, contains new Instance ID
// - error: nil if success otherwise the specific error
func (c *Client) CreateInstance(args *api.CreateInstanceArgs) (*api.CreateInstanceResult, error) {
if len(args.AdminPass) > 0 {
cryptedPass, err := api.Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass)
if err != nil {
return nil, err
}
args.AdminPass = cryptedPass
}
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return nil, jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return nil, err
}
return api.CreateInstance(c, args.ClientToken, body)
}
// ListInstances - list all instance with the specific parameters
//
// PARAMS:
// - args: the arguments to list all instance
// RETURNS:
// - *api.ListInstanceResult: the result of list Instance
// - error: nil if success otherwise the specific error
func (c *Client) ListInstances(args *api.ListInstanceArgs) (*api.ListInstanceResult, error) {
return api.ListInstances(c, args)
}
// GetInstanceDetail - get a specific instance detail info
//
// PARAMS:
// - instanceId: the specific instance ID
// RETURNS:
// - *api.GetInstanceDetailResult: the result of get instance detail info
// - error: nil if success otherwise the specific error
func (c *Client) GetInstanceDetail(instanceId string) (*api.GetInstanceDetailResult, error) {
return api.GetInstanceDetail(c, instanceId)
}
// DeleteInstance - delete a specific instance
//
// PARAMS:
// - instanceId: the specific instance ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteInstance(instanceId string) error {
return api.DeleteInstance(c, instanceId)
}
// ResizeInstance - resize a specific instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments to resize a specific instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ResizeInstance(instanceId string, args *api.ResizeInstanceArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.ResizeInstance(c, instanceId, args.ClientToken, body)
}
// RebuildInstance - rebuild an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments to rebuild an instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RebuildInstance(instanceId string, args *api.RebuildInstanceArgs) error {
cryptedPass, err := api.Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass)
if err != nil {
return err
}
args.AdminPass = cryptedPass
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.RebuildInstance(c, instanceId, body)
}
// StartInstance - start an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) StartInstance(instanceId string) error {
return api.StartInstance(c, instanceId)
}
// StopInstance - stop an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - forceStop: choose to force stop an instance or not
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) StopInstance(instanceId string, forceStop bool) error {
args := &api.StopInstanceArgs{
ForceStop: forceStop,
}
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.StopInstance(c, instanceId, body)
}
// RebootInstance - restart an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - forceStop: choose to force stop an instance or not
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RebootInstance(instanceId string, forceStop bool) error {
args := &api.StopInstanceArgs{
ForceStop: forceStop,
}
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.RebootInstance(c, instanceId, body)
}
// ChangeInstancePass - change an instance's password
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments to change password
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ChangeInstancePass(instanceId string, args *api.ChangeInstancePassArgs) error {
cryptedPass, err := api.Aes128EncryptUseSecreteKey(c.Config.Credentials.SecretAccessKey, args.AdminPass)
if err != nil {
return err
}
args.AdminPass = cryptedPass
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.ChangeInstancePass(c, instanceId, body)
}
// ModifyInstanceAttribute - modify an instance's attribute
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments of now instance's attribute
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyInstanceAttribute(instanceId string, args *api.ModifyInstanceAttributeArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.ModifyInstanceAttribute(c, instanceId, body)
}
// ModifyInstanceDesc - modify an instance's description
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments of now instance's description
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyInstanceDesc(instanceId string, args *api.ModifyInstanceDescArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.ModifyInstanceDesc(c, instanceId, body)
}
// BindSecurityGroup - bind a security group to an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - securityGroupId: the security group ID which need to bind
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) BindSecurityGroup(instanceId string, securityGroupId string) error {
args := &api.BindSecurityGroupArgs{
SecurityGroupId: securityGroupId,
}
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.BindSecurityGroup(c, instanceId, body)
}
// UnBindSecurityGroup - unbind a security group ID from instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - securityGroupId: the security group ID which need to unbind
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UnBindSecurityGroup(instanceId string, securityGroupId string) error {
args := &api.BindSecurityGroupArgs{
SecurityGroupId: securityGroupId,
}
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.UnBindSecurityGroup(c, instanceId, body)
}
// GetInstanceVNC - get an instance's VNC url
//
// PARAMS:
// - instanceId: the specific instance ID
// RETURNS:
// - *api.GetInstanceVNCResult: the result of get instance's VNC url
// - error: nil if success otherwise the specific error
func (c *Client) GetInstanceVNC(instanceId string) (*api.GetInstanceVNCResult, error) {
return api.GetInstanceVNC(c, instanceId)
}
// InstancePurchaseReserved - purchase reserve an instance
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments to purchase reserved an instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) InstancePurchaseReserved(instanceId string, args *api.PurchaseReservedArgs) error {
// this api only support Prepaid instance
args.Billing.PaymentTiming = api.PaymentTimingPrePaid
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.InstancePurchaseReserved(c, instanceId, args.ClientToken, body)
}
// DeleteInstanceWithRelateResource - delete an instance and all eip/cds relate it
//
// PARAMS:
// - instanceId: the specific instance ID
// - args: the arguments to delete instance and its relate resource
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteInstanceWithRelateResource(instanceId string, args *api.DeleteInstanceWithRelateResourceArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.DeleteInstanceWithRelatedResource(c, instanceId, body)
}
// InstanceChangeSubnet - change an instance's subnet
//
// PARAMS:
// - args: the arguments to change an instance's subnet
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) InstanceChangeSubnet(args *api.InstanceChangeSubnetArgs) error {
jsonBytes, jsonErr := json.Marshal(args)
if jsonErr != nil {
return jsonErr
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return err
}
return api.InstanceChangeSubnet(c, body)
}
//cds sdk
// CreateCDSVolume - create a CDS volume
//
// PARAMS:
// - args: the arguments to create CDS
// RETURNS:
// - *api.CreateCDSVolumeResult: the result of create CDS volume, contains new volume ID
// - error: nil if success otherwise the specific error
func (c *Client) CreateCDSVolume(args *api.CreateCDSVolumeArgs) (*api.CreateCDSVolumeResult, error) {
return api.CreateCDSVolume(c, args)
}
// ListCDSVolume - list all cds volume with the specific parameters
//
// PARAMS:
// - args: the arguments to list all cds
// RETURNS:
// - *api.ListCDSVolumeResult: the result of list all CDS volume
// - error: nil if success otherwise the specific error
func (c *Client) ListCDSVolume(queryArgs *api.ListCDSVolumeArgs) (*api.ListCDSVolumeResult, error) {
return api.ListCDSVolume(c, queryArgs)
}
// GetCDSVolumeDetail - get a CDS volume's detail info
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// RETURNS:
// - *api.GetVolumeDetailResult: the result of get a specific CDS volume's info
// - error: nil if success otherwise the specific error
func (c *Client) GetCDSVolumeDetail(volumeId string) (*api.GetVolumeDetailResult, error) {
return api.GetCDSVolumeDetail(c, volumeId)
}
// AttachCDSVolume - attach a CDS volume to an instance
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to attach a CDS volume
// RETURNS:
// - *api.AttachVolumeResult: the result of attach a CDS volume
// - error: nil if success otherwise the specific error
func (c *Client) AttachCDSVolume(volumeId string, args *api.AttachVolumeArgs) (*api.AttachVolumeResult, error) {
return api.AttachCDSVolume(c, volumeId, args)
}
// DetachCDSVolume - detach a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to detach a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DetachCDSVolume(volumeId string, args *api.DetachVolumeArgs) error {
return api.DetachCDSVolume(c, volumeId, args)
}
// DeleteCDSVolume - delete a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteCDSVolume(volumeId string) error {
return api.DeleteCDSVolume(c, volumeId)
}
// DeleteCDSVolumeNew - delete a CDS volume and snapshot
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to delete a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteCDSVolumeNew(volumeId string, args *api.DeleteCDSVolumeArgs) error {
return api.DeleteCDSVolumeNew(c, volumeId, args)
}
// ResizeCDSVolume - resize a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to resize CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ResizeCDSVolume(volumeId string, args *api.ResizeCSDVolumeArgs) error {
return api.ResizeCDSVolume(c, volumeId, args)
}
// RollbackCDSVolume - rollback a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to rollback a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RollbackCDSVolume(volumeId string, args *api.RollbackCSDVolumeArgs) error {
return api.RollbackCDSVolume(c, volumeId, args)
}
// PurchaseReservedCDSVolume - purchase reserve a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to purchase reserve a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) PurchaseReservedCDSVolume(volumeId string, args *api.PurchaseReservedCSDVolumeArgs) error {
return api.PurchaseReservedCDSVolume(c, volumeId, args)
}
// RenameCDSVolume - rename a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to rename a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RenameCDSVolume(volumeId string, args *api.RenameCSDVolumeArgs) error {
return api.RenameCDSVolume(c, volumeId, args)
}
// ModifyCDSVolume - modify a CDS volume
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to modify a CDS volume
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyCDSVolume(volumeId string, args *api.ModifyCSDVolumeArgs) error {
return api.ModifyCDSVolume(c, volumeId, args)
}
// ModifyChargeTypeCDSVolume - modify a CDS volume's charge type
//
// PARAMS:
// - volumeId: the specific CDS volume ID
// - args: the arguments to create instance
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ModifyChargeTypeCDSVolume(volumeId string, args *api.ModifyChargeTypeCSDVolumeArgs) error {
return api.ModifyChargeTypeCDSVolume(c, volumeId, args)
}
//securityGroup sdk
// CreateSecurityGroup - create a security group
//
// PARAMS:
// - args: the arguments to create security group
// RETURNS:
// - *api.CreateSecurityGroupResult: the result of create security group
// - error: nil if success otherwise the specific error
func (c *Client) CreateSecurityGroup(args *api.CreateSecurityGroupArgs) (*api.CreateSecurityGroupResult, error) {
return api.CreateSecurityGroup(c, args)
}
// ListSecurityGroup - list all security group
//
// PARAMS:
// - args: the arguments to list all security group
// RETURNS:
// - *api.ListSecurityGroupResult: the result of create Instance, contains new Instance ID
// - error: nil if success otherwise the specific error
func (c *Client) ListSecurityGroup(queryArgs *api.ListSecurityGroupArgs) (*api.ListSecurityGroupResult, error) {
return api.ListSecurityGroup(c, queryArgs)
}
// AuthorizeSecurityGroupRule - authorize a security group rule
//
// PARAMS:
// - securityGroupId: the specific securityGroup ID
// - args: the arguments to authorize a security group rule
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) AuthorizeSecurityGroupRule(securityGroupId string, args *api.AuthorizeSecurityGroupArgs) error {
return api.AuthorizeSecurityGroupRule(c, securityGroupId, args)
}
// RevokeSecurityGroupRule - revoke a security group rule
//
// PARAMS:
// - securityGroupId: the specific securityGroup ID
// - args: the arguments to revoke security group rule
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RevokeSecurityGroupRule(securityGroupId string, args *api.RevokeSecurityGroupArgs) error {
return api.RevokeSecurityGroupRule(c, securityGroupId, args)
}
// DeleteSecurityGroup - delete a security group
//
// PARAMS:
// - securityGroupId: the specific securityGroup ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteSecurityGroup(securityGroupId string) error {
return api.DeleteSecurityGroup(c, securityGroupId)
}
//image sdk
// CreateImage - create an image
//
// PARAMS:
// - args: the arguments to create image
// RETURNS:
// - *api.CreateImageResult: the result of create Image
// - error: nil if success otherwise the specific error
func (c *Client) CreateImage(args *api.CreateImageArgs) (*api.CreateImageResult, error) {
return api.CreateImage(c, args)
}
// ListImage - list all images
//
// PARAMS:
// - args: the arguments to list all images
// RETURNS:
// - *api.ListImageResult: the result of list all images
// - error: nil if success otherwise the specific error
func (c *Client) ListImage(queryArgs *api.ListImageArgs) (*api.ListImageResult, error) {
return api.ListImage(c, queryArgs)
}
// GetImageDetail - get an image's detail info
//
// PARAMS:
// - imageId: the specific image ID
// RETURNS:
// - *api.GetImageDetailResult: the result of get image's detail
// - error: nil if success otherwise the specific error
func (c *Client) GetImageDetail(imageId string) (*api.GetImageDetailResult, error) {
return api.GetImageDetail(c, imageId)
}
// DeleteImage - delete an image
//
// PARAMS:
// - imageId: the specific image ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteImage(imageId string) error {
return api.DeleteImage(c, imageId)
}
// RemoteCopyImage - copy an image from other region
//
// PARAMS:
// - imageId: the specific image ID
// - args: the arguments to remote copy an image
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) RemoteCopyImage(imageId string, args *api.RemoteCopyImageArgs) error {
return api.RemoteCopyImage(c, imageId, args)
}
// CancelRemoteCopyImage - cancel a copy image from other region operation
//
// PARAMS:
// - imageId: the specific image ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) CancelRemoteCopyImage(imageId string) error {
return api.CancelRemoteCopyImage(c, imageId)
}
// ShareImage - share an image
//
// PARAMS:
// - imageId: the specific image ID
// - args: the arguments to share an image
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) ShareImage(imageId string, args *api.SharedUser) error {
return api.ShareImage(c, imageId, args)
}
// UnShareImage - cancel share an image
//
// PARAMS:
// - imageId: the specific image ID
// - args: the arguments to cancel share an image
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UnShareImage(imageId string, args *api.SharedUser) error {
return api.UnShareImage(c, imageId, args)
}
// GetImageSharedUser - get user list use this image
//
// PARAMS:
// - imageId: the specific image ID
// RETURNS:
// - *api.GetImageSharedUserResult: the result of user list
// - error: nil if success otherwise the specific error
func (c *Client) GetImageSharedUser(imageId string) (*api.GetImageSharedUserResult, error) {
return api.GetImageSharedUser(c, imageId)
}
// GetImageOS - get image OS
//
// PARAMS:
// - args: the arguments to get OS info
// RETURNS:
// - *api.GetImageOsResult: the result of get image OS info
// - error: nil if success otherwise the specific error
func (c *Client) GetImageOS(args *api.GetImageOsArgs) (*api.GetImageOsResult, error) {
return api.GetImageOS(c, args)
}
// CreateSnapshot - create a snapshot
//
// PARAMS:
// - args: the arguments to create a snapshot
// RETURNS:
// - *api.CreateSnapshotResult: the result of create snapshot
// - error: nil if success otherwise the specific error
func (c *Client) CreateSnapshot(args *api.CreateSnapshotArgs) (*api.CreateSnapshotResult, error) {
return api.CreateSnapshot(c, args)
}
// ListSnapshot - list all snapshots
//
// PARAMS:
// - args: the arguments to list all snapshots
// RETURNS:
// - *api.ListSnapshotResult: the result of list all snapshots
// - error: nil if success otherwise the specific error
func (c *Client) ListSnapshot(args *api.ListSnapshotArgs) (*api.ListSnapshotResult, error) {
return api.ListSnapshot(c, args)
}
// GetSnapshotDetail - get a snapshot's detail info
//
// PARAMS:
// - snapshotId: the specific snapshot ID
// RETURNS:
// - *api.GetSnapshotDetailResult: the result of get snapshot's detail info
// - error: nil if success otherwise the specific error
func (c *Client) GetSnapshotDetail(snapshotId string) (*api.GetSnapshotDetailResult, error) {
return api.GetSnapshotDetail(c, snapshotId)
}
// DeleteSnapshot - delete a snapshot
//
// PARAMS:
// - snapshotId: the specific snapshot ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteSnapshot(snapshotId string) error {
return api.DeleteSnapshot(c, snapshotId)
}
// CreateAutoSnapshotPolicy - create an auto snapshot policy
//
// PARAMS:
// - args: the arguments to create an auto snapshot policy
// RETURNS:
// - *api.CreateASPResult: the result of create an auto snapshot policy
// - error: nil if success otherwise the specific error
func (c *Client) CreateAutoSnapshotPolicy(args *api.CreateASPArgs) (*api.CreateASPResult, error) {
return api.CreateAutoSnapshotPolicy(c, args)
}
// AttachAutoSnapshotPolicy - attach an ASP to volumes
//
// PARAMS:
// - aspId: the specific auto snapshot policy ID
// - args: the arguments to attach an ASP
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) AttachAutoSnapshotPolicy(aspId string, args *api.AttachASPArgs) error {
return api.AttachAutoSnapshotPolicy(c, aspId, args)
}
// DetachAutoSnapshotPolicy - detach an ASP
//
// PARAMS:
// - aspId: the specific auto snapshot policy ID
// - args: the arguments to detach an ASP
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DetachAutoSnapshotPolicy(aspId string, args *api.DetachASPArgs) error {
return api.DetachAutoSnapshotPolicy(c, aspId, args)
}
// DeleteAutoSnapshotPolicy - delete an auto snapshot policy
//
// PARAMS:
// - aspId: the specific auto snapshot policy ID
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) DeleteAutoSnapshotPolicy(aspId string) error {
return api.DeleteAutoSnapshotPolicy(c, aspId)
}
// ListAutoSnapshotPolicy - list all auto snapshot policies
//
// PARAMS:
// - args: the arguments to create instance
// RETURNS:
// - *api.ListASPResult: the result of list all auto snapshot policies
// - error: nil if success otherwise the specific error
func (c *Client) ListAutoSnapshotPolicy(args *api.ListASPArgs) (*api.ListASPResult, error) {
return api.ListAutoSnapshotPolicy(c, args)
}
// GetAutoSnapshotPolicy - get an auto snapshot policy's meta
//
// PARAMS:
// - aspId: the specific auto snapshot policy ID
// RETURNS:
// - *api.GetASPDetailResult: the result of get an auto snapshot policy's meta
// - error: nil if success otherwise the specific error
func (c *Client) GetAutoSnapshotPolicy(aspId string) (*api.GetASPDetailResult, error) {
return api.GetAutoSnapshotPolicyDetail(c, aspId)
}
// UpdateAutoSnapshotPolicy - update an auto snapshot policy
//
// PARAMS:
// - args: the arguments to update an auto snapshot policy
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) UpdateAutoSnapshotPolicy(args *api.UpdateASPArgs) error {
return api.UpdateAutoSnapshotPolicy(c, args)
}
// ListSpec - list all spec
//
// RETURNS:
// - *api.ListSpecResult: the result of all spec
// - error: nil if success otherwise the specific error
func (c *Client) ListSpec() (*api.ListSpecResult, error) {
return api.ListSpec(c)
}
// ListZone - list all zones
//
// RETURNS:
// - *api.ListZoneResult: the result of list all zones
// - error: nil if success otherwise the specific error
func (c *Client) ListZone() (*api.ListZoneResult, error) {
return api.ListZone(c)
}