-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# k2hr3client - Python client for K2HR3 REST API | ||
# | ||
# Copyright 2024 LY Corporation | ||
# | ||
# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers | ||
# common management information for the cloud. | ||
# K2HR3 can dynamically manage information as "who", "what", "operate". | ||
# These are stored as roles, resources, policies in K2hdkc, and the | ||
# client system can dynamically read and modify these information. | ||
# | ||
# For the full copyright and license information, please view | ||
# the license file that was distributed with this source code. | ||
# | ||
# AUTHOR: Hirotaka Wakabayashi | ||
# CREATE: Fri Oct 11 2024 | ||
# REVISION: | ||
# | ||
# | ||
[DEFAULT] | ||
debug = False | ||
iaas_url = "http://172.24.4.1" | ||
iaas_project = "demo" | ||
iaas_user = "demo" | ||
iaas_password = "password" | ||
iaas_url = http://172.24.4.1 | ||
iaas_project = demo | ||
iaas_user = demo | ||
iaas_password = password | ||
log_file = sys.stdout | ||
log_dir = logs | ||
log_level = logging.INFO | ||
|
||
[k2hr3] | ||
api_url = "http://127.0.0.1:18080" | ||
api_version = "v1" | ||
api_url = http://127.0.0.1:18080 | ||
api_version = v1 | ||
|
||
[http] | ||
timeout_seconds = 30 | ||
retry_interval_seconds = 60 | ||
max_retries = 3 | ||
allow_self_signed_cert = True | ||
|
||
# | ||
# Local variables: | ||
# tab-width: 4 | ||
# c-basic-offset: 4 | ||
# End: | ||
# vim600: expandtab sw=4 ts=4 fdm=marker | ||
# vim<600: expandtab sw=4 ts=4 | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,17 @@ | |
"""K2HR3 Python Client of Token API.""" | ||
|
||
__author__ = 'Hirotaka Wakabayashi <[email protected]>' | ||
__version__ = '1.1.1' | ||
__version__ = '1.1.2' | ||
|
||
import configparser | ||
import logging | ||
from logging.handlers import TimedRotatingFileHandler | ||
from logging import StreamHandler | ||
from pathlib import Path | ||
import sys | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
if sys.platform.startswith('win'): | ||
raise ImportError(r'Currently we do not test well on windows') | ||
|
||
|
@@ -61,7 +66,7 @@ def get_version() -> str: | |
default_section['iaas_password'] = "password" | ||
default_section['log_file'] = "sys.stderr" | ||
default_section['log_dir'] = "logs" | ||
default_section['log_level'] = "logging.INFO" | ||
default_section['log_level'] = "info" | ||
|
||
# [k2hr3] | ||
# api_url = "http://127.0.0.1:18080" | ||
|
@@ -100,6 +105,55 @@ def get_version() -> str: | |
CONFIG.read(my_config.absolute()) | ||
break | ||
|
||
# 3. Configure logger | ||
# 3.1. loglevel | ||
_nametolevel = { | ||
'error': logging.ERROR, | ||
'warn': logging.WARNING, | ||
'info': logging.INFO, | ||
'debug': logging.DEBUG, | ||
'notset': logging.NOTSET | ||
} | ||
LOG_LEVEL = logging.INFO # noqa | ||
if CONFIG['DEFAULT'].get('log_level'): | ||
LOG_LEVEL = _nametolevel.get( | ||
CONFIG['DEFAULT'].get('log_level'), | ||
logging.INFO) | ||
LOG.setLevel(LOG_LEVEL) | ||
|
||
# 3.2. format | ||
formatter = logging.Formatter( | ||
'%(asctime)-15s %(levelname)s %(name)s:%(lineno)d %(message)s') | ||
# 3.3. handler | ||
# Add the log message handler to the logger | ||
if CONFIG['DEFAULT'].get('log_file') == 'sys.stdout': | ||
stream_handler = StreamHandler(sys.stdout) | ||
LOG.addHandler(stream_handler) | ||
stream_handler.setFormatter(formatter) | ||
elif CONFIG['DEFAULT'].get('log_file') == 'sys.stderr': | ||
stream_handler = StreamHandler(sys.stderr) # default | ||
LOG.addHandler(stream_handler) | ||
stream_handler.setFormatter(formatter) | ||
|
||
# log_dir | ||
log_dir_path = Path('.') # default | ||
log_dir = CONFIG['DEFAULT'].get('log_dir') | ||
if log_dir: | ||
log_dir_path = Path(log_dir) | ||
log_dir_path.mkdir(parents=True, exist_ok=True) | ||
|
||
# log_file | ||
log_file = CONFIG['DEFAULT'].get('log_file') | ||
if log_file: | ||
log_file_path = log_dir_path.joinpath(log_file) | ||
log_file_path.touch() | ||
handler = TimedRotatingFileHandler( | ||
log_file_path.absolute(), | ||
when='midnight', encoding='UTF-8', | ||
backupCount=31) | ||
handler.setFormatter(formatter) | ||
LOG.addHandler(handler) | ||
|
||
# | ||
# Local variables: | ||
# tab-width: 4 | ||
|