/
ifupdown_vlan.go
57 lines (45 loc) · 1.21 KB
/
ifupdown_vlan.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
package main
import (
"context"
pb "github.com/0xef53/kvmrun/api/services/network/v1"
)
type vlanSchemeOptions struct {
VlanID uint32 `json:"vlan_id"`
MTU uint32 `json:"mtu"`
}
type vlanScheme struct {
linkname string
opts *vlanSchemeOptions
}
func (sc *vlanScheme) Configure(client pb.NetworkServiceClient, secondStage bool) error {
req := pb.ConfigureRequest{
LinkName: sc.linkname,
Attrs: &pb.ConfigureRequest_Vlan{
Vlan: &pb.ConfigureRequest_VlanAttrs{
VlanID: sc.opts.VlanID,
MTU: sc.opts.MTU,
},
},
SecondStage: secondStage,
}
if _, err := client.Configure(context.Background(), &req); err != nil {
return err
}
Info.Printf("successfully configured: %s, vlan_id=%d, mtu=%d\n", sc.linkname, sc.opts.VlanID, sc.opts.MTU)
return nil
}
func (sc *vlanScheme) Deconfigure(client pb.NetworkServiceClient) error {
req := pb.DeconfigureRequest{
LinkName: sc.linkname,
Attrs: &pb.DeconfigureRequest_Vlan{
Vlan: &pb.DeconfigureRequest_VlanAttrs{
VlanID: sc.opts.VlanID,
},
},
}
if _, err := client.Deconfigure(context.Background(), &req); err != nil {
return err
}
Info.Printf("successfully deconfigured: %s, vlan_id=%d\n", sc.linkname, sc.opts.VlanID)
return nil
}