예제 #1
0
    def set_metadata_ip_route(self, metadata_url):
        """Set a network route if the given metadata url can't be accessed.

        This is a workaround for
           https://bugs.launchpad.net/quantum/+bug/1174657.
        """
        osutils = base.get_osutils()

        if osutils.general.check_os_version(6, 0):
            # 169.254.x.x addresses are not getting routed starting from
            # Windows Vista / 2008
            metadata_netloc = urllib_parse.urlparse(metadata_url).netloc
            metadata_host = metadata_netloc.split(':')[0]

            if not metadata_host.startswith("169.254."):
                return

            routes = self.routes()
            exists_route = any(route.destination == metadata_host
                               for route in routes)
            if not exists_route and not _check_url(metadata_url):
                default_gateway = self.default_gateway()
                if default_gateway:
                    try:
                        LOG.debug('Setting gateway for host: %s',
                                  metadata_host)
                        route = Route(destination=metadata_host,
                                      netmask="255.255.255.255",
                                      gateway=default_gateway.gateway,
                                      interface=None,
                                      metric=None)
                        Route.add(route)
                    except Exception as ex:
                        # Ignore it
                        LOG.exception(ex)
예제 #2
0
    def set_metadata_ip_route(self, metadata_url):
        """Set a network route if the given metadata url can't be accessed.

        This is a workaround for
           https://bugs.launchpad.net/quantum/+bug/1174657.
        """
        osutils = base.get_osutils()

        if osutils.general.check_os_version(6, 0):
            # 169.254.x.x addresses are not getting routed starting from
            # Windows Vista / 2008
            metadata_netloc = urllib_parse.urlparse(metadata_url).netloc
            metadata_host = metadata_netloc.split(':')[0]

            if not metadata_host.startswith("169.254."):
                return

            routes = self.routes()
            exists_route = any(route.destination == metadata_host
                               for route in routes)
            if not exists_route and not _check_url(metadata_url):
                default_gateway = self.default_gateway()
                if default_gateway:
                    try:
                        LOG.debug('Setting gateway for host: %s',
                                  metadata_host)
                        route = Route(
                            destination=metadata_host,
                            netmask="255.255.255.255",
                            gateway=default_gateway.gateway,
                            interface=None, metric=None)
                        Route.add(route)
                    except Exception as ex:
                        # Ignore it
                        LOG.exception(ex)
예제 #3
0
    def _test_getosutils(self, mock_system,
                         mock_linux_distribution, mock_import_module,
                         linux=False):
        if linux:
            os_name = 'Linux'
        else:
            os_name = 'Windows'

        mock_system.return_value = os_name
        mock_linux_distribution.return_value = (os_name, None, None)
        module = base.get_osutils()

        mock_import_module.assert_called_once_with(
            "cloudinit.osys.{0}.base".format(os_name.lower()))
        self.assertEqual(mock_import_module.return_value.OSUtils,
                         module)
예제 #4
0
    def _test_getosutils(self, mock_system,
                         mock_linux_distribution, mock_import_module,
                         linux=False):
        if linux:
            os_name = 'Linux'
            mock_linux_distribution.return_value = (os_name, None, None)
        else:
            os_name = 'Windows'
            mock_system.return_value = os_name
            mock_linux_distribution.return_value = (None, None, None)

        module = base.get_osutils()

        mock_import_module.assert_called_once_with(
            "cloudinit.osys.{0}.base".format(os_name.lower()))
        self.assertEqual(mock_import_module.return_value.OSUtils,
                         module)
        if linux:
            mock_linux_distribution.assert_called_once_with()
            self.assertFalse(mock_system.called)
        else:
            mock_linux_distribution.assert_called_once_with()
            mock_system.assert_called_once_with()
예제 #5
0
 def _enable_metadata_access(metadata_url):
     if IS_WINDOWS:
         osutils = base.get_osutils()
         osutils.network.set_metadata_ip_route(metadata_url)
예제 #6
0
 def _enable_metadata_access(metadata_url):
     if IS_WINDOWS:
         osutils = base.get_osutils()
         osutils.network.set_metadata_ip_route(metadata_url)