Skip to content

Commit

Permalink
Merge pull request goharbor#2998 from cpeel/fix_logging
Browse files Browse the repository at this point in the history
Fix harborclient module logging
  • Loading branch information
yixingjia authored Oct 23, 2017
2 parents 4d4b27b + b7a2982 commit f3f220c
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions contrib/sdk/harbor-py/harborclient/harborclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import requests

logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger(__name__)

class HarborClient(object):
def __init__(self, host, user, password, protocol="http"):
Expand All @@ -23,15 +23,15 @@ def login(self):
if login_data.status_code == 200:
session_id = login_data.cookies.get('beegosessionID')
self.session_id = session_id
logging.debug("Successfully login, session id: {}".format(
logger.debug("Successfully login, session id: {}".format(
session_id))
else:
logging.error("Fail to login, please try again")
logger.error("Fail to login, please try again")

def logout(self):
requests.get('%s://%s/log_out' % (self.protocol, self.host),
cookies={'beegosessionID': self.session_id}, verify=False)
logging.debug("Successfully logout")
logger.debug("Successfully logout")

# GET /search
def search(self, query_string):
Expand All @@ -42,9 +42,9 @@ def search(self, query_string):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get search result: {}".format(result))
logger.debug("Successfully get search result: {}".format(result))
else:
logging.error("Fail to get search result")
logger.error("Fail to get search result")
return result

# GET /projects
Expand All @@ -55,10 +55,10 @@ def get_projects(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get projects result: {}".format(
logger.debug("Successfully get projects result: {}".format(
result))
else:
logging.error("Fail to get projects result")
logger.error("Fail to get projects result")
return result

# HEAD /projects
Expand All @@ -70,14 +70,14 @@ def check_project_exist(self, project_name):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Successfully check project exist, result: {}".format(result))
elif response.status_code == 404:
result = False
logging.debug(
logger.debug(
"Successfully check project exist, result: {}".format(result))
else:
logging.error("Fail to check project exist")
logger.error("Fail to check project exist")
return result

# POST /projects
Expand All @@ -91,11 +91,11 @@ def create_project(self, project_name, is_public=0):
data=request_body, verify=False)
if response.status_code == 201:
result = True
logging.debug(
logger.debug(
"Successfully create project with project name: {}".format(
project_name))
else:
logging.error(
logger.error(
"Fail to create project with project name: {}, response code: {}".format(
project_name, response.status_code))
return result
Expand All @@ -108,11 +108,11 @@ def get_project_members(self, project_id):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully create project with project id: {}".format(
project_id))
else:
logging.error(
logger.error(
"Fail to create project with project id: {}, response code: {}".format(
project_id, response.status_code))
return result
Expand All @@ -128,11 +128,11 @@ def add_project_member(self, project_id, username, role_id):
data=request_body, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Successfully add project member with project id: {}".format(
project_id))
else:
logging.error(
logger.error(
"Fail to add project member with project id: {}, response code: {}".format(
project_id, response.status_code))
return result
Expand All @@ -146,10 +146,10 @@ def delete_member_from_project(self, project_id, user_id):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = True
logging.debug("Successfully delete member with id: {}".format(
logger.debug("Successfully delete member with id: {}".format(
user_id))
else:
logging.error("Fail to delete member with id: {}, response code: {}"
logger.error("Fail to delete member with id: {}, response code: {}"
.format(user_id, response.status_code))
return result

Expand All @@ -164,11 +164,11 @@ def set_project_publicity(self, project_id, is_public):
data=request_body, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Success to set project id: {} with publicity: {}".format(
project_id, is_public))
else:
logging.error(
logger.error(
"Fail to set publicity to project id: {} with status code: {}".format(
project_id, response.status_code))
return result
Expand All @@ -181,9 +181,9 @@ def get_statistics(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get statistics: {}".format(result))
logger.debug("Successfully get statistics: {}".format(result))
else:
logging.error("Fail to get statistics result with status code: {}"
logger.error("Fail to get statistics result with status code: {}"
.format(response.status_code))
return result

Expand All @@ -196,9 +196,9 @@ def get_users(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get users result: {}".format(result))
logger.debug("Successfully get users result: {}".format(result))
else:
logging.error("Fail to get users result with status code: {}"
logger.error("Fail to get users result with status code: {}"
.format(response.status_code))
return result

Expand All @@ -210,9 +210,9 @@ def get_user_info(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get users result: {}".format(result))
logger.debug("Successfully get users result: {}".format(result))
else:
logging.error("Fail to get users result with status code: {}"
logger.error("Fail to get users result with status code: {}"
.format(response.status_code))
return result

Expand All @@ -230,10 +230,10 @@ def create_user(self, username, email, password, realname, comment):
data=request_body, verify=False)
if response.status_code == 201:
result = True
logging.debug("Successfully create user with username: {}".format(
logger.debug("Successfully create user with username: {}".format(
username))
else:
logging.error(
logger.error(
"Fail to create user with username: {}, response code: {}".format(
username, response.status_code))
return result
Expand All @@ -252,11 +252,11 @@ def update_user_profile(self, user_id, email, realname, comment):
data=request_body, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Successfully update user profile with user id: {}".format(
user_id))
else:
logging.error(
logger.error(
"Fail to update user profile with user id: {}, response code: {}".format(
user_id, response.status_code))
return result
Expand All @@ -270,10 +270,10 @@ def delete_user(self, user_id):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = True
logging.debug("Successfully delete user with id: {}".format(
logger.debug("Successfully delete user with id: {}".format(
user_id))
else:
logging.error("Fail to delete user with id: {}, response code: {}"
logger.error("Fail to delete user with id: {}, response code: {}"
.format(user_id, response.status_code))
return result

Expand All @@ -289,10 +289,10 @@ def change_password(self, user_id, old_password, new_password):
data=request_body, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Successfully change password for user id: {}".format(user_id))
else:
logging.error("Fail to change password for user id: {}".format(
logger.error("Fail to change password for user id: {}".format(
user_id))
return result

Expand All @@ -308,11 +308,11 @@ def promote_as_admin(self, user_id, has_admin_role):
data=request_body, verify=False)
if response.status_code == 200:
result = True
logging.debug(
logger.debug(
"Successfully promote user as admin with user id: {}".format(
user_id))
else:
logging.error(
logger.error(
"Fail to promote user as admin with user id: {}, response code: {}".format(
user_id, response.status_code))
return result
Expand All @@ -327,11 +327,11 @@ def get_repositories(self, project_id, query_string=None):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get repositories with id: {}, result: {}".format(
project_id, result))
else:
logging.error("Fail to get repositories result with id: {}, response code: {}".format(
logger.error("Fail to get repositories result with id: {}, response code: {}".format(
project_id, response.status_code))
return result

Expand All @@ -344,10 +344,10 @@ def delete_tag_of_repository(self, repo_name, tag):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = True
logging.debug("Successfully delete a tag of repository: {}".format(
logger.debug("Successfully delete a tag of repository: {}".format(
repo_name))
else:
logging.error("Fail to delete repository with name: {}, response code: {}".format(
logger.error("Fail to delete repository with name: {}, response code: {}".format(
repo_name, response.status_code))
return result

Expand All @@ -360,10 +360,10 @@ def delete_tags_of_repository(self, repo_name):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = True
logging.debug("Successfully delete repository: {}".format(
logger.debug("Successfully delete repository: {}".format(
repo_name))
else:
logging.error("Fail to delete repository with name: {}, response code: {}".format(
logger.error("Fail to delete repository with name: {}, response code: {}".format(
repo_name, response.status_code))
return result

Expand All @@ -376,11 +376,11 @@ def get_repository_tags(self, repo_name):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get tag with repo name: {}, result: {}".format(
repo_name, result))
else:
logging.error("Fail to get tags with repo name: {}, response code: {}".format(
logger.error("Fail to get tags with repo name: {}, response code: {}".format(
repo_name, response.status_code))
return result

Expand All @@ -393,11 +393,11 @@ def get_repository_manifest(self, repo_name, tag):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get manifests with repo name: {}, tag: {}, result: {}".format(
repo_name, tag, result))
else:
logging.error(
logger.error(
"Fail to get manifests with repo name: {}, tag: {}".format(
repo_name, tag))
return result
Expand All @@ -412,11 +412,11 @@ def get_top_accessed_repositories(self, count=None):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get top accessed repositories, result: {}".format(
result))
else:
logging.error("Fail to get top accessed repositories")
logger.error("Fail to get top accessed repositories")
return result

# GET /logs
Expand All @@ -427,9 +427,9 @@ def get_logs(self, lines=None, start_time=None, end_time=None):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug("Successfully get logs")
logger.debug("Successfully get logs")
else:
logging.error("Fail to get logs and response code: {}".format(
logger.error("Fail to get logs and response code: {}".format(
response.status_code))
return result

Expand All @@ -441,10 +441,10 @@ def get_systeminfo(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get systeminfo, result: {}".format(result))
else:
logging.error("Fail to get systeminfo, response code: {}".format(response.status_code))
logger.error("Fail to get systeminfo, response code: {}".format(response.status_code))
return result

# Get /configurations
Expand All @@ -455,8 +455,8 @@ def get_configurations(self):
cookies={'beegosessionID': self.session_id}, verify=False)
if response.status_code == 200:
result = response.json()
logging.debug(
logger.debug(
"Successfully get configurations, result: {}".format(result))
else:
logging.error("Fail to get configurations, response code: {}".format(response.status_code))
logger.error("Fail to get configurations, response code: {}".format(response.status_code))
return result

0 comments on commit f3f220c

Please sign in to comment.