Example #1
0
def _version_check():
    current_version = armada_api.get('version')
    if not is_valid_response(current_version):
        # skip version check since we cannot determinate current version
        return

    with SyncOpen(VERSION_CACHE_FILE_PATH, 'r+') as f:
        data = json.load(f)
        displayed_timestamp = data['displayed']

        cache_version = data['latest_version']
        current_is_newer = StrictVersion(current_version) >= StrictVersion(
            cache_version)
        if current_is_newer or time.time(
        ) - DISPLAY_INTERVAL < displayed_timestamp:
            return

        message = 'You are using armada version {}, however version {} is available. ' \
                  'You should consider upgrading armada via "bash <(curl -sL http://armada.sh/install)"' \
                  .format(armada_api.get('version'), data['latest_version'])
        print('\n' + message, file=sys.stderr)

        data['displayed'] = time.time()
        f.seek(0)
        f.truncate()
        json.dump(data, f)
Example #2
0
 def __get_local_image_creation_time(self):
     images_response = json.loads(armada_api.get('images/{self.microservice_name}'.format(**locals())))
     if images_response['status'] == 'ok':
         image_info = json.loads(images_response['image_info'])
         if image_info:
             return datetime.datetime.utcfromtimestamp(int(image_info[0]['Created'])).isoformat()
         else:
             return None
Example #3
0
 def get_image_creation_time(self, name, tag='latest'):
     images_response = json.loads(armada_api.get('images/{}'.format(name)))
     if images_response['status'] == 'ok':
         image_infos = json.loads(images_response['image_info'])
         name_with_tag = '{}:{}'.format(name, tag)
         image_info_for_tag = [image_info for image_info in image_infos if name_with_tag in image_info['RepoTags']]
         if image_info_for_tag:
             return datetime.utcfromtimestamp(int(image_info_for_tag[0]['Created'])).isoformat()
     return None
Example #4
0
 def get_image_creation_time(self, name, tag='latest'):
     images_response = json.loads(armada_api.get('images/{}'.format(name)))
     if images_response['status'] == 'ok':
         image_infos = json.loads(images_response['image_info'])
         name_with_tag = '{}:{}'.format(name, tag)
         image_info_for_tag = [image_info for image_info in image_infos if name_with_tag in image_info['RepoTags']]
         if image_info_for_tag:
             return datetime.utcfromtimestamp(int(image_info_for_tag[0]['Created'])).isoformat()
     return None
Example #5
0
 def get_image_creation_time(self, name, tag="latest"):
     images_response = json.loads(armada_api.get("images/{}".format(name)))
     if images_response["status"] == "ok":
         image_infos = json.loads(images_response["image_info"])
         name_with_tag = "{}:{}".format(name, tag)
         image_info_for_tag = [image_info for image_info in image_infos if name_with_tag in image_info["RepoTags"]]
         if image_info_for_tag:
             return datetime.utcfromtimestamp(int(image_info_for_tag[0]["Created"])).isoformat()
     return None
Example #6
0
 def get_image_creation_time(self, image_path, tag='latest'):
     images_response = json.loads(
         armada_api.get('images/{}'.format(image_path)))
     if images_response['status'] != 'ok':
         return None
     image_infos = json.loads(images_response['image_info'])
     name_with_tag = '{}:{}'.format(image_path, tag)
     for image_info in image_infos:
         repo_tags = image_info.get('RepoTags') or []
         if name_with_tag in repo_tags:
             return datetime.utcfromtimestamp(int(
                 image_info['Created'])).isoformat()
     return None
Example #7
0
def main():
    version = armada_api.get('version')
    if not is_valid_response(version):
        # skip sync if we cannot determine current version
        return
    r = requests.get('http://version.armada.sh/version_check', data=dict(version=version), timeout=3)
    r.raise_for_status()
    data = r.json()
    data.update({
        'displayed': 0,
        'synced': time.time(),
    })
    with SyncOpen(VERSION_CACHE_FILE_PATH, 'w') as f:
        json.dump(data, f)
Example #8
0
def _version_check():
    current_version = armada_api.get('version')
    if not is_valid_response(current_version):
        # skip version check since we cannot determinate current version
        return

    with SyncOpen(VERSION_CACHE_FILE_PATH, 'r+') as f:
        data = json.load(f)
        displayed_timestamp = data['displayed']

        cache_version = data['latest_version']
        current_is_newer = StrictVersion(current_version) >= StrictVersion(cache_version)
        if current_is_newer or time.time() - DISPLAY_INTERVAL < displayed_timestamp:
            return

        message = 'You are using armada version {}, however version {} is available. ' \
                  'You should consider upgrading armada via "bash <(curl -sL http://armada.sh/install)"' \
            .format(armada_api.get('version'), data['latest_version'])
        print('\n' + message, file=sys.stderr)

        data['displayed'] = time.time()
        f.seek(0)
        f.truncate()
        json.dump(data, f)
Example #9
0
def main():
    version = armada_api.get('version')
    if not is_valid_response(version):
        # skip sync if we cannot determine current version
        return
    r = requests.get('http://version.armada.sh/version_check',
                     data=dict(version=version),
                     timeout=3)
    r.raise_for_status()
    data = r.json()
    data.update({
        'displayed': 0,
        'synced': time.time(),
    })
    with SyncOpen(VERSION_CACHE_FILE_PATH, 'w') as f:
        json.dump(data, f)
Example #10
0
def command_version(args):
    version = armada_api.get('version')
    print(version)