Merge ~oddbloke/cloud-init/+git/cloud-init:networking into cloud-init:master

Proposed by Dan Watkins
Status: Rejected
Rejected by: Dan Watkins
Proposed branch: ~oddbloke/cloud-init/+git/cloud-init:networking
Merge into: cloud-init:master
Diff against target: 63 lines (+25/-13)
1 file modified
cloudinit/net/__init__.py (+25/-13)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+372289@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

If the interface already has an IP, it may not have anything else that we'd apply after parsing the lease output (routes, etc).

This sort of feels OK in that we skip tearing down when we don't do anything else, but it also seems wrong in that the whole context manager should exit if we don't bring up DHCP.

Revision history for this message
Dan Watkins (oddbloke) wrote :

On Wed, Sep 04, 2019 at 06:30:07PM -0000, Ryan Harper wrote:
> If the interface already has an IP, it may not have anything else that
> we'd apply after parsing the lease output (routes, etc).

If the interface already has an IP before we DHCP, it's not 100% clear
to me that we should consider routes etc. from the DHCP response
applicable.

> This sort of feels OK in that we skip tearing down when we don't do
> anything else, but it also seems wrong in that the whole context
> manager should exit if we don't bring up DHCP.

What do you mean by "should exit" here? The way we use the context
manager (in DataSourceOpenStack, at least), is essentially "ensure I
have network while executing the body", so not needing to configure
networking isn't really an error condition in that usecase.

Revision history for this message
Chad Smith (chad.smith) :

Unmerged commits

c37ec07... by Dan Watkins

[WIP] net: only apply routes if we bring an ephemeral DHCP interface up

TODO:
* Tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index ea707c0..f308d03 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -756,7 +756,11 @@ class EphemeralIPv4Network(object):
756 ' to %s', self.connectivity_url)756 ' to %s', self.connectivity_url)
757 return757 return
758758
759 self._bringup_device()759 device_brought_up = self._bringup_device()
760 if not device_brought_up:
761 # If we didn't bring the device up, no need to do anything else
762 # with it
763 return
760764
761 # rfc3442 requires us to ignore the router config *if* classless static765 # rfc3442 requires us to ignore the router config *if* classless static
762 # routes are provided.766 # routes are provided.
@@ -787,7 +791,13 @@ class EphemeralIPv4Network(object):
787 capture=True)791 capture=True)
788792
789 def _bringup_device(self):793 def _bringup_device(self):
790 """Perform the ip comands to fully setup the device."""794 """
795 Perform the ip comands to fully setup the device.
796
797 :return:
798 True if the device was brought up, False if it already had an
799 address.
800 """
791 cidr = '{0}/{1}'.format(self.ip, self.prefix)801 cidr = '{0}/{1}'.format(self.ip, self.prefix)
792 LOG.debug(802 LOG.debug(
793 'Attempting setup of ephemeral network on %s with %s brd %s',803 'Attempting setup of ephemeral network on %s with %s brd %s',
@@ -803,17 +813,19 @@ class EphemeralIPv4Network(object):
803 LOG.debug(813 LOG.debug(
804 'Skip ephemeral network setup, %s already has address %s',814 'Skip ephemeral network setup, %s already has address %s',
805 self.interface, self.ip)815 self.interface, self.ip)
806 else:816 return False
807 # Address creation success, bring up device and queue cleanup817
808 util.subp(818 # Address creation success, bring up device and queue cleanup
809 ['ip', '-family', 'inet', 'link', 'set', 'dev', self.interface,819 util.subp(
810 'up'], capture=True)820 ['ip', '-family', 'inet', 'link', 'set', 'dev', self.interface,
811 self.cleanup_cmds.append(821 'up'], capture=True)
812 ['ip', '-family', 'inet', 'link', 'set', 'dev', self.interface,822 self.cleanup_cmds.append(
813 'down'])823 ['ip', '-family', 'inet', 'link', 'set', 'dev', self.interface,
814 self.cleanup_cmds.append(824 'down'])
815 ['ip', '-family', 'inet', 'addr', 'del', cidr, 'dev',825 self.cleanup_cmds.append(
816 self.interface])826 ['ip', '-family', 'inet', 'addr', 'del', cidr, 'dev',
827 self.interface])
828 return True
817829
818 def _bringup_static_routes(self):830 def _bringup_static_routes(self):
819 # static_routes = [("169.254.169.254/32", "130.56.248.255"),831 # static_routes = [("169.254.169.254/32", "130.56.248.255"),

Subscribers

People subscribed via source and target branches