-
Notifications
You must be signed in to change notification settings - Fork 2
/
ccm.go
1399 lines (1129 loc) · 37.9 KB
/
ccm.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
// gRPC Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2020.09.
package api
import (
"encoding/json"
"errors"
"io"
"time"
gc "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/common"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/config"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/logger"
pb "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/stub/cbspider"
"github.com/cloud-barista/poc-cicd-spider/interface/api/request"
"google.golang.org/grpc"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// CCMApi - CCM API 구조 정의
type CCMApi struct {
gConf *config.GrpcConfig
conn *grpc.ClientConn
jaegerCloser io.Closer
clientCCM pb.CCMClient
clientSSH pb.SSHClient
requestCCM *request.CCMRequest
requestSSH *request.SSHRequest
inType string
outType string
}
// ImageReq - Image 정보 생성 요청 구조 정의
type ImageReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
ReqInfo ImageInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
// ImageInfo - Image 정보 구조 정의
type ImageInfo struct {
Name string `yaml:"Name" json:"Name"`
}
// VPCReq - VPC 정보 생성 요청 구조 정의
type VPCReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
ReqInfo VPCInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
// VPCInfo - VPC 정보 구조 정의
type VPCInfo struct {
Name string `yaml:"Name" json:"Name"`
IPv4_CIDR string `yaml:"IPv4_CIDR" json:"IPv4_CIDR"`
SubnetInfoList *[]SubnetInfo `yaml:"SubnetInfoList" json:"SubnetInfoList"`
}
// SubnetInfo - Subnet 정보 구조 정의
type SubnetInfo struct {
Name string `yaml:"Name" json:"Name"`
IPv4_CIDR string `yaml:"IPv4_CIDR" json:"IPv4_CIDR"`
}
type SubnetReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
VPCName string `yaml:"VPCName" json:"VPCName"`
ReqInfo SubnetInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
// SecurityReq - Security 정보 생성 요청 구조 정의
type SecurityReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
ReqInfo SecurityInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
// SecurityInfo - Security 정보 구조 정의
type SecurityInfo struct {
Name string `yaml:"Name" json:"Name"`
VPCName string `yaml:"VPCName" json:"VPCName"`
Direction string `yaml:"Direction" json:"Direction"`
SecurityRules *[]SecurityRuleInfo `yaml:"SecurityRules" json:"SecurityRules"`
}
// SecurityRuleInfo - Security Rule 정보 구조 정의
type SecurityRuleInfo struct {
FromPort string `yaml:"FromPort" json:"FromPort"`
ToPort string `yaml:"ToPort" json:"ToPort"`
IPProtocol string `yaml:"IPProtocol" json:"IPProtocol"`
Direction string `yaml:"Direction" json:"Direction"`
CIDR string `yaml:"CIDR" json:"CIDR"`
}
// KeyReq - Key Pair 정보 생성 요청 구조 정의
type KeyReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
ReqInfo KeyInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
// KeyInfo - Key 정보 구조 정의
type KeyInfo struct {
Name string `yaml:"Name" json:"Name"`
}
// VMReq - VM 정보 생성 요청 구조 정의
type VMReq struct {
ConnectionName string `yaml:"ConnectionName" json:"ConnectionName"`
ReqInfo VMInfo `yaml:"ReqInfo" json:"ReqInfo"`
}
//VMInfo - VM 정보 구조 정의
type VMInfo struct {
Name string `yaml:"Name" json:"Name"`
ImageName string `yaml:"ImageName" json:"ImageName"`
VPCName string `yaml:"VPCName" json:"VPCName"`
SubnetName string `yaml:"SubnetName" json:"SubnetName"`
SecurityGroupNames []string `yaml:"SecurityGroupNames" json:"SecurityGroupNames"`
VMSpecName string `yaml:"VMSpecName" json:"VMSpecName"`
KeyPairName string `yaml:"KeyPairName" json:"KeyPairName"`
VMUserId string `yaml:"VMUserId" json:"VMUserId"`
VMUserPasswd string `yaml:"VMUserPasswd" json:"VMUserPasswd"`
}
// SSHRUNReq - SSH 실행 요청 구조 정의
type SSHRUNReq struct {
UserName string `yaml:"UserName" json:"UserName"`
PrivateKey []string `yaml:"PrivateKey" json:"PrivateKey"`
ServerPort string `yaml:"ServerPort" json:"ServerPort"`
Command string `yaml:"Command" json:"Command"`
}
// ===== [ Implementations ] =====
// SetServerAddr - Spider 서버 주소 설정
func (ccm *CCMApi) SetServerAddr(addr string) error {
if addr == "" {
return errors.New("parameter is empty")
}
ccm.gConf.GSL.SpiderCli.ServerAddr = addr
return nil
}
// GetServerAddr - Spider 서버 주소 값 조회
func (ccm *CCMApi) GetServerAddr() (string, error) {
return ccm.gConf.GSL.SpiderCli.ServerAddr, nil
}
// SetTLSCA - TLS CA 설정
func (ccm *CCMApi) SetTLSCA(tlsCAFile string) error {
if tlsCAFile == "" {
return errors.New("parameter is empty")
}
if ccm.gConf.GSL.SpiderCli.TLS == nil {
ccm.gConf.GSL.SpiderCli.TLS = &config.TLSConfig{}
}
ccm.gConf.GSL.SpiderCli.TLS.TLSCA = tlsCAFile
return nil
}
// GetTLSCA - TLS CA 값 조회
func (ccm *CCMApi) GetTLSCA() (string, error) {
if ccm.gConf.GSL.SpiderCli.TLS == nil {
return "", nil
}
return ccm.gConf.GSL.SpiderCli.TLS.TLSCA, nil
}
// SetTimeout - Timeout 설정
func (ccm *CCMApi) SetTimeout(timeout time.Duration) error {
ccm.gConf.GSL.SpiderCli.Timeout = timeout
return nil
}
// GetTimeout - Timeout 값 조회
func (ccm *CCMApi) GetTimeout() (time.Duration, error) {
return ccm.gConf.GSL.SpiderCli.Timeout, nil
}
// SetJWTToken - JWT 인증 토큰 설정
func (ccm *CCMApi) SetJWTToken(token string) error {
if token == "" {
return errors.New("parameter is empty")
}
if ccm.gConf.GSL.SpiderCli.Interceptors == nil {
ccm.gConf.GSL.SpiderCli.Interceptors = &config.InterceptorsConfig{}
ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT = &config.AuthJWTConfig{}
}
if ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT == nil {
ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT = &config.AuthJWTConfig{}
}
ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT.JWTToken = token
return nil
}
// GetJWTToken - JWT 인증 토큰 값 조회
func (ccm *CCMApi) GetJWTToken() (string, error) {
if ccm.gConf.GSL.SpiderCli.Interceptors == nil {
return "", nil
}
if ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT == nil {
return "", nil
}
return ccm.gConf.GSL.SpiderCli.Interceptors.AuthJWT.JWTToken, nil
}
// SetConfigPath - 환경설정 파일 설정
func (ccm *CCMApi) SetConfigPath(configFile string) error {
logger := logger.NewLogger()
// Viper 를 사용하는 설정 파서 생성
parser := config.MakeParser()
var (
gConf config.GrpcConfig
err error
)
if configFile == "" {
logger.Error("Please, provide the path to your configuration file")
return errors.New("configuration file are not specified")
}
logger.Debug("Parsing configuration file: ", configFile)
if gConf, err = parser.GrpcParse(configFile); err != nil {
logger.Error("ERROR - Parsing the configuration file.\n", err.Error())
return err
}
// SPIDER CLIENT 필수 입력 항목 체크
spidercli := gConf.GSL.SpiderCli
if spidercli == nil {
return errors.New("spidercli field are not specified")
}
if spidercli.ServerAddr == "" {
return errors.New("spidercli.server_addr field are not specified")
}
if spidercli.Timeout == 0 {
spidercli.Timeout = 90 * time.Second
}
if spidercli.TLS != nil {
if spidercli.TLS.TLSCA == "" {
return errors.New("spidercli.tls.tls_ca field are not specified")
}
}
if spidercli.Interceptors != nil {
if spidercli.Interceptors.AuthJWT != nil {
if spidercli.Interceptors.AuthJWT.JWTToken == "" {
return errors.New("spidercli.interceptors.auth_jwt.jwt_token field are not specified")
}
}
if spidercli.Interceptors.Opentracing != nil {
if spidercli.Interceptors.Opentracing.Jaeger != nil {
if spidercli.Interceptors.Opentracing.Jaeger.Endpoint == "" {
return errors.New("spidercli.interceptors.opentracing.jaeger.endpoint field are not specified")
}
}
}
}
ccm.gConf = &gConf
return nil
}
// Open - 연결 설정
func (ccm *CCMApi) Open() error {
spidercli := ccm.gConf.GSL.SpiderCli
// grpc 커넥션 생성
cbconn, closer, err := gc.NewCBConnection(spidercli)
if err != nil {
return err
}
if closer != nil {
ccm.jaegerCloser = closer
}
ccm.conn = cbconn.Conn
// grpc 클라이언트 생성
ccm.clientCCM = pb.NewCCMClient(ccm.conn)
ccm.clientSSH = pb.NewSSHClient(ccm.conn)
// grpc 호출 Wrapper
ccm.requestCCM = &request.CCMRequest{Client: ccm.clientCCM, Timeout: spidercli.Timeout, InType: ccm.inType, OutType: ccm.outType}
ccm.requestSSH = &request.SSHRequest{Client: ccm.clientSSH, Timeout: spidercli.Timeout, InType: ccm.inType, OutType: ccm.outType}
return nil
}
// Close - 연결 종료
func (ccm *CCMApi) Close() {
if ccm.conn != nil {
ccm.conn.Close()
}
if ccm.jaegerCloser != nil {
ccm.jaegerCloser.Close()
}
ccm.jaegerCloser = nil
ccm.conn = nil
ccm.clientCCM = nil
ccm.clientSSH = nil
ccm.requestCCM = nil
ccm.requestSSH = nil
}
// SetInType - 입력 문서 타입 설정 (json/yaml)
func (ccm *CCMApi) SetInType(in string) error {
if in == "json" {
ccm.inType = in
} else if in == "yaml" {
ccm.inType = in
} else {
return errors.New("input type is not supported")
}
if ccm.requestCCM != nil {
ccm.requestCCM.InType = ccm.inType
}
return nil
}
// GetInType - 입력 문서 타입 값 조회
func (ccm *CCMApi) GetInType() (string, error) {
return ccm.inType, nil
}
// SetOutType - 출력 문서 타입 설정 (json/yaml)
func (ccm *CCMApi) SetOutType(out string) error {
if out == "json" {
ccm.outType = out
} else if out == "yaml" {
ccm.outType = out
} else {
return errors.New("output type is not supported")
}
if ccm.requestCCM != nil {
ccm.requestCCM.OutType = ccm.outType
}
return nil
}
// GetOutType - 출력 문서 타입 값 조회
func (ccm *CCMApi) GetOutType() (string, error) {
return ccm.outType, nil
}
// CreateImage - Image 생성
func (ccm *CCMApi) CreateImage(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.CreateImage()
}
// CreateImageByParam - Image 생성
func (ccm *CCMApi) CreateImageByParam(req *ImageReq) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
j, err := json.Marshal(req)
if err != nil {
return "", err
}
ccm.requestCCM.InData = string(j)
result, err := ccm.requestCCM.CreateImage()
ccm.SetInType(holdType)
return result, err
}
// ListImage - Image 목록
func (ccm *CCMApi) ListImage(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListImage()
}
// ListImageByParam - Image 목록
func (ccm *CCMApi) ListImageByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListImage()
ccm.SetInType(holdType)
return result, err
}
// GetImage - Image 조회
func (ccm *CCMApi) GetImage(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.GetImage()
}
// GetImageByParam - Image 조회
func (ccm *CCMApi) GetImageByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.GetImage()
ccm.SetInType(holdType)
return result, err
}
// DeleteImage - Image 삭제
func (ccm *CCMApi) DeleteImage(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.DeleteImage()
}
// DeleteImageByParam - Image 삭제
func (ccm *CCMApi) DeleteImageByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.DeleteImage()
ccm.SetInType(holdType)
return result, err
}
// ListVMSpec - VM Spec 목록
func (ccm *CCMApi) ListVMSpec(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListVMSpec()
}
// ListVMSpecByParam - VM Spec 목록
func (ccm *CCMApi) ListVMSpecByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListVMSpec()
ccm.SetInType(holdType)
return result, err
}
// GetVMSpec - VM Spec 조회
func (ccm *CCMApi) GetVMSpec(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.GetVMSpec()
}
// GetVMSpecByParam - VM Spec 조회
func (ccm *CCMApi) GetVMSpecByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.GetVMSpec()
ccm.SetInType(holdType)
return result, err
}
// ListOrgVMSpec - 클라우드의 원래 VM Spec 목록
func (ccm *CCMApi) ListOrgVMSpec(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListOrgVMSpec()
}
// ListOrgVMSpecByParam - 클라우드의 원래 VM Spec 목록
func (ccm *CCMApi) ListOrgVMSpecByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListOrgVMSpec()
ccm.SetInType(holdType)
return result, err
}
// GetOrgVMSpec - 클라우드의 원래 VM Spec 조회
func (ccm *CCMApi) GetOrgVMSpec(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.GetOrgVMSpec()
}
// GetOrgVMSpecByParam - 클라우드의 원래 VM Spec 조회
func (ccm *CCMApi) GetOrgVMSpecByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.GetOrgVMSpec()
ccm.SetInType(holdType)
return result, err
}
// CreateVPC - VPC 생성
func (ccm *CCMApi) CreateVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.CreateVPC()
}
// CreateVPCByParam - VPC 생성
func (ccm *CCMApi) CreateVPCByParam(req *VPCReq) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
j, err := json.Marshal(req)
if err != nil {
return "", err
}
ccm.requestCCM.InData = string(j)
result, err := ccm.requestCCM.CreateVPC()
ccm.SetInType(holdType)
return result, err
}
// ListVPC - VPC 목록
func (ccm *CCMApi) ListVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListVPC()
}
// ListVPCByParam - VPC 목록
func (ccm *CCMApi) ListVPCByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListVPC()
ccm.SetInType(holdType)
return result, err
}
// GetVPC - VPC 조회
func (ccm *CCMApi) GetVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.GetVPC()
}
// GetVPCByParam - VPC 조회
func (ccm *CCMApi) GetVPCByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.GetVPC()
ccm.SetInType(holdType)
return result, err
}
// DeleteVPC - VPC 삭제
func (ccm *CCMApi) DeleteVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.DeleteVPC()
}
// DeleteVPCByParam - VPC 삭제
func (ccm *CCMApi) DeleteVPCByParam(connectionName string, name string, force string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `", "force":"` + force + `"}`
result, err := ccm.requestCCM.DeleteVPC()
ccm.SetInType(holdType)
return result, err
}
// ListAllVPC - 관리 VPC 목록
func (ccm *CCMApi) ListAllVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListAllVPC()
}
// ListAllVPCByParam - 관리 VPC 목록
func (ccm *CCMApi) ListAllVPCByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListAllVPC()
ccm.SetInType(holdType)
return result, err
}
// DeleteCSPVPC - 관리 VPC 삭제
func (ccm *CCMApi) DeleteCSPVPC(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.DeleteCSPVPC()
}
// DeleteCSPVPCByParam - 관리 VPC 삭제
func (ccm *CCMApi) DeleteCSPVPCByParam(connectionName string, id string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Id":"` + id + `"}`
result, err := ccm.requestCCM.DeleteCSPVPC()
ccm.SetInType(holdType)
return result, err
}
// AddSubnet - Subnet 추가
func (ccm *CCMApi) AddSubnet(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.AddSubnet()
}
// AddSubnetByParam - Subnet 추가
func (ccm *CCMApi) AddSubnetByParam(req *SubnetReq) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
j, err := json.Marshal(req)
if err != nil {
return "", err
}
ccm.requestCCM.InData = string(j)
result, err := ccm.requestCCM.AddSubnet()
ccm.SetInType(holdType)
return result, err
}
// RemoveSubnet - Subnet 삭제
func (ccm *CCMApi) RemoveSubnet(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.RemoveSubnet()
}
// RemoveSubnetByParam - Subnet 삭제
func (ccm *CCMApi) RemoveSubnetByParam(connectionName string, vpcName string, subnetName string, force string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "VPCName":"` + vpcName + `", "SubnetName":"` + subnetName + `", "force":"` + force + `"}`
result, err := ccm.requestCCM.RemoveSubnet()
ccm.SetInType(holdType)
return result, err
}
// RemoveCSPSubnet - CSP Subnet 삭제
func (ccm *CCMApi) RemoveCSPSubnet(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.RemoveCSPSubnet()
}
// RemoveCSPSubnetByParam - CSP Subnet 삭제
func (ccm *CCMApi) RemoveCSPSubnetByParam(connectionName string, vpcName string, id string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "VPCName":"` + vpcName + `", "Id":"` + id + `"}`
result, err := ccm.requestCCM.RemoveCSPSubnet()
ccm.SetInType(holdType)
return result, err
}
// CreateSecurity - Security 생성
func (ccm *CCMApi) CreateSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.CreateSecurity()
}
// CreateSecurityByParam - Security 생성
func (ccm *CCMApi) CreateSecurityByParam(req *SecurityReq) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
j, err := json.Marshal(req)
if err != nil {
return "", err
}
ccm.requestCCM.InData = string(j)
result, err := ccm.requestCCM.CreateSecurity()
ccm.SetInType(holdType)
return result, err
}
// ListSecurity - Security 목록
func (ccm *CCMApi) ListSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListSecurity()
}
// ListSecurityByParam - Security 목록
func (ccm *CCMApi) ListSecurityByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListSecurity()
ccm.SetInType(holdType)
return result, err
}
// GetSecurity - Security 조회
func (ccm *CCMApi) GetSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.GetSecurity()
}
// GetSecurityByParam - Security 조회
func (ccm *CCMApi) GetSecurityByParam(connectionName string, name string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `"}`
result, err := ccm.requestCCM.GetSecurity()
ccm.SetInType(holdType)
return result, err
}
// DeleteSecurity - Security 삭제
func (ccm *CCMApi) DeleteSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.DeleteSecurity()
}
// DeleteSecurityByParam - Security 삭제
func (ccm *CCMApi) DeleteSecurityByParam(connectionName string, name string, force string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Name":"` + name + `", "force":"` + force + `"}`
result, err := ccm.requestCCM.DeleteSecurity()
ccm.SetInType(holdType)
return result, err
}
// ListAllSecurity - 관리 Security 목록
func (ccm *CCMApi) ListAllSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.ListAllSecurity()
}
// ListAllSecurityByParam - 관리 Security 목록
func (ccm *CCMApi) ListAllSecurityByParam(connectionName string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `"}`
result, err := ccm.requestCCM.ListAllSecurity()
ccm.SetInType(holdType)
return result, err
}
// DeleteCSPSecurity - 관리 Security 삭제
func (ccm *CCMApi) DeleteCSPSecurity(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.DeleteCSPSecurity()
}
// DeleteCSPSecurityByParam - 관리 Security 삭제
func (ccm *CCMApi) DeleteCSPSecurityByParam(connectionName string, id string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
ccm.requestCCM.InData = `{"ConnectionName":"` + connectionName + `", "Id":"` + id + `"}`
result, err := ccm.requestCCM.DeleteCSPSecurity()
ccm.SetInType(holdType)
return result, err
}
// CreateKey - Key Pair 생성
func (ccm *CCMApi) CreateKey(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc
return ccm.requestCCM.CreateKey()
}
// CreateKeyByParam - Key Pair 생성
func (ccm *CCMApi) CreateKeyByParam(req *KeyReq) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
holdType, _ := ccm.GetInType()
ccm.SetInType("json")
j, err := json.Marshal(req)
if err != nil {
return "", err
}
ccm.requestCCM.InData = string(j)
result, err := ccm.requestCCM.CreateKey()
ccm.SetInType(holdType)
return result, err
}
// ListKey - Key Pair 목록
func (ccm *CCMApi) ListKey(doc string) (string, error) {
if ccm.requestCCM == nil {
return "", errors.New("The Open() function must be called")
}
ccm.requestCCM.InData = doc