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