Пример #1
0
    def wait_for_metadata_service(self, url):
        mcfg = self.ds_cfg

        max_wait = 120
        try:
            max_wait = int(mcfg.get("max_wait", max_wait))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get max wait. using %s" % max_wait)

        if max_wait == 0:
            return False

        timeout = 50
        try:
            timeout = int(mcfg.get("timeout", timeout))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get timeout, using %s" % timeout)

        starttime = time.time()
        check_url = "%s/%s/meta-data/instance-id" % (url, MD_VERSION)
        url = util.wait_for_url(urls=[check_url], max_wait=max_wait,
            timeout=timeout, status_cb=log.warn,
            headers_cb=self.md_headers)

        if url:
            log.debug("Using metadata source: '%s'" % url)
        else:
            log.critical("giving up on md after %i seconds\n" %
                         int(time.time() - starttime))

        return (bool(url))
Пример #2
0
    def wait_for_metadata_service(self):
        mcfg = self.ds_cfg

        if not hasattr(mcfg, "get"):
            mcfg = {}

        max_wait = 120
        try:
            max_wait = int(mcfg.get("max_wait", max_wait))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get max wait. using %s" % max_wait)

        if max_wait == 0:
            return False

        timeout = 50
        try:
            timeout = int(mcfg.get("timeout", timeout))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get timeout, using %s" % timeout)

        def_mdurls = ["http://169.254.169.254", "http://instance-data.:8773"]
        mdurls = mcfg.get("metadata_urls", def_mdurls)

        # Remove addresses from the list that wont resolve.
        filtered = [x for x in mdurls if util.is_resolvable_url(x)]

        if set(filtered) != set(mdurls):
            log.debug("removed the following from metadata urls: %s" % list(
                (set(mdurls) - set(filtered))))

        if len(filtered):
            mdurls = filtered
        else:
            log.warn("Empty metadata url list! using default list")
            mdurls = def_mdurls

        urls = []
        url2base = {False: False}
        for url in mdurls:
            cur = "%s/%s/meta-data/instance-id" % (url, self.api_ver)
            urls.append(cur)
            url2base[cur] = url

        starttime = time.time()
        url = util.wait_for_url(urls=urls,
                                max_wait=max_wait,
                                timeout=timeout,
                                status_cb=log.warn)

        if url:
            log.debug("Using metadata source: '%s'" % url2base[url])
        else:
            log.critical("giving up on md after %i seconds\n" %
                         int(time.time() - starttime))

        self.metadata_address = url2base[url]
        return (bool(url))
Пример #3
0
    def wait_for_metadata_service(self):
        mcfg = self.ds_cfg

        if not hasattr(mcfg, "get"):
            mcfg = {}

        max_wait = 120
        try:
            max_wait = int(mcfg.get("max_wait", max_wait))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get max wait. using %s" % max_wait)

        if max_wait == 0:
            return False

        timeout = 50
        try:
            timeout = int(mcfg.get("timeout", timeout))
        except Exception:
            util.logexc(log)
            log.warn("Failed to get timeout, using %s" % timeout)

        def_mdurls = ["http://169.254.169.254", "http://instance-data.:8773"]
        mdurls = mcfg.get("metadata_urls", def_mdurls)

        # Remove addresses from the list that wont resolve.
        filtered = [x for x in mdurls if util.is_resolvable_url(x)]

        if set(filtered) != set(mdurls):
            log.debug("removed the following from metadata urls: %s" %
                list((set(mdurls) - set(filtered))))

        if len(filtered):
            mdurls = filtered
        else:
            log.warn("Empty metadata url list! using default list")
            mdurls = def_mdurls

        urls = []
        url2base = {False: False}
        for url in mdurls:
            cur = "%s/%s/meta-data/instance-id" % (url, self.api_ver)
            urls.append(cur)
            url2base[cur] = url

        starttime = time.time()
        url = util.wait_for_url(urls=urls, max_wait=max_wait,
                                timeout=timeout, status_cb=log.warn)

        if url:
            log.debug("Using metadata source: '%s'" % url2base[url])
        else:
            log.critical("giving up on md after %i seconds\n" %
                         int(time.time() - starttime))

        self.metadata_address = url2base[url]
        return (bool(url))