mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
libnetwork: ipvlan: reduce use of const for driver name
Inlining the string makes the code more grep'able; renaming the const to "driverName" to reflect the remaining uses of it. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
dddb4d25d2
commit
aca80d1cda
4 changed files with 14 additions and 13 deletions
|
@ -18,7 +18,7 @@ const (
|
||||||
containerVethPrefix = "eth"
|
containerVethPrefix = "eth"
|
||||||
vethPrefix = "veth"
|
vethPrefix = "veth"
|
||||||
|
|
||||||
ipvlanType = "ipvlan" // driver type name
|
driverName = "ipvlan" // driver type name
|
||||||
parentOpt = "parent" // parent interface -o parent
|
parentOpt = "parent" // parent interface -o parent
|
||||||
driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode
|
driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode
|
||||||
driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag
|
driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag
|
||||||
|
@ -75,7 +75,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return dc.RegisterDriver(ipvlanType, d, c)
|
return dc.RegisterDriver(driverName, d, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
|
func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
|
||||||
|
@ -91,7 +91,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) Type() string {
|
func (d *driver) Type() string {
|
||||||
return ipvlanType
|
return driverName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) IsBuiltIn() bool {
|
func (d *driver) IsBuiltIn() bool {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
||||||
return fmt.Errorf("network id %q not found", nid)
|
return fmt.Errorf("network id %q not found", nid)
|
||||||
}
|
}
|
||||||
if ifInfo.MacAddress() != nil {
|
if ifInfo.MacAddress() != nil {
|
||||||
return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType)
|
return fmt.Errorf("ipvlan interfaces do not support custom mac address assignment")
|
||||||
}
|
}
|
||||||
ep := &endpoint{
|
ep := &endpoint{
|
||||||
id: eid,
|
id: eid,
|
||||||
|
@ -42,7 +42,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
||||||
if opt, ok := epOptions[netlabel.PortMap]; ok {
|
if opt, ok := epOptions[netlabel.PortMap]; ok {
|
||||||
if _, ok := opt.([]types.PortBinding); ok {
|
if _, ok := opt.([]types.PortBinding); ok {
|
||||||
if len(opt.([]types.PortBinding)) > 0 {
|
if len(opt.([]types.PortBinding)) > 0 {
|
||||||
logrus.Warnf("%s driver does not support port mappings", ipvlanType)
|
logrus.Warnf("ipvlan driver does not support port mappings")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
||||||
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
|
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
|
||||||
if _, ok := opt.([]types.TransportPort); ok {
|
if _, ok := opt.([]types.TransportPort); ok {
|
||||||
if len(opt.([]types.TransportPort)) > 0 {
|
if len(opt.([]types.TransportPort)) > 0 {
|
||||||
logrus.Warnf("%s driver does not support port exposures", ipvlanType)
|
logrus.Warnf("ipvlan driver does not support port exposures")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
|
||||||
defer osl.InitOSContext()()
|
defer osl.InitOSContext()()
|
||||||
kv, err := kernel.GetKernelVersion()
|
kv, err := kernel.GetKernelVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err)
|
return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err)
|
||||||
}
|
}
|
||||||
// ensure Kernel version is >= v4.2 for ipvlan support
|
// ensure Kernel version is >= v4.2 for ipvlan support
|
||||||
if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) {
|
if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) {
|
||||||
|
@ -52,6 +52,7 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
|
||||||
if foundExisting {
|
if foundExisting {
|
||||||
return types.InternalMaskableErrorf("restoring existing network %s", config.ID)
|
return types.InternalMaskableErrorf("restoring existing network %s", config.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update persistent db, rollback on fail
|
// update persistent db, rollback on fail
|
||||||
err = d.storeUpdate(config)
|
err = d.storeUpdate(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,7 +88,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
}
|
}
|
||||||
config.CreatedSlaveLink = true
|
config.CreatedSlaveLink = true
|
||||||
|
|
||||||
// notify the user in logs they have limited communications
|
// notify the user in logs that they have limited communications
|
||||||
logrus.Debugf("Empty -o parent= flags limit communications to other containers inside of network: %s",
|
logrus.Debugf("Empty -o parent= flags limit communications to other containers inside of network: %s",
|
||||||
config.Parent)
|
config.Parent)
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,7 +116,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
return foundExisting, nil
|
return foundExisting, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteNetwork the network for the specified driver type
|
// DeleteNetwork deletes the network for the specified driver type
|
||||||
func (d *driver) DeleteNetwork(nid string) error {
|
func (d *driver) DeleteNetwork(nid string) error {
|
||||||
defer osl.InitOSContext()()
|
defer osl.InitOSContext()()
|
||||||
n := d.network(nid)
|
n := d.network(nid)
|
||||||
|
@ -164,7 +165,7 @@ func (d *driver) DeleteNetwork(nid string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseNetworkOptions parse docker network options
|
// parseNetworkOptions parses docker network options
|
||||||
func parseNetworkOptions(id string, option options.Generic) (*configuration, error) {
|
func parseNetworkOptions(id string, option options.Generic) (*configuration, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -38,7 +38,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
|
||||||
// Get the link for the master index (Example: the docker host eth iface)
|
// Get the link for the master index (Example: the docker host eth iface)
|
||||||
parentLink, err := ns.NlHandle().LinkByName(parent)
|
parentLink, err := ns.NlHandle().LinkByName(parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, parent, err)
|
return "", fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", parent, err)
|
||||||
}
|
}
|
||||||
// Create an ipvlan link
|
// Create an ipvlan link
|
||||||
ipvlan := &netlink.IPVlan{
|
ipvlan := &netlink.IPVlan{
|
||||||
|
@ -51,7 +51,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
|
||||||
}
|
}
|
||||||
if err := ns.NlHandle().LinkAdd(ipvlan); err != nil {
|
if err := ns.NlHandle().LinkAdd(ipvlan); err != nil {
|
||||||
// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
|
// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
|
||||||
return "", fmt.Errorf("failed to create the %s port: %v", ipvlanType, err)
|
return "", fmt.Errorf("failed to create the ipvlan port: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipvlan.Attrs().Name, nil
|
return ipvlan.Attrs().Name, nil
|
||||||
|
@ -190,7 +190,7 @@ func createDummyLink(dummyName, truncNetID string) error {
|
||||||
}
|
}
|
||||||
parentDummyLink, err := ns.NlHandle().LinkByName(dummyName)
|
parentDummyLink, err := ns.NlHandle().LinkByName(dummyName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, dummyName, err)
|
return fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", dummyName, err)
|
||||||
}
|
}
|
||||||
// bring the new netlink iface up
|
// bring the new netlink iface up
|
||||||
if err := ns.NlHandle().LinkSetUp(parentDummyLink); err != nil {
|
if err := ns.NlHandle().LinkSetUp(parentDummyLink); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue