def addresses(self, tenant=None): if not tenant: tenant = self.default_namespace url = '/hub/v2/blockchain/tenant/{}/addresses'.format(tenant) resp = self._get(url) if resp.status_code == 404: if resp.json()['error_id'] == 'tenant_not_found': raise NotFound(resp.json()) addresses = [i.get('address') for i in resp.json()["results"]] return {tenant: addresses}
def get_team_profile(team_id=None): with open('teams.yml') as f: teams_yml = yaml.load(f) if not team_id: return teams_yml['teams'] else: team = [t for t in teams_yml['teams'] if str(t.get('id')) == team_id] if not team: raise NotFound(f"Team id {team_id} not found in teams.yml") return team[0]
def get(self): args = reqparse.RequestParser() \ .add_argument('repo_tag', required=True) \ .add_argument('with_cache', type=bool, default=False) \ .parse_args() repo_tag = args.get('repo_tag') with_cache = args.get('with_cache') try: time = docker_client().estimate_image_hash_time( repo_tag, with_cache) return time, 200 except docker.errors.NotFound as e: raise NotFound(json.loads(e.explanation))
def get_metrics(source_type, _id, year, quarter): if source_type == 'jira': j = Jira(project_id=_id) return j.get_metrics(year, quarter) elif source_type == 'pivotal': p = Pivotal(project_id=_id) return p.get_metrics(year, quarter) elif source_type == 'trello': t = Trello(board_id=_id) return t.get_metrics(year, quarter) elif source_type == 'github': gh = Github(team_id=_id) return gh.get_metrics(year, quarter) else: raise NotFound(f"Source {source_type} not found")
def setUpClass(cls): cls.maxDiff = None cls.gateAlreadyExists = ServiceAlreadyExists().message cls.notFound = NotFound().message cls.gateNameNotValid = ServiceNameNotValid().message cls.gateStateNotValid = GateStateNotValid().message cls.environmentNotFound = EnvironmentNotFound("non_existing_environment").message cls.ticketNotFound = TicketNotFound().message cls.jsonStructureError = JsonStructureError().message cls.api_helper = ApiHelper('test') cls.database_helper = DatabaseHelper('test') cls.testdata_helper = TestDataHelper(cls.api_helper) cls.keys_develop_state = ['environments', 'develop', 'state']
def pull_image(self, repository, tag=None, username=None, password=None): _, _, _, _tag = parse_image_name(repository) if not tag: tag = _tag auth_config = None if username and password: auth_config = dict(username=username, password=password) resp = self.pull(repository, tag, stream=True, insecure_registry=True, auth_config=auth_config) def iter_json(): for i in resp: i = i.strip() if not i: continue try: j = json.loads(i) yield j except ValueError: continue layers = {} for j in iter_json(): if j.get('status') == 'Pulling fs layer': layers[j.get('id')] = {} elif layers or j.get('status') == 'Downloading': break elif 'error' in j: if 'not found' in j['error']: raise NotFound(j) else: raise APIException(j) def iter_progress(): for _j in iter_json(): if _j.get('status') == 'Downloading': layers[_j.get('id')] = _j.get('progressDetail') total = None current = None if all(layers): total = sum( [i.get('total', 0) for i in layers.values()]) current = sum( [i.get('current', 0) for i in layers.values()]) yield dict(layer_count=len(layers), layers=layers, current=current, total=total, percent=current * 100 / total, finished=False) task_id = 'p_%s' % gen_random_str(8) def consume(): cache = Cache() for i in iter_progress(): cache.set(task_id, i) cache.set(task_id, {'finished': True, 'percent': 100}) gevent.spawn(consume) # consume() return task_id