设为首页 收藏本站
查看: 995|回复: 0

[经验分享] Docker Libnetwork driver API

[复制链接]

尚未签到

发表于 2017-12-6 15:20:12 | 显示全部楼层 |阅读模式
  以下内容均在libnetwork/driverapi目录下
  Driver接口如下所示:



// Driver is an interface that every plugin driver needs to implement.
type Driver interface {
  discoverapi.Discover
  // NetworkAllocate invokes the driver method to allocate network
  // specific resources passing network id and network specific config.
  // It returns a key, value pair of network specific driver allocations
  // to the caller.
  NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error)
  // NetworkFree invokes the driver method to free network specific resources
  // associated with a given network id.
  NetworkFree(nid string) error

  // CreateNetwork invokes the driver method to create a network
  // passing the network id and network specific config. The
  // config mechanism will eventually be replaced with labels
  // which are yet to be introduced. The driver can return a
  // list of table names for which it is interested in receiving
  // notification when a CRUD operation is performed on any
  // entry in that table. This will be ignored for local scope drivers.
  CreateNetwork(nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error

  // DeleteNetwork invokes the driver method to delete network passing
  // the network id.
  DeleteNetwork(nid string) error
  // CreateEndpoint invokes the driver method to create an endpoint
  // passing the network id, endpoint id endpoint information and driver
  // specific config. The endpoint information can be either consumed by
  // the driver or populated by the driver. The config mechanism will
  // eventually be replaced with labels which are yet to be introducd.
  CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
  // DeleteEndpoint invokes the driver method to delete an endpoint
  // passing the network id and endpoint id.
  DeleteEndpoint(nid, eid string) error
  // EndpointOperInfo retrieves from the driver the operational data related to the specific endpoint
  EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  // Join method is invoked when a Sandbox is attached to an endpoint.
  Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  // Leave method is invoked when a Sandbox detaches from an endpoint.
  Leave(nid, eid string) error
  // ProgramExternalConnectivity invokes the driver method which does the necessary
  // programming to allow the external connectivity dictated by the passed options.
  ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
  // RevokeExternalConnectivity asks the driver to remove any external connectivity
  // programming that was done so far
  RevokeExternalConnectivity(nid, eid string) error
  // EventNotify notifies the driver when a CRUD operation has
  // happended on a table of its interest as soon as this node
  // receives such an event in the gossip layer. This method is
  // only invoked for the global scope driver.
  EventNotify(event EventType, nid string, tableName string, key string, value []byte)
  // Type returns the type of this driver, the network type this driver manages.
  Type() string
  // IsBuiltIn returns true if it is a built-in driver
  IsBuiltIn() bool
}

  NetworkInfo接口如下所示:



// NetworkInfo provides a go interface for drivers to provide network
// specific information on libnetwork.
type NetworkInfo interface {
  // TableEventRegister registers driver interest in a given
  // table name.
  TableEventRegister(tableName string) error
}

  InterfaceInfo接口如下所示:



// InterfaceInfo provides a go interface for drivers to retrive
// network information to interface resources.
type InterfaceInfo interface {
  // SetMacAddress allows the driver to set the mac address to the endpoint interface
  // during the call to CreateEndpoint, if the mac address is not already set.
  SetMacAddress(mac net.HardwareAddr) error
  // SetIPAddress allows the driver to set the ip address to the endpoint interface
  // during the call to CreateEndpoint, if the address is not already set.
  // The API is to be used to assign both the IPv4 and IPv6 address types.
  SetIPAddress(ip *net.IPNet) error
  // MacAddress returns the MAC address.
  MacAddress() net.HardwareAddr
  // Address returns the IPv4 address.
  Address() *net.IPNet
  // AddressIPv6 returns the IPv4 address.
  AddressIPv6() *net.IPNet
}

  InterfaceNameInfo接口如下所示:



// InterfaceNameInfo provides a go interface for the drivers to assign names
// to interfaces
type InterfaceNameInfo interface {
  // SetNames method assigns the srcName and dstPrefix for the interface.
  SetNames(srcName, dstPrefix string) error
}

  JoinInfo接口如下所示:



// JoinInfo represents a set of resources that the driver has the ability to provide during
// join time.
type JoinInfo interface {
  // InterfaceName returns an InterfaceNameInfo go interface to facilitate
  // setting the names for the interface.
  InterfaceName() InterfaceNameInfo
  // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  SetGateway(net.IP) error
  // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint
  SetGateway(net.IP) error
  // AddStaticRoute adds a route to the sandbox.
  // It may be used in addition to or instead of a default gateway (as above)
  AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
  // DisableGatewayService tells libnetwork not to provide Default GW for the container
  DisableGatewayService()
  // AddTableEntry adds a table entry to the gossip layer
  // passing the table name, key and an opaque value.
  AddTableEntry(tableName string, key string, value []byte) error
}

  IPAMData结构如下所示



// IPAMData represents the per-network ip related
// operational information libnetwork will send
// to the network driver during CreateNetwork()
type IPAMData struct {
  AddressSpace   string
  Pool        *net.IPNet
  Gateway     *net.IPNet
  AuxAddresses   map[string]*net.IPNet
}

  DriverCallback数据结构如下所示



// DriverCallback provides a Callback interface for Drivers into LibNetwork
type DriverCallback interface{
  // GetPluginGetter returns the pluginv2 getter.
  GetPluginGetter() plugingetter.PluginGetter
  // RegisterDriver provides a way for remote drivers to dynamically register new NetworkType and associate with a driver instance
  RegisterDriver(name string, driver Driver, capability Capability) error
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421360-1-1.html 上篇帖子: spring boot / cloud (十八) 使用docker快速搭建本地环境 下篇帖子: Docker 安装使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表