diff --git a/sdcclient/_common.py b/sdcclient/_common.py index d8d0483c..57c15f62 100644 --- a/sdcclient/_common.py +++ b/sdcclient/_common.py @@ -715,9 +715,28 @@ def get_teams(self, team_filter='', product_filter=''): return [False, self.lasterr] ret = [t for t in res.json()['teams'] if team_filter in t['name']] if product_filter: - ret = [t for t in ret if product_filter in t['products']] + ret = [t for t in ret if product_filter in t['products']] return [True, ret] + def get_team_by_id(self, id): + '''**Description** + Return the team with the specified team ID, if it is present. + + **Arguments** + - **id**: the ID of the team to return + + **Success Return Value** + The requested team. + + **Example** + `examples/user_team_mgmt.py `_ + ''' + res = self.http.get(self.url + '/api/teams/' + str(id), headers=self.hdrs, verify=self.ssl_verify) + if not self._checkResponse(res): + return [False, self.lasterr] + + return [True, res.json()['team']] + def get_team(self, name): '''**Description** Return the team with the specified team name, if it is present. @@ -731,13 +750,18 @@ def get_team(self, name): **Example** `examples/user_team_mgmt.py `_ ''' - ok, res = self.get_teams(name) + res = self.http.get(self.url + '/api/v2/teams/light/name/' + str(name), headers=self.hdrs, verify=self.ssl_verify) + if not self._checkResponse(res): + return [False, self.lasterr] + + light_team = res.json()['team'] + + ok, team_with_memberships = self.get_team_by_id(light_team['id']) + if not ok: - return ok, res - for team in res: - if team['name'] == name: - return [True, team] - return [False, 'Could not find team'] + return [False, self.lasterr] + + return [True, team_with_memberships] def get_team_ids(self, teams): res = self.http.get(self.url + '/api/teams', headers=self.hdrs, verify=self.ssl_verify)