service CNIserver {
// Process CNI message
+ rpc CNIconfig (ConfPath) returns (CNIerror) {}
+
rpc CNIop (CNImsg) returns (CNIresult) {
option (google.api.http) = {
post: "/1/cni"
body: "*"
};
}
+
+ rpc CNIadd (CNIaddMsg) returns (ADDresult) {
+ option (google.api.http) = {
+ post: "/1/add"
+ body: "*"
+ };
+ }
+}
+
+message CNIerror {
+ string error = 1;
}
enum CmdType {
// { "hostPort": 9090, "containerPort": 90, "protocol": "tcp" }
// ]
+message PortMapMsg {
+
+ message PORTMAPPINGS {
+ double hostPort = 1;
+ double containerPort = 2;
+ string protocol = 3;
+ }
+
+ repeated PORTMAPPINGS portMappings = 1;
+}
+
message CNIcapArgs {
- string name = 1;
- string value = 2;
+ repeated PortMapMsg portMap = 1;
}
message ConfPath {
string stdOut = 3;
}
+message CNIaddMsg {
+ string conf = 1;
+ string containerID = 2;
+ string netNS = 3;
+ string ifName = 4;
+ string cniArgs = 5;
+ repeated CNIcapArgs capArgs = 6;
+}
+
+message ADDresult {
+ string error = 2;
+ string stdOut = 3;
+}
+
+message CNIcheckMsg {
+ string conf = 1;
+ string containerID = 2;
+ string netNS = 3;
+ string ifName = 4;
+ string cniArgs = 5;
+ repeated CNIcapArgs capArgs = 6;
+}
+
+message CNIdelMsg {
+ string conf =1;
+ string containerID = 2;
+ string netNS = 3;
+ string ifName = 4;
+ string cniArgs = 5;
+ repeated CNIcapArgs capArgs = 6;
+}
+
type CNIServer struct {
}
+func (s *CNIServer) CNIconfig(ctx context.Context, confPath *ConfPath) (*CNIerror, error) {
+
+ cniError := CNIerror{}
+
+ if confPath != nil {
+ if confPath.NetDir != "" {
+ log.Printf("Receive message NetDir: %s", confPath.NetDir)
+ }
+ if confPath.NetConf != "" {
+ log.Printf("Receive message NetConf: %s", confPath.NetConf)
+ }
+ }
+
+ log.Printf("Response from server: %v", cniError)
+ return &cniError, nil
+}
+
// CNIop generates result to a CNImsg
func (s *CNIServer) CNIop(ctx context.Context, in *CNImsg) (*CNIresult, error) {
return &cniResult, nil
}
+// CNIadd generates result to a CNImsg
+func (s *CNIServer) CNIadd(ctx context.Context, in *CNIaddMsg) (*ADDresult, error) {
+
+ log.Printf("Receive message Conf file: %s", in.Conf)
+
+ log.Printf("Receive message ContainerID: %s", in.ContainerID)
+ log.Printf("Receive message NetNS: %s", in.NetNS)
+ log.Printf("Receive message IfName: %s", in.IfName)
+ log.Printf("Receive message CniArgs: %s", in.CniArgs)
+
+ cniResult := ADDresult{
+ StdOut: "stdOutStringHere",
+ }
+
+ log.Printf("Response from server: %s", cniResult.StdOut)
+ return &cniResult, nil
+}
}
log.Printf("Response from TCP server: %s", result.StdOut)
+ // Now use add version of .proto
+ cniAddMsg := api.CNIaddMsg{
+ Conf: cniPath.NetConf,
+ ContainerID: "containerOne",
+ NetNS: "mcc-test-0",
+ IfName: "ensX",
+ CniArgs: "IgnoreUnknown=1;IP=10.1.0.20",
+
+ }
+ resultAdd, err := cni.CNIadd(context.Background(), &cniAddMsg)
+ if err != nil {
+ log.Fatalf("error when calling CNIadd: %s", err)
+ return err
+ }
+ log.Printf("Response from TCP server: %s", resultAdd.StdOut)
+
+
return nil
}