1package host
2
3import (
4	"sync"
5
6	"github.com/docker/libnetwork/datastore"
7	"github.com/docker/libnetwork/discoverapi"
8	"github.com/docker/libnetwork/driverapi"
9	"github.com/docker/libnetwork/types"
10)
11
12const networkType = "host"
13
14type driver struct {
15	network string
16	sync.Mutex
17}
18
19// Init registers a new instance of host driver
20func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
21	c := driverapi.Capability{
22		DataScope:         datastore.LocalScope,
23		ConnectivityScope: datastore.LocalScope,
24	}
25	return dc.RegisterDriver(networkType, &driver{}, c)
26}
27
28func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
29	return nil, types.NotImplementedErrorf("not implemented")
30}
31
32func (d *driver) NetworkFree(id string) error {
33	return types.NotImplementedErrorf("not implemented")
34}
35
36func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
37}
38
39func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
40	return "", nil
41}
42
43func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
44	d.Lock()
45	defer d.Unlock()
46
47	if d.network != "" {
48		return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType)
49	}
50
51	d.network = id
52
53	return nil
54}
55
56func (d *driver) DeleteNetwork(nid string) error {
57	return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType)
58}
59
60func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
61	return nil
62}
63
64func (d *driver) DeleteEndpoint(nid, eid string) error {
65	return nil
66}
67
68func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
69	return make(map[string]interface{}, 0), nil
70}
71
72// Join method is invoked when a Sandbox is attached to an endpoint.
73func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
74	return nil
75}
76
77// Leave method is invoked when a Sandbox detaches from an endpoint.
78func (d *driver) Leave(nid, eid string) error {
79	return nil
80}
81
82func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
83	return nil
84}
85
86func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
87	return nil
88}
89
90func (d *driver) Type() string {
91	return networkType
92}
93
94func (d *driver) IsBuiltIn() bool {
95	return true
96}
97
98// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
99func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
100	return nil
101}
102
103// DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
104func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
105	return nil
106}
107