common.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package backend
  15. import (
  16. "github.com/coreos/flannel/Godeps/_workspace/src/golang.org/x/net/context"
  17. "github.com/coreos/flannel/subnet"
  18. )
  19. type SubnetDef struct {
  20. Lease *subnet.Lease
  21. MTU int
  22. }
  23. // Besides the entry points in the Backend interface, the backend's New()
  24. // function receives static network interface information (like internal and
  25. // external IP addresses, MTU, etc) which it should cache for later use if
  26. // needed.
  27. //
  28. // To implement a singleton backend which manages multiple networks, the
  29. // New() function should create the singleton backend object once, and return
  30. // that object on on further calls to New(). The backend is guaranteed that
  31. // the arguments passed via New() will not change across invocations. Also,
  32. // since multiple RegisterNetwork() and Run() calls may be in-flight at any
  33. // given time for a singleton backend, it must protect these calls with a mutex.
  34. type Backend interface {
  35. // Called when the backend should create or begin managing a new network
  36. RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (*SubnetDef, error)
  37. // Called after the backend's first network has been registered to
  38. // allow the plugin to watch dynamic events
  39. Run(ctx context.Context)
  40. }