Skip to content

Commit

Permalink
start two cns servers
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Mar 19, 2024
1 parent f8e451d commit da26897
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 161 deletions.
24 changes: 12 additions & 12 deletions cnm/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (plugin *ipamPlugin) getCapabilities(w http.ResponseWriter, r *http.Request
RequiresRequestReplay: requiresRequestReplay,
}

err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -135,7 +135,7 @@ func (plugin *ipamPlugin) getDefaultAddressSpaces(w http.ResponseWriter, r *http
resp.LocalDefaultAddressSpace = localId
resp.GlobalDefaultAddressSpace = globalId

err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -145,7 +145,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
var req RequestPoolRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -163,7 +163,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
poolId = ipam.NewAddressPoolId(req.AddressSpace, poolId, "").String()
resp := RequestPoolResponse{PoolID: poolId, Pool: subnet, Data: data}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -173,7 +173,7 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
var req ReleasePoolRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -195,7 +195,7 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
// Encode response.
resp := ReleasePoolResponse{}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -205,7 +205,7 @@ func (plugin *ipamPlugin) getPoolInfo(w http.ResponseWriter, r *http.Request) {
var req GetPoolInfoRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -234,7 +234,7 @@ func (plugin *ipamPlugin) getPoolInfo(w http.ResponseWriter, r *http.Request) {
resp.UnhealthyAddresses = append(resp.UnhealthyAddresses, addr.String())
}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -244,7 +244,7 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
var req RequestAddressRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand Down Expand Up @@ -275,7 +275,7 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
data := make(map[string]string)
resp := RequestAddressResponse{Address: addr, Data: data}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
Expand All @@ -285,7 +285,7 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
var req ReleaseAddressRequest

// Decode request.
err := plugin.Listener.Decode(w, r, &req)
err := common.Decode(w, r, &req)
log.Request(plugin.Name, &req, err)
if err != nil {
return
Expand All @@ -307,7 +307,7 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
// Encode response.
resp := ReleaseAddressResponse{}

err = plugin.Listener.Encode(w, &resp)
err = common.Encode(w, &resp)

log.Response(plugin.Name, &resp, returnCode, returnStr, err)
}
4 changes: 2 additions & 2 deletions cnm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ func (plugin *Plugin) activate(w http.ResponseWriter, r *http.Request) {
log.Request(plugin.Name, &req, nil)

resp := ActivateResponse{Implements: plugin.Listener.GetEndpoints()}
err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, 0, "Success", err)
}

// SendErrorResponse sends and logs an error response.
func (plugin *Plugin) SendErrorResponse(w http.ResponseWriter, errMsg error) {
resp := errorResponse{errMsg.Error()}
err := plugin.Listener.Encode(w, &resp)
err := common.Encode(w, &resp)

log.Response(plugin.Name, &resp, 0, "Success", err)
}
15 changes: 8 additions & 7 deletions cns/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ type ServiceAPI interface {

// ServiceConfig specifies common configuration.
type ServiceConfig struct {
Name string
Version string
Listener *acn.Listener
ErrChan chan<- error
Store store.KeyValueStore
ChannelMode string
TlsSettings tls.TlsSettings
Name string
Version string
Listener *acn.Listener
ErrChan chan<- error
Store store.KeyValueStore
PrimaryInterfaceIP string
ChannelMode string
TLSSettings tls.TlsSettings
}

// NewService creates a new Service object.
Expand Down
Loading

0 comments on commit da26897

Please sign in to comment.