From debba41487b2c1ce3182988f7c47d8a0cf44e542 Mon Sep 17 00:00:00 2001 From: Michael Cambria Date: Wed, 17 Apr 2019 16:48:02 -0400 Subject: [PATCH] add CNIcheckMsg and CNIdelMsg --- api/api.proto | 26 ++++++++++++++++++++++++-- api/handler.go | 37 ++++++++++++++++++++++++++++++++++++- using-curl.txt | 6 +++--- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/api/api.proto b/api/api.proto index 7578e5d..cb50e81 100644 --- a/api/api.proto +++ b/api/api.proto @@ -20,6 +20,20 @@ service CNIserver { body: "*" }; } + + rpc CNIcheck (CNIcheckMsg) returns (CHECKresult) { + option (google.api.http) = { + post: "/1/check" + body: "*" + }; + } + + rpc CNIdel (CNIdelMsg) returns (DELresult) { + option (google.api.http) = { + post: "/1/del" + body: "*" + }; + } } message CNIerror { @@ -87,8 +101,8 @@ message CNIaddMsg { } message ADDresult { - string error = 2; - string stdOut = 3; + string error = 1; + string stdOut = 2; } message CNIcheckMsg { @@ -100,6 +114,10 @@ message CNIcheckMsg { repeated CNIcapArgs capArgs = 6; } +message CHECKresult { + string error = 1; +} + message CNIdelMsg { string conf =1; string containerID = 2; @@ -109,3 +127,7 @@ message CNIdelMsg { repeated CNIcapArgs capArgs = 6; } +message DELresult { + string error = 1; + string stdOut = 2; +} diff --git a/api/handler.go b/api/handler.go index 4840479..882459d 100644 --- a/api/handler.go +++ b/api/handler.go @@ -56,7 +56,7 @@ func (s *CNIServer) CNIop(ctx context.Context, in *CNImsg) (*CNIresult, error) { return &cniResult, nil } -// CNIadd generates result to a CNImsg +// CNIadd generates result to a CNIaddMsg func (s *CNIServer) CNIadd(ctx context.Context, in *CNIaddMsg) (*ADDresult, error) { log.Printf("Receive message Conf file: %s", in.Conf) @@ -74,3 +74,38 @@ func (s *CNIServer) CNIadd(ctx context.Context, in *CNIaddMsg) (*ADDresult, erro return &cniResult, nil } +// CNIcheck generates result to a CNIcheckMsg +func (s *CNIServer) CNIcheck(ctx context.Context, in *CNIcheckMsg) (*CHECKresult, 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 := CHECKresult{ + Error: "", + } + + log.Printf("Response from server: %s", cniResult.Error) + return &cniResult, nil +} + +// CNIdel generates result to a CNIdelMsg +func (s *CNIServer) CNIdel(ctx context.Context, in *CNIdelMsg) (*DELresult, 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 := DELresult{ + StdOut: "stdOutStringHere", + } + + log.Printf("Response from server: %s", cniResult.StdOut) + return &cniResult, nil +} diff --git a/using-curl.txt b/using-curl.txt index e7217f4..fcfa253 100644 --- a/using-curl.txt +++ b/using-curl.txt @@ -5,10 +5,10 @@ curl -H "login:john" -H "password:doe" -X POST 'http://localhost:7778/1/cni' -d Use these: -curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/cni' -d @add-cmd.json +curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/add' -d @add-cmd.json -curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/cni' -d @check-cmd.json +curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/check' -d @check-cmd.json -curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/cni' -d @del-cmd.json +curl -H "login:john" -H "password:doe" --header "Content-Type: application/json" -X POST 'http://localhost:7778/1/del' -d @del-cmd.json -- 2.44.0