Beispiel #1
0
    def get_region(self):
        if os.environ.get("AX_AWS_REGION", None):
            return os.environ.get("AX_AWS_REGION")
        if Cloud().own_cloud() != Cloud.CLOUD_AWS:
            return "unknown-region"

        url = self._meta_url + "placement/availability-zone"
        retry = AXRetry(retry_exception=(Exception, ))
        r = ax_retry(requests.get, retry, url, timeout=10)
        return r.text[:-1]
Beispiel #2
0
 def _remove(self, container, **kwargs):
     try:
         self._conn.remove_container(container, v=True, **kwargs)
     except NotFound:
         pass
     except APIError as e:
         if "Conflict" in str(e):
             logger.error("Not removing running container %s", container)
         elif "device or resource busy" in str(e):
             # Work around https://github.com/google/cadvisor/issues/771
             logger.error("Container removal temporary failure. Retrying.")
             retry = AXRetry(retries=10,
                             delay=1,
                             retry_exception=(Exception, ),
                             success_exception=(NotFound, ))
             ax_retry(self._conn.remove_container,
                      retry,
                      container,
                      v=True,
                      force=True)
         else:
             logger.exception("Failed to remove container %s", container)
     except Exception:
         logger.exception("Failed to remove container %s", container)
Beispiel #3
0
    def post(topic, op, data, key=None):
        """
        Post an event to axevent server.

        :param path: pathname for event.
        :param data: event json data.
        :return POST response or None
        """
        logger.debug("Post {} {} {}".format(topic, key, json.dumps(data)))
        retry = AXRetry(retry_exception=(Exception, ))
        # kafka consumer has its own timeout, by default is 30 seconds
        return ax_retry(AXEventClient.producer().send,
                        retry,
                        topic=topic,
                        key=key,
                        value=AXEventClient.pack_message_body(op, data))
Beispiel #4
0
 def get_user_data(self, attr=None, plain_text=False):
     """
     Get AWS EC2 user data.
     :param attr: string: name of attribute if only one attribute is needed.
     :param plain_text: Is user data plain text or json.
     :return value of user data
     """
     retry = AXRetry(retry_exception=(Exception, ))
     r = ax_retry(requests.get, retry, self._user_url, timeout=10)
     if r:
         if plain_text:
             return r.text
         else:
             if attr:
                 return r.json().get(attr, None)
             else:
                 return r.json()
Beispiel #5
0
 def _push_with_retry(self, registry, name, tag):
     return ax_retry(self._push, self._retry, registry, name, tag)
Beispiel #6
0
 def _pull_with_retry(self, registry, name, tag, **kwargs):
     return ax_retry(self._pull, self._retry, registry, name, tag, **kwargs)
Beispiel #7
0
 def get_instance_type(self):
     url = self._meta_url + "instance-type"
     retry = AXRetry(retries=3, delay=2, retry_exception=(Exception, ))
     r = ax_retry(requests.get, retry, url, timeout=3)
     return r.text.strip()
Beispiel #8
0
 def get_zone(self):
     url = self._meta_url + "placement/availability-zone"
     retry = AXRetry(retry_exception=(Exception, ))
     r = ax_retry(requests.get, retry, url, timeout=10)
     return r.text