Updated plugins to use path constants
This commit is contained in:
Родитель
1570d83456
Коммит
c8400962ba
|
@ -88,9 +88,8 @@ func (listener *Listener) GetMux() *http.ServeMux {
|
|||
}
|
||||
|
||||
// Registers a protocol handler.
|
||||
func (listener *Listener) AddHandler(endpoint string, method string, handler func(http.ResponseWriter, *http.Request)) {
|
||||
url := fmt.Sprintf("/%s.%s", endpoint, method)
|
||||
listener.mux.HandleFunc(url, handler)
|
||||
func (listener *Listener) AddHandler(path string, handler func(http.ResponseWriter, *http.Request)) {
|
||||
listener.mux.HandleFunc(path, handler)
|
||||
}
|
||||
|
||||
// Decodes JSON payload.
|
||||
|
|
|
@ -42,7 +42,7 @@ func (plugin *Plugin) Initialize(errChan chan error) error {
|
|||
}
|
||||
|
||||
// Add generic protocol handlers.
|
||||
listener.AddHandler("Plugin", "Activate", plugin.activatePlugin)
|
||||
listener.AddHandler(activatePath, plugin.activate)
|
||||
|
||||
plugin.Listener = listener
|
||||
err = listener.Start(errChan)
|
||||
|
@ -59,8 +59,11 @@ func (plugin *Plugin) Uninitialize() {
|
|||
// Libnetwork remote plugin API
|
||||
//
|
||||
|
||||
func (plugin *Plugin) activatePlugin(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(plugin.Name, "Activate", nil, nil)
|
||||
// Handles Activate requests.
|
||||
func (plugin *Plugin) activate(w http.ResponseWriter, r *http.Request) {
|
||||
var req activateRequest
|
||||
|
||||
log.Request(plugin.Name, "Activate", req, nil)
|
||||
|
||||
resp := &activateResponse{[]string{plugin.EndpointType}}
|
||||
err := plugin.Listener.Encode(w, resp)
|
||||
|
|
|
@ -38,18 +38,18 @@ func NewPlugin(name string, version string) (IpamPlugin, error) {
|
|||
func (plugin *ipamPlugin) Start(errChan chan error) error {
|
||||
err := plugin.Initialize(errChan)
|
||||
if err != nil {
|
||||
log.Printf("%s: Failed to start: %v", err)
|
||||
log.Printf("%s: Failed to start: %v", plugin.Name, err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Add protocol handlers.
|
||||
listener := plugin.Listener
|
||||
listener.AddHandler(endpointType, "GetCapabilities", plugin.getCapabilities)
|
||||
listener.AddHandler(endpointType, "GetDefaultAddressSpaces", plugin.getDefaultAddressSpaces)
|
||||
listener.AddHandler(endpointType, "RequestPool", plugin.requestPool)
|
||||
listener.AddHandler(endpointType, "ReleasePool", plugin.releasePool)
|
||||
listener.AddHandler(endpointType, "RequestAddress", plugin.requestAddress)
|
||||
listener.AddHandler(endpointType, "ReleaseAddress", plugin.releaseAddress)
|
||||
listener.AddHandler(getCapabilitiesPath, plugin.getCapabilities)
|
||||
listener.AddHandler(getAddressSpacesPath, plugin.getDefaultAddressSpaces)
|
||||
listener.AddHandler(requestPoolPath, plugin.requestPool)
|
||||
listener.AddHandler(releasePoolPath, plugin.releasePool)
|
||||
listener.AddHandler(requestAddressPath, plugin.requestAddress)
|
||||
listener.AddHandler(releaseAddressPath, plugin.releaseAddress)
|
||||
|
||||
log.Printf("%s: Plugin started.", plugin.Name)
|
||||
|
||||
|
|
|
@ -52,15 +52,15 @@ func (plugin *netPlugin) Start(errChan chan error) error {
|
|||
}
|
||||
|
||||
// Add protocol handlers.
|
||||
listener.AddHandler("Plugin", "Activate", plugin.activatePlugin)
|
||||
listener.AddHandler(endpointType, "GetCapabilities", plugin.getCapabilities)
|
||||
listener.AddHandler(endpointType, "CreateNetwork", plugin.createNetwork)
|
||||
listener.AddHandler(endpointType, "DeleteNetwork", plugin.deleteNetwork)
|
||||
listener.AddHandler(endpointType, "CreateEndpoint", plugin.createEndpoint)
|
||||
listener.AddHandler(endpointType, "DeleteEndpoint", plugin.deleteEndpoint)
|
||||
listener.AddHandler(endpointType, "Join", plugin.join)
|
||||
listener.AddHandler(endpointType, "Leave", plugin.leave)
|
||||
listener.AddHandler(endpointType, "EndpointOperInfo", plugin.endpointOperInfo)
|
||||
listener.AddHandler("/Plugin.Activate", plugin.activatePlugin)
|
||||
listener.AddHandler(getCapabilitiesPath, plugin.getCapabilities)
|
||||
listener.AddHandler(createNetworkPath, plugin.createNetwork)
|
||||
listener.AddHandler(deleteNetworkPath, plugin.deleteNetwork)
|
||||
listener.AddHandler(createEndpointPath, plugin.createEndpoint)
|
||||
listener.AddHandler(deleteEndpointPath, plugin.deleteEndpoint)
|
||||
listener.AddHandler(joinPath, plugin.join)
|
||||
listener.AddHandler(leavePath, plugin.leave)
|
||||
listener.AddHandler(endpointOperInfoPath, plugin.endpointOperInfo)
|
||||
|
||||
plugin.listener = listener
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче