-
Notifications
You must be signed in to change notification settings - Fork 16
/
vswitch.go
45 lines (38 loc) · 1.27 KB
/
vswitch.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
package server
import (
"context"
pb "yunion.io/x/sdnagent/pkg/agent/proto"
"github.com/digitalocean/go-openvswitch/ovs"
)
type vSwitchService struct {
agent *AgentServer
vSwitchCli *ovs.VSwitchService
}
func newVSwitchService(agent *AgentServer) *vSwitchService {
return &vSwitchService{
agent: agent,
vSwitchCli: ovs.New().VSwitch,
}
}
func (s *vSwitchService) newResponse(err error) *pb.Response {
if err == nil {
return &pb.Response{Code: 0, Mesg: "ok"}
}
return &pb.Response{Code: 1, Mesg: err.Error()}
}
func (s *vSwitchService) AddBridge(ctx context.Context, in *pb.AddBridgeRequest) (*pb.Response, error) {
err := s.vSwitchCli.AddBridge(in.Bridge)
return s.newResponse(err), nil
}
func (s *vSwitchService) DelBridge(ctx context.Context, in *pb.DelBridgeRequest) (*pb.Response, error) {
err := s.vSwitchCli.DeleteBridge(in.Bridge)
return s.newResponse(err), nil
}
func (s *vSwitchService) AddBridgePort(ctx context.Context, in *pb.AddBridgePortRequest) (*pb.Response, error) {
err := s.vSwitchCli.AddPort(in.Bridge, in.Port)
return s.newResponse(err), nil
}
func (s *vSwitchService) DelBridgePort(ctx context.Context, in *pb.DelBridgePortRequest) (*pb.Response, error) {
err := s.vSwitchCli.DeletePort(in.Bridge, in.Port)
return s.newResponse(err), nil
}