Created CNIAddMsg and ADDresults
authorMichael Cambria <mcambria@redhat.com>
Wed, 17 Apr 2019 20:13:21 +0000 (16:13 -0400)
committerMichael Cambria <mcambria@redhat.com>
Wed, 17 Apr 2019 20:13:21 +0000 (16:13 -0400)
api/api.proto
api/handler.go
client/main.go

index d9ac730..7578e5d 100644 (file)
@@ -5,12 +5,25 @@ import "google/api/annotations.proto";
 
 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 {
@@ -25,10 +38,20 @@ 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 {
@@ -54,3 +77,35 @@ message CNIresult {
   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;
+}
+
index a605abf..4840479 100644 (file)
@@ -10,6 +10,23 @@ import (
 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) {
 
@@ -39,4 +56,21 @@ 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
+}
 
index b991231..2466ea4 100644 (file)
@@ -142,6 +142,23 @@ func sendgRPCusingTcp() error {
        }
        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
 }