This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
forked from nutanix/terraform-provider-nutanix
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathv3_service.go
1058 lines (840 loc) · 31.3 KB
/
v3_service.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
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package v3
import (
"context"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/terraform-providers/terraform-provider-nutanix/client"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)
// Operations ...
type Operations struct {
client *client.Client
}
// Service ...
type Service interface {
CreateVM(createRequest *VMIntentInput) (*VMIntentResponse, error)
DeleteVM(uuid string) (*DeleteResponse, error)
GetVM(uuid string) (*VMIntentResponse, error)
ListVM(getEntitiesRequest *DSMetadata) (*VMListIntentResponse, error)
UpdateVM(uuid string, body *VMIntentInput) (*VMIntentResponse, error)
CreateSubnet(createRequest *SubnetIntentInput) (*SubnetIntentResponse, error)
DeleteSubnet(uuid string) (*DeleteResponse, error)
GetSubnet(uuid string) (*SubnetIntentResponse, error)
ListSubnet(getEntitiesRequest *DSMetadata) (*SubnetListIntentResponse, error)
UpdateSubnet(uuid string, body *SubnetIntentInput) (*SubnetIntentResponse, error)
CreateImage(createRequest *ImageIntentInput) (*ImageIntentResponse, error)
DeleteImage(uuid string) (*DeleteResponse, error)
GetImage(uuid string) (*ImageIntentResponse, error)
ListImage(getEntitiesRequest *DSMetadata) (*ImageListIntentResponse, error)
UpdateImage(uuid string, body *ImageIntentInput) (*ImageIntentResponse, error)
UploadImage(uuid, filepath string) error
CreateOrUpdateCategoryKey(body *CategoryKey) (*CategoryKeyStatus, error)
ListCategories(getEntitiesRequest *CategoryListMetadata) (*CategoryKeyListResponse, error)
DeleteCategoryKey(name string) error
GetCategoryKey(name string) (*CategoryKeyStatus, error)
ListCategoryValues(name string, getEntitiesRequest *CategoryListMetadata) (*CategoryValueListResponse, error)
CreateOrUpdateCategoryValue(name string, body *CategoryValue) (*CategoryValueStatus, error)
GetCategoryValue(name string, value string) (*CategoryValueStatus, error)
DeleteCategoryValue(name string, value string) error
GetCategoryQuery(query *CategoryQueryInput) (*CategoryQueryResponse, error)
UpdateNetworkSecurityRule(uuid string, body *NetworkSecurityRuleIntentInput) (*NetworkSecurityRuleIntentResponse, error)
ListNetworkSecurityRule(getEntitiesRequest *DSMetadata) (*NetworkSecurityRuleListIntentResponse, error)
GetNetworkSecurityRule(uuid string) (*NetworkSecurityRuleIntentResponse, error)
DeleteNetworkSecurityRule(uuid string) (*DeleteResponse, error)
CreateNetworkSecurityRule(request *NetworkSecurityRuleIntentInput) (*NetworkSecurityRuleIntentResponse, error)
ListCluster(getEntitiesRequest *DSMetadata) (*ClusterListIntentResponse, error)
GetCluster(uuid string) (*ClusterIntentResponse, error)
UpdateVolumeGroup(uuid string, body *VolumeGroupInput) (*VolumeGroupResponse, error)
ListVolumeGroup(getEntitiesRequest *DSMetadata) (*VolumeGroupListResponse, error)
GetVolumeGroup(uuid string) (*VolumeGroupResponse, error)
DeleteVolumeGroup(uuid string) error
CreateVolumeGroup(request *VolumeGroupInput) (*VolumeGroupResponse, error)
ListAllVM() (*VMListIntentResponse, error)
ListAllSubnet() (*SubnetListIntentResponse, error)
ListAllNetworkSecurityRule() (*NetworkSecurityRuleListIntentResponse, error)
ListAllImage() (*ImageListIntentResponse, error)
ListAllCluster() (*ClusterListIntentResponse, error)
GetTask(taskUUID string) (*TasksResponse, error)
}
/*CreateVM Creates a VM
* This operation submits a request to create a VM based on the input parameters.
*
* @param body
* @return *VMIntentResponse
*/
func (op Operations) CreateVM(createRequest *VMIntentInput) (*VMIntentResponse, error) {
ctx := context.TODO()
req, err := op.client.NewRequest(ctx, http.MethodPost, "/vms", createRequest)
vmIntentResponse := new(VMIntentResponse)
if err != nil {
return nil, err
}
return vmIntentResponse, op.client.Do(ctx, req, vmIntentResponse)
}
/*DeleteVM Deletes a VM
* This operation submits a request to delete a op.
*
* @param uuid The uuid of the entity.
* @return error
*/
func (op Operations) DeleteVM(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/vms/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)
if err != nil {
return nil, err
}
return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}
/*GetVM Gets a VM
* This operation gets a op.
*
* @param uuid The uuid of the entity.
* @return *VMIntentResponse
*/
func (op Operations) GetVM(uuid string) (*VMIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/vms/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
vmIntentResponse := new(VMIntentResponse)
if err != nil {
return nil, err
}
return vmIntentResponse, op.client.Do(ctx, req, vmIntentResponse)
}
/*ListVM Get a list of VMs This operation gets a list of VMs, allowing for sorting and pagination. Note: Entities that have not been created
* successfully are not listed.
*
* @param getEntitiesRequest @return *VmListIntentResponse
*/
func (op Operations) ListVM(getEntitiesRequest *DSMetadata) (*VMListIntentResponse, error) {
ctx := context.TODO()
path := "/vms/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
vmListIntentResponse := new(VMListIntentResponse)
if err != nil {
return nil, err
}
return vmListIntentResponse, op.client.Do(ctx, req, vmListIntentResponse)
}
/*UpdateVM Updates a VM
* This operation submits a request to update a VM based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return *VMIntentResponse
*/
func (op Operations) UpdateVM(uuid string, body *VMIntentInput) (*VMIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/vms/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
vmIntentResponse := new(VMIntentResponse)
if err != nil {
return nil, err
}
return vmIntentResponse, op.client.Do(ctx, req, vmIntentResponse)
}
/*CreateSubnet Creates a subnet
* This operation submits a request to create a subnet based on the input parameters. A subnet is a block of IP addresses.
*
* @param body
* @return *SubnetIntentResponse
*/
func (op Operations) CreateSubnet(createRequest *SubnetIntentInput) (*SubnetIntentResponse, error) {
ctx := context.TODO()
req, err := op.client.NewRequest(ctx, http.MethodPost, "/subnets", createRequest)
subnetIntentResponse := new(SubnetIntentResponse)
if err != nil {
return nil, err
}
return subnetIntentResponse, op.client.Do(ctx, req, subnetIntentResponse)
}
/*DeleteSubnet Deletes a subnet
* This operation submits a request to delete a subnet.
*
* @param uuid The uuid of the entity.
* @return error if exist error
*/
func (op Operations) DeleteSubnet(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/subnets/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)
if err != nil {
return nil, err
}
return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}
/*GetSubnet Gets a subnet entity
* This operation gets a subnet.
*
* @param uuid The uuid of the entity.
* @return *SubnetIntentResponse
*/
func (op Operations) GetSubnet(uuid string) (*SubnetIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/subnets/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
subnetIntentResponse := new(SubnetIntentResponse)
if err != nil {
return nil, err
}
// Recheck subnet already exist error
// if *subnetIntentResponse.Status.State == "ERROR" {
// pretty, _ := json.MarshalIndent(subnetIntentResponse.Status.MessageList, "", " ")
// return nil, fmt.Errorf("error: %s", string(pretty))
// }
return subnetIntentResponse, op.client.Do(ctx, req, subnetIntentResponse)
}
/*ListSubnet Gets a list of subnets This operation gets a list of subnets, allowing for sorting and pagination. Note: Entities that have not
* been created successfully are not listed.
*
* @param getEntitiesRequest @return *SubnetListIntentResponse
*/
func (op Operations) ListSubnet(getEntitiesRequest *DSMetadata) (*SubnetListIntentResponse, error) {
ctx := context.TODO()
path := "/subnets/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
subnetListIntentResponse := new(SubnetListIntentResponse)
if err != nil {
return nil, err
}
return subnetListIntentResponse, op.client.Do(ctx, req, subnetListIntentResponse)
}
/*UpdateSubnet Updates a subnet
* This operation submits a request to update a subnet based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return *SubnetIntentResponse
*/
func (op Operations) UpdateSubnet(uuid string, body *SubnetIntentInput) (*SubnetIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/subnets/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
subnetIntentResponse := new(SubnetIntentResponse)
if err != nil {
return nil, err
}
return subnetIntentResponse, op.client.Do(ctx, req, subnetIntentResponse)
}
/*CreateImage Creates a IMAGE Images are raw ISO, QCOW2, or VMDK files that are uploaded by a user can be attached to a op. An ISO image is
* attached as a virtual CD-ROM drive, and QCOW2 and VMDK files are attached as SCSI disks. An image has to be explicitly added to the
* self-service catalog before users can create VMs from it.
*
* @param body @return *ImageIntentResponse
*/
func (op Operations) CreateImage(body *ImageIntentInput) (*ImageIntentResponse, error) {
ctx := context.TODO()
req, err := op.client.NewRequest(ctx, http.MethodPost, "/images", body)
imageIntentResponse := new(ImageIntentResponse)
if err != nil {
return nil, err
}
return imageIntentResponse, op.client.Do(ctx, req, imageIntentResponse)
}
/*UploadImage Uplloads a Image Binary file Images are raw ISO, QCOW2, or VMDK files that are uploaded by a user can be attached to a op. An
* ISO image is attached as a virtual CD-ROM drive, and QCOW2 and VMDK files are attached as SCSI disks. An image has to be explicitly added
* to the self-service catalog before users can create VMs from it.
*
* @param uuid @param filepath
*/
func (op Operations) UploadImage(uuid, filepath string) error {
ctx := context.Background()
path := fmt.Sprintf("/images/%s/file", uuid)
file, err := os.Open(filepath)
if err != nil {
return fmt.Errorf("error: cannot open file: %s", err)
}
defer file.Close()
fileContents, err := ioutil.ReadAll(file)
if err != nil {
return fmt.Errorf("error: Cannot read file %s", err)
}
req, err := op.client.NewUploadRequest(ctx, http.MethodPut, path, fileContents)
if err != nil {
return fmt.Errorf("error: Creating request %s", err)
}
err = op.client.Do(ctx, req, nil)
return err
}
/*DeleteImage deletes a IMAGE
* This operation submits a request to delete a IMAGE.
*
* @param uuid The uuid of the entity.
* @return error if error exists
*/
func (op Operations) DeleteImage(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/images/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)
if err != nil {
return nil, err
}
return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}
/*GetImage gets a IMAGE
* This operation gets a IMAGE.
*
* @param uuid The uuid of the entity.
* @return *ImageIntentResponse
*/
func (op Operations) GetImage(uuid string) (*ImageIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/images/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
imageIntentResponse := new(ImageIntentResponse)
if err != nil {
return nil, err
}
return imageIntentResponse, op.client.Do(ctx, req, imageIntentResponse)
}
/*ListImage gets a list of IMAGEs This operation gets a list of IMAGEs, allowing for sorting and pagination. Note: Entities that have not
* been created successfully are not listed.
*
* @param getEntitiesRequest @return *ImageListIntentResponse
*/
func (op Operations) ListImage(getEntitiesRequest *DSMetadata) (*ImageListIntentResponse, error) {
ctx := context.TODO()
path := "/images/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
imageListIntentResponse := new(ImageListIntentResponse)
if err != nil {
return nil, err
}
return imageListIntentResponse, op.client.Do(ctx, req, imageListIntentResponse)
}
/*UpdateImage updates a IMAGE
* This operation submits a request to update a IMAGE based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return *ImageIntentResponse
*/
func (op Operations) UpdateImage(uuid string, body *ImageIntentInput) (*ImageIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/images/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
imageIntentResponse := new(ImageIntentResponse)
if err != nil {
return nil, err
}
return imageIntentResponse, op.client.Do(ctx, req, imageIntentResponse)
}
/*GetCluster gets a CLUSTER
* This operation gets a CLUSTER.
*
* @param uuid The uuid of the entity.
* @return *ImageIntentResponse
*/
func (op Operations) GetCluster(uuid string) (*ClusterIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/clusters/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
clusterIntentResponse := new(ClusterIntentResponse)
if err != nil {
return nil, err
}
return clusterIntentResponse, op.client.Do(ctx, req, clusterIntentResponse)
}
/*ListCluster gets a list of CLUSTERS This operation gets a list of CLUSTERS, allowing for sorting and pagination. Note: Entities that have
* not been created successfully are not listed.
*
* @param getEntitiesRequest @return *ClusterListIntentResponse
*/
func (op Operations) ListCluster(getEntitiesRequest *DSMetadata) (*ClusterListIntentResponse, error) {
ctx := context.TODO()
path := "/clusters/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
clusterList := new(ClusterListIntentResponse)
if err != nil {
return nil, err
}
return clusterList, op.client.Do(ctx, req, clusterList)
}
/*UpdateImage updates a CLUSTER
* This operation submits a request to update a CLUSTER based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return *ImageIntentResponse
*/
// func (op Operations) UpdateImage(uuid string, body *ImageIntentInput) (*ImageIntentResponse, error) {
// ctx := context.TODO()
// path := fmt.Sprintf("/images/%s", uuid)
// req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
// if err != nil {
// return nil, err
// }
// imageIntentResponse := new(ImageIntentResponse)
// err = op.client.Do(ctx, req, imageIntentResponse)
// if err != nil {
// return nil, err
// }
// return imageIntentResponse, nil
// }
// CreateOrUpdateCategoryKey ...
func (op Operations) CreateOrUpdateCategoryKey(body *CategoryKey) (*CategoryKeyStatus, error) {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s", utils.StringValue(body.Name))
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
categoryKeyResponse := new(CategoryKeyStatus)
if err != nil {
return nil, err
}
return categoryKeyResponse, op.client.Do(ctx, req, categoryKeyResponse)
}
/*ListCategories gets a list of Categories This operation gets a list of Categories, allowing for sorting and pagination. Note: Entities
* that have not been created successfully are not listed.
*
* @param getEntitiesRequest @return *ImageListIntentResponse
*/
func (op Operations) ListCategories(getEntitiesRequest *CategoryListMetadata) (*CategoryKeyListResponse, error) {
ctx := context.TODO()
path := "/categories/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
categoryKeyListResponse := new(CategoryKeyListResponse)
if err != nil {
return nil, err
}
return categoryKeyListResponse, op.client.Do(ctx, req, categoryKeyListResponse)
}
/*DeleteCategoryKey Deletes a Category
* This operation submits a request to delete a op.
*
* @param name The name of the entity.
* @return error
*/
func (op Operations) DeleteCategoryKey(name string) error {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s", name)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil {
return err
}
return op.client.Do(ctx, req, nil)
}
/*GetCategoryKey gets a Category
* This operation gets a Category.
*
* @param name The name of the entity.
* @return *CategoryKeyStatus
*/
func (op Operations) GetCategoryKey(name string) (*CategoryKeyStatus, error) {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s", name)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
categoryKeyStatusResponse := new(CategoryKeyStatus)
if err != nil {
return nil, err
}
return categoryKeyStatusResponse, op.client.Do(ctx, req, categoryKeyStatusResponse)
}
/*ListCategoryValues gets a list of Category values for a specific key This operation gets a list of Categories, allowing for sorting and
* pagination. Note: Entities that have not been created successfully are not listed.
*
* @param name @param getEntitiesRequest @return *CategoryValueListResponse
*/
func (op Operations) ListCategoryValues(name string, getEntitiesRequest *CategoryListMetadata) (*CategoryValueListResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s/list", name)
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
categoryValueListResponse := new(CategoryValueListResponse)
if err != nil {
return nil, err
}
return categoryValueListResponse, op.client.Do(ctx, req, categoryValueListResponse)
}
// CreateOrUpdateCategoryValue ...
func (op Operations) CreateOrUpdateCategoryValue(name string, body *CategoryValue) (*CategoryValueStatus, error) {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s/%s", name, utils.StringValue(body.Value))
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
categoryValueResponse := new(CategoryValueStatus)
if err != nil {
return nil, err
}
return categoryValueResponse, op.client.Do(ctx, req, categoryValueResponse)
}
/*GetCategoryValue gets a Category Value
* This operation gets a Category Value.
*
* @param name The name of the entity.
* @params value the value of entity that belongs to category key
* @return *CategoryValueStatus
*/
func (op Operations) GetCategoryValue(name string, value string) (*CategoryValueStatus, error) {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s/%s", name, value)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
categoryValueStatusResponse := new(CategoryValueStatus)
if err != nil {
return nil, err
}
return categoryValueStatusResponse, op.client.Do(ctx, req, categoryValueStatusResponse)
}
/*DeleteCategoryValue Deletes a Category Value
* This operation submits a request to delete a op.
*
* @param name The name of the entity.
* @params value the value of entity that belongs to category key
* @return error
*/
func (op Operations) DeleteCategoryValue(name string, value string) error {
ctx := context.TODO()
path := fmt.Sprintf("/categories/%s/%s", name, value)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil {
return err
}
return op.client.Do(ctx, req, nil)
}
/*GetCategoryQuery gets list of entities attached to categories or policies in which categories are used as defined by the filter criteria.
*
* @param query Categories query input object.
* @return *CategoryQueryResponse
*/
func (op Operations) GetCategoryQuery(query *CategoryQueryInput) (*CategoryQueryResponse, error) {
ctx := context.TODO()
path := "/categories/query"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, query)
categoryQueryResponse := new(CategoryQueryResponse)
if err != nil {
return nil, err
}
return categoryQueryResponse, op.client.Do(ctx, req, categoryQueryResponse)
}
/*CreateNetworkSecurityRule Creates a Network security rule
* This operation submits a request to create a Network security rule based on the input parameters.
*
* @param request
* @return *NetworkSecurityRuleIntentResponse
*/
func (op Operations) CreateNetworkSecurityRule(request *NetworkSecurityRuleIntentInput) (*NetworkSecurityRuleIntentResponse, error) {
ctx := context.TODO()
networkSecurityRuleIntentResponse := new(NetworkSecurityRuleIntentResponse)
req, err := op.client.NewRequest(ctx, http.MethodPost, "/network_security_rules", request)
if err != nil {
return nil, err
}
return networkSecurityRuleIntentResponse, op.client.Do(ctx, req, networkSecurityRuleIntentResponse)
}
/*DeleteNetworkSecurityRule Deletes a Network security rule
* This operation submits a request to delete a Network security rule.
*
* @param uuid The uuid of the entity.
* @return void
*/
func (op Operations) DeleteNetworkSecurityRule(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/network_security_rules/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)
if err != nil {
return nil, err
}
return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}
/*GetNetworkSecurityRule Gets a Network security rule
* This operation gets a Network security rule.
*
* @param uuid The uuid of the entity.
* @return *NetworkSecurityRuleIntentResponse
*/
func (op Operations) GetNetworkSecurityRule(uuid string) (*NetworkSecurityRuleIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/network_security_rules/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
networkSecurityRuleIntentResponse := new(NetworkSecurityRuleIntentResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleIntentResponse, op.client.Do(ctx, req, networkSecurityRuleIntentResponse)
}
/*ListNetworkSecurityRule Gets all network security rules This operation gets a list of Network security rules, allowing for sorting and
* pagination. Note: Entities that have not been created successfully are not listed.
*
* @param getEntitiesRequest @return *NetworkSecurityRuleListIntentResponse
*/
func (op Operations) ListNetworkSecurityRule(getEntitiesRequest *DSMetadata) (*NetworkSecurityRuleListIntentResponse, error) {
ctx := context.TODO()
path := "/network_security_rules/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
networkSecurityRuleListIntentResponse := new(NetworkSecurityRuleListIntentResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleListIntentResponse, op.client.Do(ctx, req, networkSecurityRuleListIntentResponse)
}
/*UpdateNetworkSecurityRule Updates a Network security rule
* This operation submits a request to update a Network security rule based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return void
*/
func (op Operations) UpdateNetworkSecurityRule(
uuid string,
body *NetworkSecurityRuleIntentInput) (*NetworkSecurityRuleIntentResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/network_security_rules/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
networkSecurityRuleIntentResponse := new(NetworkSecurityRuleIntentResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleIntentResponse, op.client.Do(ctx, req, networkSecurityRuleIntentResponse)
}
/*CreateVolumeGroup Creates a Volume group
* This operation submits a request to create a Volume group based on the input parameters.
*
* @param request
* @return *VolumeGroupResponse
*/
func (op Operations) CreateVolumeGroup(request *VolumeGroupInput) (*VolumeGroupResponse, error) {
ctx := context.TODO()
req, err := op.client.NewRequest(ctx, http.MethodPost, "/volume_groups", request)
networkSecurityRuleResponse := new(VolumeGroupResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleResponse, op.client.Do(ctx, req, networkSecurityRuleResponse)
}
/*DeleteVolumeGroup Deletes a Volume group
* This operation submits a request to delete a Volume group.
*
* @param uuid The uuid of the entity.
* @return void
*/
func (op Operations) DeleteVolumeGroup(uuid string) error {
ctx := context.TODO()
path := fmt.Sprintf("/volume_groups/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil {
return err
}
return op.client.Do(ctx, req, nil)
}
/*GetVolumeGroup Gets a Volume group
* This operation gets a Volume group.
*
* @param uuid The uuid of the entity.
* @return *VolumeGroupResponse
*/
func (op Operations) GetVolumeGroup(uuid string) (*VolumeGroupResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/volume_groups/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
networkSecurityRuleResponse := new(VolumeGroupResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleResponse, op.client.Do(ctx, req, networkSecurityRuleResponse)
}
/*ListVolumeGroup Gets all network security rules This operation gets a list of Volume groups, allowing for sorting and pagination. Note:
* Entities that have not been created successfully are not listed.
*
* @param getEntitiesRequest @return *VolumeGroupListResponse
*/
func (op Operations) ListVolumeGroup(getEntitiesRequest *DSMetadata) (*VolumeGroupListResponse, error) {
ctx := context.TODO()
path := "/volume_groups/list"
req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
networkSecurityRuleListResponse := new(VolumeGroupListResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleListResponse, op.client.Do(ctx, req, networkSecurityRuleListResponse)
}
/*UpdateVolumeGroup Updates a Volume group
* This operation submits a request to update a Volume group based on the input parameters.
*
* @param uuid The uuid of the entity.
* @param body
* @return void
*/
func (op Operations) UpdateVolumeGroup(uuid string, body *VolumeGroupInput) (*VolumeGroupResponse, error) {
ctx := context.TODO()
path := fmt.Sprintf("/volume_groups/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
networkSecurityRuleResponse := new(VolumeGroupResponse)
if err != nil {
return nil, err
}
return networkSecurityRuleResponse, op.client.Do(ctx, req, networkSecurityRuleResponse)
}
const itemsPerPage = int64(100)
func hasNext(ri *int64) bool {
*ri -= itemsPerPage
return *ri >= (0 - itemsPerPage)
}
// ListAllVM ...
func (op Operations) ListAllVM() (*VMListIntentResponse, error) {
entities := make([]*VMIntentResource, 0)
resp, err := op.ListVM(&DSMetadata{
Kind: utils.StringPtr("vm"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}
totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)
if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListVM(&DSMetadata{
Kind: utils.StringPtr("vm"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})
if err != nil {
return nil, err
}
entities = append(entities, resp.Entities...)
offset += itemsPerPage
}
resp.Entities = entities
}
return resp, nil
}
// ListAllSubnet ...
func (op Operations) ListAllSubnet() (*SubnetListIntentResponse, error) {
entities := make([]*SubnetIntentResponse, 0)
resp, err := op.ListSubnet(&DSMetadata{
Kind: utils.StringPtr("subnet"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}
totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)
if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListSubnet(&DSMetadata{
Kind: utils.StringPtr("subnet"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})
if err != nil {
return nil, err
}
entities = append(entities, resp.Entities...)
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}
resp.Entities = entities
}
return resp, nil
}
// ListAllNetworkSecurityRule ...
func (op Operations) ListAllNetworkSecurityRule() (*NetworkSecurityRuleListIntentResponse, error) {
entities := make([]*NetworkSecurityRuleIntentResource, 0)
resp, err := op.ListNetworkSecurityRule(&DSMetadata{
Kind: utils.StringPtr("network_security_rule"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}
totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)
if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListNetworkSecurityRule(&DSMetadata{
Kind: utils.StringPtr("network_security_rule"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})
if err != nil {
return nil, err
}
entities = append(entities, resp.Entities...)
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}
resp.Entities = entities
}
return resp, nil
}
// ListAllImage ...
func (op Operations) ListAllImage() (*ImageListIntentResponse, error) {
entities := make([]*ImageIntentResponse, 0)
resp, err := op.ListImage(&DSMetadata{
Kind: utils.StringPtr("image"),
Length: utils.Int64Ptr(itemsPerPage),
})
if err != nil {
return nil, err
}
totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)
if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListImage(&DSMetadata{
Kind: utils.StringPtr("image"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})
if err != nil {
return nil, err
}
entities = append(entities, resp.Entities...)
offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}
resp.Entities = entities
}