Move dummyLinkExists into createDummyLink
Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
This commit is contained in:
parent
ddd22a8198
commit
d22824dc11
|
@ -97,16 +97,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
if !parentExists(config.Parent) {
|
if !parentExists(config.Parent) {
|
||||||
// if the --internal flag is set, create a dummy link
|
// if the --internal flag is set, create a dummy link
|
||||||
if config.Internal {
|
if config.Internal {
|
||||||
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
|
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
||||||
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
config.CreatedSlaveLink = true
|
|
||||||
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Dummy Link %s for ipvlan already exists", getDummyName(stringid.TruncateID(config.ID)))
|
|
||||||
}
|
}
|
||||||
|
config.CreatedSlaveLink = true
|
||||||
|
|
||||||
// notify the user in logs they have limited communications
|
// notify the user in logs they have limited communications
|
||||||
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
||||||
|
@ -116,17 +111,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
} else {
|
} else {
|
||||||
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
|
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
|
||||||
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
||||||
if !vlanLinkExists(config.Parent) {
|
err := createVlanLink(config.Parent)
|
||||||
err := createVlanLink(config.Parent)
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
// if driver created the networks slave link, record it for future deletion
|
|
||||||
config.CreatedSlaveLink = true
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
|
|
||||||
}
|
}
|
||||||
|
// if driver created the networks slave link, record it for future deletion
|
||||||
|
config.CreatedSlaveLink = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundExisting {
|
if !foundExisting {
|
||||||
|
|
|
@ -81,6 +81,11 @@ func vlanLinkExists(linkStr string) bool {
|
||||||
|
|
||||||
// createVlanLink parses sub-interfaces and vlan id for creation
|
// createVlanLink parses sub-interfaces and vlan id for creation
|
||||||
func createVlanLink(parentName string) error {
|
func createVlanLink(parentName string) error {
|
||||||
|
if vlanLinkExists(parentName) {
|
||||||
|
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Contains(parentName, ".") {
|
if strings.Contains(parentName, ".") {
|
||||||
parent, vidInt, err := parseVlan(parentName)
|
parent, vidInt, err := parseVlan(parentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -176,6 +181,11 @@ func dummyLinkExists(dummyName string) bool {
|
||||||
|
|
||||||
// createDummyLink creates a dummy0 parent link
|
// createDummyLink creates a dummy0 parent link
|
||||||
func createDummyLink(dummyName, truncNetID string) error {
|
func createDummyLink(dummyName, truncNetID string) error {
|
||||||
|
// check if dummyLinkExists and return if it does
|
||||||
|
if dummyLinkExists(truncNetID) {
|
||||||
|
logrus.Debugf("Dummy Link %s for ipvlan already exists", truncNetID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// create a parent interface since one was not specified
|
// create a parent interface since one was not specified
|
||||||
parent := &netlink.Dummy{
|
parent := &netlink.Dummy{
|
||||||
LinkAttrs: netlink.LinkAttrs{
|
LinkAttrs: netlink.LinkAttrs{
|
||||||
|
|
|
@ -102,15 +102,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
if !parentExists(config.Parent) {
|
if !parentExists(config.Parent) {
|
||||||
// if the --internal flag is set, create a dummy link
|
// if the --internal flag is set, create a dummy link
|
||||||
if config.Internal {
|
if config.Internal {
|
||||||
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
|
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
||||||
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
|
if err != nil {
|
||||||
if err != nil {
|
return false, err
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
config.CreatedSlaveLink = true
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", getDummyName(stringid.TruncateID(config.ID)))
|
|
||||||
}
|
}
|
||||||
|
config.CreatedSlaveLink = true
|
||||||
// notify the user in logs they have limited communications
|
// notify the user in logs they have limited communications
|
||||||
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
|
||||||
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
|
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
|
||||||
|
@ -119,19 +115,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
|
||||||
} else {
|
} else {
|
||||||
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
|
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
|
||||||
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
||||||
|
err := createVlanLink(config.Parent)
|
||||||
if !vlanLinkExists(config.Parent) {
|
if err != nil {
|
||||||
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
|
return false, err
|
||||||
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
|
|
||||||
err := createVlanLink(config.Parent)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
// if driver created the networks slave link, record it for future deletion
|
|
||||||
config.CreatedSlaveLink = true
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
|
|
||||||
}
|
}
|
||||||
|
// if driver created the networks slave link, record it for future deletion
|
||||||
|
config.CreatedSlaveLink = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundExisting {
|
if !foundExisting {
|
||||||
|
|
|
@ -85,6 +85,10 @@ func vlanLinkExists(linkStr string) bool {
|
||||||
|
|
||||||
// createVlanLink parses sub-interfaces and vlan id for creation
|
// createVlanLink parses sub-interfaces and vlan id for creation
|
||||||
func createVlanLink(parentName string) error {
|
func createVlanLink(parentName string) error {
|
||||||
|
if vlanLinkExists(parentName) {
|
||||||
|
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if strings.Contains(parentName, ".") {
|
if strings.Contains(parentName, ".") {
|
||||||
parent, vidInt, err := parseVlan(parentName)
|
parent, vidInt, err := parseVlan(parentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,6 +184,10 @@ func dummyLinkExists(dummyName string) bool {
|
||||||
|
|
||||||
// createDummyLink creates a dummy0 parent link
|
// createDummyLink creates a dummy0 parent link
|
||||||
func createDummyLink(dummyName, truncNetID string) error {
|
func createDummyLink(dummyName, truncNetID string) error {
|
||||||
|
if dummyLinkExists(truncNetID) {
|
||||||
|
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", truncNetID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// create a parent interface since one was not specified
|
// create a parent interface since one was not specified
|
||||||
parent := &netlink.Dummy{
|
parent := &netlink.Dummy{
|
||||||
LinkAttrs: netlink.LinkAttrs{
|
LinkAttrs: netlink.LinkAttrs{
|
||||||
|
|
Loading…
Reference in New Issue