-
Notifications
You must be signed in to change notification settings - Fork 28
/
ipv6_addr.go
90 lines (73 loc) · 2.06 KB
/
ipv6_addr.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
package client
import (
"github.com/go-routeros/routeros"
)
// Ipv6Address defines resource
type Ipv6Address struct {
Id string `mikrotik:".id" codegen:"id,mikrotikID,terraformID"`
Address string `mikrotik:"address" codegen:"address,required"`
Advertise bool `mikrotik:"advertise" codegen:"advertise"`
Comment string `mikrotik:"comment" codegen:"comment"`
Disabled bool `mikrotik:"disabled" codegen:"disabled"`
Eui64 bool `mikrotik:"eui-64" codegen:"eui_64"`
FromPool string `mikrotik:"from-pool" codegen:"from_pool"`
Interface string `mikrotik:"interface" codegen:"interface,required"`
NoDad bool `mikrotik:"no-dad" codegen:"no_dad"`
}
var _ Resource = (*Ipv6Address)(nil)
func (b *Ipv6Address) ActionToCommand(a Action) string {
return map[Action]string{
Add: "/ipv6/address/add",
Find: "/ipv6/address/print",
Update: "/ipv6/address/set",
Delete: "/ipv6/address/remove",
}[a]
}
func (b *Ipv6Address) IDField() string {
return ".id"
}
func (b *Ipv6Address) ID() string {
return b.Id
}
func (b *Ipv6Address) SetID(id string) {
b.Id = id
}
func (b *Ipv6Address) AfterAddHook(r *routeros.Reply) {
b.Id = r.Done.Map["ret"]
}
// Typed wrappers
func (c Mikrotik) AddIpv6Address(r *Ipv6Address) (*Ipv6Address, error) {
res, err := c.Add(r)
if err != nil {
return nil, err
}
return res.(*Ipv6Address), nil
}
func (c Mikrotik) UpdateIpv6Address(r *Ipv6Address) (*Ipv6Address, error) {
res, err := c.Update(r)
if err != nil {
return nil, err
}
return res.(*Ipv6Address), nil
}
func (c Mikrotik) ListIpv6Address() ([]Ipv6Address, error) {
res, err := c.List(&Ipv6Address{})
if err != nil {
return nil, err
}
returnSlice := make([]Ipv6Address, len(res))
for i, v := range res {
returnSlice[i] = *(v.(*Ipv6Address))
}
return returnSlice, nil
}
func (c Mikrotik) FindIpv6Address(id string) (*Ipv6Address, error) {
res, err := c.Find(&Ipv6Address{Id: id})
if err != nil {
return nil, err
}
return res.(*Ipv6Address), nil
}
func (c Mikrotik) DeleteIpv6Address(id string) error {
return c.Delete(&Ipv6Address{Id: id})
}