@@ -28,19 +28,19 @@ import (
28
28
29
29
"github.com/coreos/etcd/clientv3"
30
30
"github.com/docker/docker/api/types/versions"
31
- "google.golang.org/grpc"
32
- "google.golang.org/grpc/credentials"
33
-
34
31
"go.ligato.io/cn-infra/v2/db/keyval"
35
32
"go.ligato.io/cn-infra/v2/db/keyval/etcd"
36
33
"go.ligato.io/cn-infra/v2/logging"
37
34
"go.ligato.io/cn-infra/v2/logging/logrus"
35
+ "google.golang.org/grpc"
36
+ "google.golang.org/grpc/credentials"
38
37
39
38
"go.ligato.io/vpp-agent/v3/client"
40
39
"go.ligato.io/vpp-agent/v3/client/remoteclient"
41
40
"go.ligato.io/vpp-agent/v3/cmd/agentctl/api"
42
41
"go.ligato.io/vpp-agent/v3/cmd/agentctl/api/types"
43
42
"go.ligato.io/vpp-agent/v3/pkg/debug"
43
+ "go.ligato.io/vpp-agent/v3/proto/ligato/configurator"
44
44
)
45
45
46
46
const (
@@ -107,16 +107,13 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
107
107
grpcPort : DefaultPortGRPC ,
108
108
httpPort : DefaultPortHTTP ,
109
109
}
110
-
111
110
for _ , op := range ops {
112
111
if err := op (c ); err != nil {
113
112
return nil , err
114
113
}
115
114
}
116
-
117
115
c .grpcAddr = net .JoinHostPort (c .host , strconv .Itoa (c .grpcPort ))
118
116
c .httpAddr = net .JoinHostPort (c .host , strconv .Itoa (c .httpPort ))
119
-
120
117
return c , nil
121
118
}
122
119
@@ -155,15 +152,23 @@ func (c *Client) GRPCConn() (*grpc.ClientConn, error) {
155
152
return c .grpcClient , nil
156
153
}
157
154
158
- // ConfigClient returns "remoteclient" with gRPC connection.
159
- func (c * Client ) ConfigClient () (client.ConfigClient , error ) {
155
+ func (c * Client ) GenericClient () (client.GenericClient , error ) {
160
156
conn , err := c .GRPCConn ()
161
157
if err != nil {
162
158
return nil , err
163
159
}
164
160
return remoteclient .NewClientGRPC (conn ), nil
165
161
}
166
162
163
+ // ConfiguratorClient returns "confi" with gRPC connection.
164
+ func (c * Client ) ConfiguratorClient () (configurator.ConfiguratorServiceClient , error ) {
165
+ conn , err := c .GRPCConn ()
166
+ if err != nil {
167
+ return nil , err
168
+ }
169
+ return configurator .NewConfiguratorServiceClient (conn ), nil
170
+ }
171
+
167
172
// HTTPClient returns configured HTTP client.
168
173
func (c * Client ) HTTPClient () * http.Client {
169
174
if c .httpClient == nil {
@@ -231,35 +236,32 @@ func (c *Client) getAPIPath(ctx context.Context, p string, query url.Values) str
231
236
232
237
func (c * Client ) NegotiateAPIVersion (ctx context.Context ) {
233
238
if ! c .manualOverride {
234
- ping , _ := c .Ping (ctx )
235
- c .negotiateAPIVersionPing (ping )
239
+ version , _ := c .AgentVersion (ctx )
240
+ c .negotiateAPIVersionPing (version )
236
241
}
237
242
}
238
243
239
- func (c * Client ) NegotiateAPIVersionPing (p types.Ping ) {
244
+ func (c * Client ) NegotiateAPIVersionPing (p * types.Version ) {
240
245
if ! c .manualOverride {
241
246
c .negotiateAPIVersionPing (p )
242
247
}
243
248
}
244
249
245
250
// negotiateAPIVersionPing queries the API and updates the version to match the
246
251
// API version. Any errors are silently ignored.
247
- func (c * Client ) negotiateAPIVersionPing (p types.Ping ) {
252
+ func (c * Client ) negotiateAPIVersionPing (p * types.Version ) {
248
253
// try the latest version before versioning headers existed
249
254
if p .APIVersion == "" {
250
255
p .APIVersion = "0.1"
251
256
}
252
-
253
257
// if the client is not initialized with a version, start with the latest supported version
254
258
if c .version == "" {
255
259
c .version = api .DefaultVersion
256
260
}
257
-
258
261
// if server version is lower than the client version, downgrade
259
262
if versions .LessThan (p .APIVersion , c .version ) {
260
263
c .version = p .APIVersion
261
264
}
262
-
263
265
// Store the results, so that automatic API version negotiation (if enabled)
264
266
// won't be performed on the next request.
265
267
if c .negotiateVersion {
@@ -272,9 +274,7 @@ func connectGrpc(addr string, tc *tls.Config) (*grpc.ClientConn, error) {
272
274
if tc != nil {
273
275
dialOpt = grpc .WithTransportCredentials (credentials .NewTLS (tc ))
274
276
}
275
-
276
277
logging .Debugf ("dialing grpc address: %v" , addr )
277
-
278
278
return grpc .Dial (addr , dialOpt )
279
279
}
280
280
@@ -285,12 +285,10 @@ func connectEtcd(endpoints []string, dialTimeout time.Duration, tc *tls.Config)
285
285
} else {
286
286
log .SetLevel (logging .WarnLevel )
287
287
}
288
-
289
288
dt := defaultEtcdDialTimeout
290
289
if dialTimeout != 0 {
291
290
dt = dialTimeout
292
291
}
293
-
294
292
cfg := etcd.ClientConfig {
295
293
Config : & clientv3.Config {
296
294
Endpoints : endpoints ,
@@ -299,7 +297,6 @@ func connectEtcd(endpoints []string, dialTimeout time.Duration, tc *tls.Config)
299
297
},
300
298
OpTimeout : defaultEtcdOpTimeout ,
301
299
}
302
-
303
300
kvdb , err := etcd .NewEtcdConnectionWithBytes (cfg , log )
304
301
if err != nil {
305
302
return nil , err
0 commit comments