@@ -36,8 +36,142 @@ func init() {
36
36
cblog .SetLevel ("debug" )
37
37
}
38
38
39
- // Test SecurityHandler
40
39
func handleSecurity () {
40
+ cblogger .Debug ("Start Security Resource Test" )
41
+
42
+ ResourceHandler , err := getResourceHandler ("Security" )
43
+ if err != nil {
44
+ panic (err )
45
+ }
46
+ handler := ResourceHandler .(irs.SecurityHandler )
47
+
48
+ //config := readConfigFile()
49
+ //VmID := config.Aws.VmID
50
+
51
+ securityName := "CB-SecurityTest1"
52
+ securityId := "sg-0d6a2bb960481ce68"
53
+ vpcId := "vpc-c0479cab"
54
+
55
+ for {
56
+ fmt .Println ("Security Management" )
57
+ fmt .Println ("0. Quit" )
58
+ fmt .Println ("1. Security List" )
59
+ fmt .Println ("2. Security Create" )
60
+ fmt .Println ("3. Security Get" )
61
+ fmt .Println ("4. Security Delete" )
62
+
63
+ var commandNum int
64
+ inputCnt , err := fmt .Scan (& commandNum )
65
+ if err != nil {
66
+ panic (err )
67
+ }
68
+
69
+ if inputCnt == 1 {
70
+ switch commandNum {
71
+ case 0 :
72
+ return
73
+
74
+ case 1 :
75
+ result , err := handler .ListSecurity ()
76
+ if err != nil {
77
+ cblogger .Infof (" Security 목록 조회 실패 : " , err )
78
+ } else {
79
+ cblogger .Info ("Security 목록 조회 결과" )
80
+ //cblogger.Info(result)
81
+ spew .Dump (result )
82
+ if result != nil {
83
+ securityId = result [0 ].IId .SystemId // 조회 및 삭제를 위해 생성된 ID로 변경
84
+ }
85
+ }
86
+
87
+ case 2 :
88
+ cblogger .Infof ("[%s] Security 생성 테스트" , securityName )
89
+
90
+ securityReqInfo := irs.SecurityReqInfo {
91
+ IId : irs.IID {NameId : securityName },
92
+ VpcIID : irs.IID {SystemId : vpcId },
93
+ SecurityRules : & []irs.SecurityRuleInfo { //보안 정책 설정
94
+ {
95
+ FromPort : "20" ,
96
+ ToPort : "22" ,
97
+ IPProtocol : "tcp" ,
98
+ Direction : "inbound" ,
99
+ },
100
+
101
+ {
102
+ FromPort : "80" ,
103
+ ToPort : "80" ,
104
+ IPProtocol : "tcp" ,
105
+ Direction : "inbound" ,
106
+ },
107
+ {
108
+ FromPort : "8080" ,
109
+ ToPort : "8080" ,
110
+ IPProtocol : "tcp" ,
111
+ Direction : "inbound" ,
112
+ },
113
+ {
114
+ FromPort : "-1" ,
115
+ ToPort : "-1" ,
116
+ IPProtocol : "icmp" ,
117
+ Direction : "inbound" ,
118
+ },
119
+ {
120
+ FromPort : "443" ,
121
+ ToPort : "443" ,
122
+ IPProtocol : "tcp" ,
123
+ Direction : "outbound" ,
124
+ },
125
+ {
126
+ FromPort : "8443" ,
127
+ ToPort : "9999" ,
128
+ IPProtocol : "tcp" ,
129
+ Direction : "outbound" ,
130
+ },
131
+ /*
132
+ {
133
+ //FromPort: "8443",
134
+ //ToPort: "9999",
135
+ IPProtocol: "-1", // 모두 허용 (포트 정보 없음)
136
+ Direction: "inbound",
137
+ },
138
+ */
139
+ },
140
+ }
141
+
142
+ result , err := handler .CreateSecurity (securityReqInfo )
143
+ if err != nil {
144
+ cblogger .Infof (securityName , " Security 생성 실패 : " , err )
145
+ } else {
146
+ cblogger .Infof ("[%s] Security 생성 결과 : [%v]" , securityName , result )
147
+ spew .Dump (result )
148
+ }
149
+
150
+ case 3 :
151
+ cblogger .Infof ("[%s] Security 조회 테스트" , securityId )
152
+ result , err := handler .GetSecurity (irs.IID {SystemId : securityId })
153
+ if err != nil {
154
+ cblogger .Infof (securityId , " Security 조회 실패 : " , err )
155
+ } else {
156
+ cblogger .Infof ("[%s] Security 조회 결과 : [%v]" , securityId , result )
157
+ spew .Dump (result )
158
+ }
159
+
160
+ case 4 :
161
+ cblogger .Infof ("[%s] Security 삭제 테스트" , securityId )
162
+ result , err := handler .DeleteSecurity (irs.IID {SystemId : securityId })
163
+ if err != nil {
164
+ cblogger .Infof (securityId , " Security 삭제 실패 : " , err )
165
+ } else {
166
+ cblogger .Infof ("[%s] Security 삭제 결과 : [%s]" , securityId , result )
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ // Test SecurityHandler
174
+ func handleSecurityOld () {
41
175
cblogger .Debug ("Start handler" )
42
176
43
177
ResourceHandler , err := getResourceHandler ("Security" )
@@ -937,16 +1071,15 @@ func main() {
937
1071
}
938
1072
*/
939
1073
940
- //handleVNetwork() //VPC
1074
+ //handleVPC()
941
1075
//handleKeyPair()
942
1076
//handlePublicIP() // PublicIP 생성 후 conf
943
- // handleSecurity()
944
- handleVM ()
1077
+ handleSecurity ()
1078
+ // handleVM()
945
1079
946
1080
//handleImage() //AMI
947
1081
//handleVNic() //Lancard
948
1082
//handleVMSpec()
949
- //handleVPC()
950
1083
951
1084
/*
952
1085
KeyPairHandler, err := setKeyPairHandler()
0 commit comments