-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.html
419 lines (361 loc) · 14.7 KB
/
coverage.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>rds: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">rds/rds.go (70.5%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">not covered</span>
<span class="cov8">covered</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/gophercloud/utils/client"
"github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/subnets"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/vpcs"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v2/extensions/security/groups"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/instances"
"gopkg.in/yaml.v3"
"k8s.io/klog/v2"
)
var (
osExit = os.Exit
create *bool
help *bool
version *bool
)
const (
AppVersion = "0.0.4"
RdsYaml = "rds.yaml"
)
type conf struct {
Name string `yaml:"name"`
Datastore *Datastore `yaml:"datastore"`
Ha *Ha `yaml:"ha"`
Port string `yaml:"port"`
Password string `yaml:"password"`
BackupStrategy *BackupStrategy `yaml:"backupstrategy"`
FlavorRef string `yaml:"flavorref"`
Volume *Volume `yaml:"volume"`
Region string `yaml:"region"`
AvailabilityZone string `yaml:"availabilityzone"`
Vpc string `yaml:"vpc"`
Subnet string `yaml:"subnet"`
SecurityGroup string `yaml:"securitygroup"`
}
type Datastore struct {
Type string `json:"type" required:"true"`
Version string `json:"version" required:"true"`
}
type Ha struct {
Mode string `json:"mode" required:"true"`
ReplicationMode string `json:"replicationmode,omitempty"`
}
type BackupStrategy struct {
StartTime string `json:"starttime" required:"true"`
KeepDays int `json:"keepdays,omitempty"`
}
type Volume struct {
Type string `json:"type" required:"true"`
Size int `json:"size" required:"true"`
}
func init() <span class="cov8" title="1">{
create = flag.Bool("create", false, "create RDS instance")
help = flag.Bool("help", false, "program help")
version = flag.Bool("version", false, "version of the program")
}</span>
func secgroupGet(client *golangsdk.ServiceClient, opts *groups.ListOpts) (*groups.SecGroup, error) <span class="cov8" title="1">{
pages, err := groups.List(client, *opts).AllPages()
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="1">n, err := groups.ExtractGroups(pages)
if len(n) == 0 </span><span class="cov0" title="0">{
klog.Exitf("no secgroup found")
}</span>
<span class="cov8" title="1">return &n[0], nil</span>
}
func subnetGet(client *golangsdk.ServiceClient, opts *subnets.ListOpts) (*subnets.Subnet, error) <span class="cov8" title="1">{
n, err := subnets.List(client, *opts)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="1">if len(n) == 0 </span><span class="cov0" title="0">{
klog.Exitf("no subnet found")
}</span>
<span class="cov8" title="1">return &n[0], nil</span>
}
func vpcGet(client *golangsdk.ServiceClient, opts *vpcs.ListOpts) (*vpcs.Vpc, error) <span class="cov8" title="1">{
n, err := vpcs.List(client, *opts)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="1">if len(n) == 0 </span><span class="cov0" title="0">{
klog.Exitf("no vpc found")
}</span>
<span class="cov8" title="1">return &n[0], nil</span>
}
func rdsGet(client *golangsdk.ServiceClient, rdsId string) (*instances.RdsInstanceResponse, error) <span class="cov8" title="1">{
listOpts := instances.ListRdsInstanceOpts{
Id: rdsId,
}
allPages, err := instances.List(client, listOpts).AllPages()
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="1">n, err := instances.ExtractRdsInstances(allPages)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="1">if len(n.Instances) == 0 </span><span class="cov0" title="0">{
return nil, nil
}</span>
<span class="cov8" title="1">return &n.Instances[0], nil</span>
}
func rdsCreate(netclient1 *golangsdk.ServiceClient, netclient2 *golangsdk.ServiceClient, client *golangsdk.ServiceClient, opts *instances.CreateRdsOpts) error <span class="cov8" title="1">{
var c conf
c.getConf()
g, err := secgroupGet(netclient2, &groups.ListOpts{Name: c.SecurityGroup})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting secgroup state: %v", err)
}</span>
<span class="cov8" title="1">s, err := subnetGet(netclient1, &subnets.ListOpts{Name: c.Subnet})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting subnet state: %v", err)
}</span>
<span class="cov8" title="1">v, err := vpcGet(netclient1, &vpcs.ListOpts{Name: c.Vpc})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting vpc state: %v", err)
}</span>
<span class="cov8" title="1">createOpts := instances.CreateRdsOpts{
Name: c.Name,
Datastore: &instances.Datastore{
Type: c.Datastore.Type,
Version: c.Datastore.Version,
},
Ha: &instances.Ha{
Mode: c.Ha.Mode,
ReplicationMode: c.Ha.ReplicationMode,
},
Port: c.Port,
Password: c.Password,
BackupStrategy: &instances.BackupStrategy{
StartTime: c.BackupStrategy.StartTime,
KeepDays: c.BackupStrategy.KeepDays,
},
FlavorRef: c.FlavorRef,
Volume: &instances.Volume{
Type: c.Volume.Type,
Size: c.Volume.Size,
},
Region: c.Region,
AvailabilityZone: c.AvailabilityZone,
VpcId: v.ID,
SubnetId: s.ID,
SecurityGroupId: g.ID,
}
createResult := instances.Create(client, createOpts)
r, err := createResult.Extract()
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error creating rds instance: %v", err)
}</span>
<span class="cov8" title="1">jobResponse, err := createResult.ExtractJobResponse()
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error creating rds job: %v", err)
}</span>
<span class="cov8" title="1">if err := instances.WaitForJobCompleted(client, int(1800), jobResponse.JobID); err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting rds job: %v", err)
}</span>
<span class="cov8" title="1">rdsInstance, err := rdsGet(client, r.Instance.Id)
fmt.Println(rdsInstance.PrivateIps[0])
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting rds state: %v", err)
}</span>
<span class="cov8" title="1">return nil</span>
}
func (c *conf) getConf() *conf <span class="cov8" title="1">{
yfile, err := ioutil.ReadFile(RdsYaml)
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error reading yaml file: %v", err)
}</span>
<span class="cov8" title="1">err = yaml.Unmarshal(yfile, c)
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error unmarshal yaml file: %v", err)
}</span>
<span class="cov8" title="1">return c</span>
}
func getProvider() *golangsdk.ProviderClient <span class="cov8" title="1">{
if os.Getenv("OS_AUTH_URL") == "" </span><span class="cov0" title="0">{
os.Setenv("OS_AUTH_URL", "https://iam.eu-de.otc.t-systems.com:443/v3")
}</span>
<span class="cov8" title="1">if os.Getenv("OS_IDENTITY_API_VERSION") == "" </span><span class="cov0" title="0">{
os.Setenv("OS_IDENTITY_API_VERSION", "3")
}</span>
<span class="cov8" title="1">if os.Getenv("OS_REGION_NAME") == "" </span><span class="cov8" title="1">{
os.Setenv("OS_REGION_NAME", "eu-de")
}</span>
<span class="cov8" title="1">if os.Getenv("OS_PROJECT_NAME") == "" </span><span class="cov8" title="1">{
os.Setenv("OS_PROJECT_NAME", "eu-de")
}</span>
<span class="cov8" title="1">opts, err := openstack.AuthOptionsFromEnv()
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("error getting auth from env: %v", err)
}</span>
<span class="cov8" title="1">provider, err := openstack.AuthenticatedClient(opts)
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("unable to initialize openstack client: %v", err)
}</span>
<span class="cov8" title="1">if os.Getenv("OS_DEBUG") != "" </span><span class="cov0" title="0">{
provider.HTTPClient = http.Client{
Transport: &client.RoundTripper{
Rt: &http.Transport{},
Logger: &client.DefaultLogger{},
},
}
}</span>
<span class="cov8" title="1">return provider</span>
}
func getFlags(cliFullArg string) <span class="cov8" title="1">{
flag.Parse()
if *help || cliFullArg == " -help " </span><span class="cov8" title="1">{
fmt.Println("Provide ENV variable to connect OTC: OS_PROJECT_NAME, OS_REGION_NAME, OS_AUTH_URL, OS_IDENTITY_API_VERSION, OS_USER_DOMAIN_NAME, OS_USERNAME, OS_PASSWORD")
osExit(0)
}</span>
<span class="cov8" title="1">if *version || cliFullArg == " -version " </span><span class="cov8" title="1">{
fmt.Println("version", AppVersion)
osExit(0)
}</span>
<span class="cov8" title="1">if *create || cliFullArg == " -create " </span><span class="cov0" title="0">{
fmt.Println("version", AppVersion)
Create()
}</span>
<span class="cov8" title="1">return</span>
}
func Create() <span class="cov8" title="1">{
provider := getProvider()
network1, err := openstack.NewNetworkV1(provider, golangsdk.EndpointOpts{})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("unable to initialize network v1 client: %v", err)
return
}</span>
<span class="cov8" title="1">network2, err := openstack.NewNetworkV2(provider, golangsdk.EndpointOpts{})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("unable to initialize network v2 client: %v", err)
return
}</span>
<span class="cov8" title="1">rds, err := openstack.NewRDSV3(provider, golangsdk.EndpointOpts{})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("unable to initialize rds client: %v", err)
return
}</span>
/* Debug output of the ProviderClient response
git clone https://github.com/opentelekomcloud/gophertelekomcloud.git
cd gophercloud
git patch ../provider_client.go.patch
cd ..
go mod edit -replace=github.com/opentelekomcloud/gophertelekomcloud=./gophertelekomcloud
fmt.Println("network1:", network1)
fmt.Printf("%+v\n", network1.ProviderClient)
*/
<span class="cov8" title="1">rdsCreate(network1, network2, rds, &instances.CreateRdsOpts{})
if err != nil </span><span class="cov0" title="0">{
klog.Exitf("rds creating failed: %v", err)
return
}</span>
<span class="cov8" title="1">return</span>
}
func main() <span class="cov8" title="1">{
getFlags("default")
}</span>
</pre>
</div>
</body>
<script>
(function() {
var files = document.getElementById('files');
var visible;
files.addEventListener('change', onChange, false);
function select(part) {
if (visible)
visible.style.display = 'none';
visible = document.getElementById(part);
if (!visible)
return;
files.value = part;
visible.style.display = 'block';
location.hash = part;
}
function onChange() {
select(files.value);
window.scrollTo(0, 0);
}
if (location.hash != "") {
select(location.hash.substr(1));
}
if (!visible) {
select("file0");
}
})();
</script>
</html>