This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
forked from xanzy/go-cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RouterService.go
1320 lines (1208 loc) · 41.8 KB
/
RouterService.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
//
// Copyright 2014, Sander van Harmelen
//
// 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.
//
package cloudstack
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
)
type StartRouterParams struct {
p map[string]interface{}
}
func (p *StartRouterParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *StartRouterParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new StartRouterParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewStartRouterParams(id string) *StartRouterParams {
p := &StartRouterParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Starts a router.
func (s *RouterService) StartRouter(p *StartRouterParams) (*StartRouterResponse, error) {
resp, err := s.cs.newRequest("startRouter", p.toURLValues())
if err != nil {
return nil, err
}
var r StartRouterResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}
var r StartRouterResponse
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
return &r, nil
}
return &r, nil
}
type StartRouterResponse struct {
JobID string `json:"jobid,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Podid string `json:"podid,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
Name string `json:"name,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
State string `json:"state,omitempty"`
Guestnetworkid string `json:"guestnetworkid,omitempty"`
Templateid string `json:"templateid,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Domain string `json:"domain,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Nic []struct {
Type string `json:"type,omitempty"`
Networkid string `json:"networkid,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Networkname string `json:"networkname,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Gateway string `json:"gateway,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Id string `json:"id,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Secondaryip []string `json:"secondaryip,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Netmask string `json:"netmask,omitempty"`
} `json:"nic,omitempty"`
Domainid string `json:"domainid,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Projectid string `json:"projectid,omitempty"`
Created string `json:"created,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Role string `json:"role,omitempty"`
Hostid string `json:"hostid,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Project string `json:"project,omitempty"`
Publicip string `json:"publicip,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Version string `json:"version,omitempty"`
Account string `json:"account,omitempty"`
Zonename string `json:"zonename,omitempty"`
}
type RebootRouterParams struct {
p map[string]interface{}
}
func (p *RebootRouterParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *RebootRouterParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new RebootRouterParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewRebootRouterParams(id string) *RebootRouterParams {
p := &RebootRouterParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Starts a router.
func (s *RouterService) RebootRouter(p *RebootRouterParams) (*RebootRouterResponse, error) {
resp, err := s.cs.newRequest("rebootRouter", p.toURLValues())
if err != nil {
return nil, err
}
var r RebootRouterResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}
var r RebootRouterResponse
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
return &r, nil
}
return &r, nil
}
type RebootRouterResponse struct {
JobID string `json:"jobid,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Hostid string `json:"hostid,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Version string `json:"version,omitempty"`
Gateway string `json:"gateway,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Domainid string `json:"domainid,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
Templateid string `json:"templateid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
Guestnetworkid string `json:"guestnetworkid,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Projectid string `json:"projectid,omitempty"`
Created string `json:"created,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Nic []struct {
Traffictype string `json:"traffictype,omitempty"`
Networkid string `json:"networkid,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Netmask string `json:"netmask,omitempty"`
Id string `json:"id,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Secondaryip []string `json:"secondaryip,omitempty"`
Type string `json:"type,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Networkname string `json:"networkname,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Gateway string `json:"gateway,omitempty"`
} `json:"nic,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Domain string `json:"domain,omitempty"`
Zonename string `json:"zonename,omitempty"`
Project string `json:"project,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Name string `json:"name,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Role string `json:"role,omitempty"`
Account string `json:"account,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
State string `json:"state,omitempty"`
Publicip string `json:"publicip,omitempty"`
Podid string `json:"podid,omitempty"`
Id string `json:"id,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
}
type StopRouterParams struct {
p map[string]interface{}
}
func (p *StopRouterParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["forced"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forced", vv)
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *StopRouterParams) SetForced(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forced"] = v
return
}
func (p *StopRouterParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new StopRouterParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewStopRouterParams(id string) *StopRouterParams {
p := &StopRouterParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Stops a router.
func (s *RouterService) StopRouter(p *StopRouterParams) (*StopRouterResponse, error) {
resp, err := s.cs.newRequest("stopRouter", p.toURLValues())
if err != nil {
return nil, err
}
var r StopRouterResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}
var r StopRouterResponse
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
return &r, nil
}
return &r, nil
}
type StopRouterResponse struct {
JobID string `json:"jobid,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Templateid string `json:"templateid,omitempty"`
Created string `json:"created,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Projectid string `json:"projectid,omitempty"`
Podid string `json:"podid,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Account string `json:"account,omitempty"`
Guestnetworkid string `json:"guestnetworkid,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Version string `json:"version,omitempty"`
Publicip string `json:"publicip,omitempty"`
Nic []struct {
Networkid string `json:"networkid,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Type string `json:"type,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Gateway string `json:"gateway,omitempty"`
Id string `json:"id,omitempty"`
Networkname string `json:"networkname,omitempty"`
Netmask string `json:"netmask,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Secondaryip []string `json:"secondaryip,omitempty"`
} `json:"nic,omitempty"`
Hostname string `json:"hostname,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Domain string `json:"domain,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Name string `json:"name,omitempty"`
Role string `json:"role,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Gateway string `json:"gateway,omitempty"`
Zonename string `json:"zonename,omitempty"`
Domainid string `json:"domainid,omitempty"`
State string `json:"state,omitempty"`
Id string `json:"id,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Hostid string `json:"hostid,omitempty"`
Project string `json:"project,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
}
type DestroyRouterParams struct {
p map[string]interface{}
}
func (p *DestroyRouterParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
return u
}
func (p *DestroyRouterParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
// You should always use this function to get a new DestroyRouterParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewDestroyRouterParams(id string) *DestroyRouterParams {
p := &DestroyRouterParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
return p
}
// Destroys a router.
func (s *RouterService) DestroyRouter(p *DestroyRouterParams) (*DestroyRouterResponse, error) {
resp, err := s.cs.newRequest("destroyRouter", p.toURLValues())
if err != nil {
return nil, err
}
var r DestroyRouterResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}
var r DestroyRouterResponse
if err := json.Unmarshal(b, &r); err != nil {
return nil, err
}
return &r, nil
}
return &r, nil
}
type DestroyRouterResponse struct {
JobID string `json:"jobid,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
Nic []struct {
Isolationuri string `json:"isolationuri,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Id string `json:"id,omitempty"`
Secondaryip []string `json:"secondaryip,omitempty"`
Type string `json:"type,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Networkid string `json:"networkid,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Netmask string `json:"netmask,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Networkname string `json:"networkname,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Gateway string `json:"gateway,omitempty"`
} `json:"nic,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Hostid string `json:"hostid,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Hostname string `json:"hostname,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Guestnetworkid string `json:"guestnetworkid,omitempty"`
Templateid string `json:"templateid,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Name string `json:"name,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Created string `json:"created,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Version string `json:"version,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Project string `json:"project,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Role string `json:"role,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Projectid string `json:"projectid,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
State string `json:"state,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Zonename string `json:"zonename,omitempty"`
Domain string `json:"domain,omitempty"`
Account string `json:"account,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
Id string `json:"id,omitempty"`
Domainid string `json:"domainid,omitempty"`
Podid string `json:"podid,omitempty"`
Publicip string `json:"publicip,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
}
type ChangeServiceForRouterParams struct {
p map[string]interface{}
}
func (p *ChangeServiceForRouterParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["serviceofferingid"]; found {
u.Set("serviceofferingid", v.(string))
}
return u
}
func (p *ChangeServiceForRouterParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ChangeServiceForRouterParams) SetServiceofferingid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["serviceofferingid"] = v
return
}
// You should always use this function to get a new ChangeServiceForRouterParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewChangeServiceForRouterParams(id string, serviceofferingid string) *ChangeServiceForRouterParams {
p := &ChangeServiceForRouterParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
p.p["serviceofferingid"] = serviceofferingid
return p
}
// Upgrades domain router to a new service offering
func (s *RouterService) ChangeServiceForRouter(p *ChangeServiceForRouterParams) (*ChangeServiceForRouterResponse, error) {
resp, err := s.cs.newRequest("changeServiceForRouter", p.toURLValues())
if err != nil {
return nil, err
}
var r ChangeServiceForRouterResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ChangeServiceForRouterResponse struct {
Hostname string `json:"hostname,omitempty"`
Templateid string `json:"templateid,omitempty"`
Nic []struct {
Secondaryip []string `json:"secondaryip,omitempty"`
Networkid string `json:"networkid,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Id string `json:"id,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Type string `json:"type,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Networkname string `json:"networkname,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Netmask string `json:"netmask,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Gateway string `json:"gateway,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
} `json:"nic,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
State string `json:"state,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Projectid string `json:"projectid,omitempty"`
Account string `json:"account,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Domainid string `json:"domainid,omitempty"`
Guestnetworkid string `json:"guestnetworkid,omitempty"`
Id string `json:"id,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Publicip string `json:"publicip,omitempty"`
Version string `json:"version,omitempty"`
Name string `json:"name,omitempty"`
Zonename string `json:"zonename,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Hostid string `json:"hostid,omitempty"`
Domain string `json:"domain,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Podid string `json:"podid,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
Gateway string `json:"gateway,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Networkdomain string `json:"networkdomain,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Role string `json:"role,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Project string `json:"project,omitempty"`
Created string `json:"created,omitempty"`
Vpcid string `json:"vpcid,omitempty"`
Serviceofferingid string `json:"serviceofferingid,omitempty"`
}
type ListRoutersParams struct {
p map[string]interface{}
}
func (p *ListRoutersParams) toURLValues() url.Values {
u := url.Values{}
if p.p == nil {
return u
}
if v, found := p.p["account"]; found {
u.Set("account", v.(string))
}
if v, found := p.p["clusterid"]; found {
u.Set("clusterid", v.(string))
}
if v, found := p.p["domainid"]; found {
u.Set("domainid", v.(string))
}
if v, found := p.p["forvpc"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("forvpc", vv)
}
if v, found := p.p["hostid"]; found {
u.Set("hostid", v.(string))
}
if v, found := p.p["id"]; found {
u.Set("id", v.(string))
}
if v, found := p.p["isrecursive"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("isrecursive", vv)
}
if v, found := p.p["keyword"]; found {
u.Set("keyword", v.(string))
}
if v, found := p.p["listall"]; found {
vv := strconv.FormatBool(v.(bool))
u.Set("listall", vv)
}
if v, found := p.p["name"]; found {
u.Set("name", v.(string))
}
if v, found := p.p["networkid"]; found {
u.Set("networkid", v.(string))
}
if v, found := p.p["page"]; found {
vv := strconv.Itoa(v.(int))
u.Set("page", vv)
}
if v, found := p.p["pagesize"]; found {
vv := strconv.Itoa(v.(int))
u.Set("pagesize", vv)
}
if v, found := p.p["podid"]; found {
u.Set("podid", v.(string))
}
if v, found := p.p["projectid"]; found {
u.Set("projectid", v.(string))
}
if v, found := p.p["state"]; found {
u.Set("state", v.(string))
}
if v, found := p.p["version"]; found {
u.Set("version", v.(string))
}
if v, found := p.p["vpcid"]; found {
u.Set("vpcid", v.(string))
}
if v, found := p.p["zoneid"]; found {
u.Set("zoneid", v.(string))
}
return u
}
func (p *ListRoutersParams) SetAccount(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["account"] = v
return
}
func (p *ListRoutersParams) SetClusterid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["clusterid"] = v
return
}
func (p *ListRoutersParams) SetDomainid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["domainid"] = v
return
}
func (p *ListRoutersParams) SetForvpc(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["forvpc"] = v
return
}
func (p *ListRoutersParams) SetHostid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["hostid"] = v
return
}
func (p *ListRoutersParams) SetId(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["id"] = v
return
}
func (p *ListRoutersParams) SetIsrecursive(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["isrecursive"] = v
return
}
func (p *ListRoutersParams) SetKeyword(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["keyword"] = v
return
}
func (p *ListRoutersParams) SetListall(v bool) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["listall"] = v
return
}
func (p *ListRoutersParams) SetName(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["name"] = v
return
}
func (p *ListRoutersParams) SetNetworkid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["networkid"] = v
return
}
func (p *ListRoutersParams) SetPage(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["page"] = v
return
}
func (p *ListRoutersParams) SetPagesize(v int) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["pagesize"] = v
return
}
func (p *ListRoutersParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["podid"] = v
return
}
func (p *ListRoutersParams) SetProjectid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["projectid"] = v
return
}
func (p *ListRoutersParams) SetState(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["state"] = v
return
}
func (p *ListRoutersParams) SetVersion(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["version"] = v
return
}
func (p *ListRoutersParams) SetVpcid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["vpcid"] = v
return
}
func (p *ListRoutersParams) SetZoneid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["zoneid"] = v
return
}
// You should always use this function to get a new ListRoutersParams instance,
// as then you are sure you have configured all required params
func (s *RouterService) NewListRoutersParams() *ListRoutersParams {
p := &ListRoutersParams{}
p.p = make(map[string]interface{})
return p
}
// This is a courtesy helper function, which in some cases may not work as expected!
func (s *RouterService) GetRouterID(name string) (string, error) {
p := &ListRoutersParams{}
p.p = make(map[string]interface{})
p.p["name"] = name
l, err := s.ListRouters(p)
if err != nil {
return "", err
}
if l.Count != 1 {
return "", fmt.Errorf("%d matches found for %s: %+v", l.Count, name, l)
}
return l.Routers[0].Id, nil
}
// List routers.
func (s *RouterService) ListRouters(p *ListRoutersParams) (*ListRoutersResponse, error) {
resp, err := s.cs.newRequest("listRouters", p.toURLValues())
if err != nil {
return nil, err
}
var r ListRoutersResponse
if err := json.Unmarshal(resp, &r); err != nil {
return nil, err
}
return &r, nil
}
type ListRoutersResponse struct {
Count int `json:"count"`
Routers []*Router `json:"router"`
}
type Router struct {
Vpcid string `json:"vpcid,omitempty"`
Domain string `json:"domain,omitempty"`
Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
Publicnetworkid string `json:"publicnetworkid,omitempty"`
Domainid string `json:"domainid,omitempty"`
Dns2 string `json:"dns2,omitempty"`
Dns1 string `json:"dns1,omitempty"`
Zonename string `json:"zonename,omitempty"`
Account string `json:"account,omitempty"`
Linklocalip string `json:"linklocalip,omitempty"`
Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
Ip6dns1 string `json:"ip6dns1,omitempty"`
Zoneid string `json:"zoneid,omitempty"`
Redundantstate string `json:"redundantstate,omitempty"`
Publicmacaddress string `json:"publicmacaddress,omitempty"`
Role string `json:"role,omitempty"`
Publicnetmask string `json:"publicnetmask,omitempty"`
Version string `json:"version,omitempty"`
Project string `json:"project,omitempty"`
Nic []struct {
Type string `json:"type,omitempty"`
Gateway string `json:"gateway,omitempty"`
Netmask string `json:"netmask,omitempty"`
Ipaddress string `json:"ipaddress,omitempty"`
Ip6address string `json:"ip6address,omitempty"`
Macaddress string `json:"macaddress,omitempty"`
Isolationuri string `json:"isolationuri,omitempty"`
Broadcasturi string `json:"broadcasturi,omitempty"`
Networkname string `json:"networkname,omitempty"`
Ip6cidr string `json:"ip6cidr,omitempty"`
Ip6gateway string `json:"ip6gateway,omitempty"`
Traffictype string `json:"traffictype,omitempty"`
Secondaryip []string `json:"secondaryip,omitempty"`
Isdefault bool `json:"isdefault,omitempty"`
Id string `json:"id,omitempty"`
Networkid string `json:"networkid,omitempty"`
} `json:"nic,omitempty"`
Projectid string `json:"projectid,omitempty"`
Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
Hostid string `json:"hostid,omitempty"`
State string `json:"state,omitempty"`
Guestmacaddress string `json:"guestmacaddress,omitempty"`
Scriptsversion string `json:"scriptsversion,omitempty"`
Ip6dns2 string `json:"ip6dns2,omitempty"`
Guestnetmask string `json:"guestnetmask,omitempty"`
Created string `json:"created,omitempty"`
Isredundantrouter bool `json:"isredundantrouter,omitempty"`
Publicip string `json:"publicip,omitempty"`
Name string `json:"name,omitempty"`
Templateid string `json:"templateid,omitempty"`
Requiresupgrade bool `json:"requiresupgrade,omitempty"`
Serviceofferingname string `json:"serviceofferingname,omitempty"`
Guestipaddress string `json:"guestipaddress,omitempty"`
Hostname string `json:"hostname,omitempty"`
Id string `json:"id,omitempty"`