more updates to using f string
This commit is contained in:
parent
79cde8cd59
commit
7d2a615716
23 changed files with 248 additions and 251 deletions
|
@ -17,7 +17,9 @@ from core import constants
|
|||
from core.api.grpc.server import CoreGrpcServer
|
||||
from core.api.tlv.corehandlers import CoreHandler, CoreUdpHandler
|
||||
from core.api.tlv.coreserver import CoreServer, CoreUdpServer
|
||||
from core.constants import CORE_CONF_DIR, COREDPY_VERSION
|
||||
from core.emulator import enumerations
|
||||
from core.emulator.enumerations import CORE_API_PORT
|
||||
from core.utils import close_onexec, load_logging_config
|
||||
|
||||
|
||||
|
@ -67,7 +69,9 @@ def cored(cfg):
|
|||
# initialize grpc api
|
||||
if cfg["grpc"] == "True":
|
||||
grpc_server = CoreGrpcServer(server.coreemu)
|
||||
grpc_address = "%s:%s" % (cfg["grpcaddress"], cfg["grpcport"])
|
||||
address_config = cfg["grpcaddress"]
|
||||
port_config = cfg["grpcport"]
|
||||
grpc_address = f"{address_config}:{port_config}"
|
||||
grpc_thread = threading.Thread(target=grpc_server.listen, args=(grpc_address,))
|
||||
grpc_thread.daemon = True
|
||||
grpc_thread.start()
|
||||
|
@ -91,30 +95,34 @@ def get_merged_config(filename):
|
|||
:rtype: dict
|
||||
"""
|
||||
# these are the defaults used in the config file
|
||||
default_log = os.path.join(constants.CORE_CONF_DIR, "logging.conf")
|
||||
default_grpc_port = "50051"
|
||||
default_threads = "1"
|
||||
default_address = "localhost"
|
||||
defaults = {
|
||||
"port": "%d" % enumerations.CORE_API_PORT,
|
||||
"listenaddr": "localhost",
|
||||
"numthreads": "1",
|
||||
"grpcport": "50051",
|
||||
"grpcaddress": "localhost",
|
||||
"logfile": os.path.join(constants.CORE_CONF_DIR, "logging.conf")
|
||||
"port": str(CORE_API_PORT),
|
||||
"listenaddr": default_address,
|
||||
"numthreads": default_threads,
|
||||
"grpcport": default_grpc_port,
|
||||
"grpcaddress": default_address,
|
||||
"logfile": default_log
|
||||
}
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="CORE daemon v.%s instantiates Linux network namespace nodes." % constants.COREDPY_VERSION)
|
||||
description=f"CORE daemon v.{COREDPY_VERSION} instantiates Linux network namespace nodes.")
|
||||
parser.add_argument("-f", "--configfile", dest="configfile",
|
||||
help="read config from specified file; default = %s" % filename)
|
||||
help=f"read config from specified file; default = {filename}")
|
||||
parser.add_argument("-p", "--port", dest="port", type=int,
|
||||
help="port number to listen on; default = %s" % defaults["port"])
|
||||
help=f"port number to listen on; default = {CORE_API_PORT}")
|
||||
parser.add_argument("-n", "--numthreads", dest="numthreads", type=int,
|
||||
help="number of server threads; default = %s" % defaults["numthreads"])
|
||||
help=f"number of server threads; default = {default_threads}")
|
||||
parser.add_argument("--ovs", action="store_true", help="enable experimental ovs mode, default is false")
|
||||
parser.add_argument("--grpc", action="store_true", help="enable grpc api, default is false")
|
||||
parser.add_argument("--grpc-port", dest="grpcport",
|
||||
help="grpc port to listen on; default %s" % defaults["grpcport"])
|
||||
help=f"grpc port to listen on; default {default_grpc_port}")
|
||||
parser.add_argument("--grpc-address", dest="grpcaddress",
|
||||
help="grpc address to listen on; default %s" % defaults["grpcaddress"])
|
||||
parser.add_argument("-l", "--logfile", help="core logging configuration; default %s" % defaults["logfile"])
|
||||
help=f"grpc address to listen on; default {default_address}")
|
||||
parser.add_argument("-l", "--logfile", help=f"core logging configuration; default {default_log}")
|
||||
|
||||
# parse command line options
|
||||
args = parser.parse_args()
|
||||
|
@ -146,7 +154,7 @@ def main():
|
|||
:return: nothing
|
||||
"""
|
||||
# get a configuration merged from config file and command-line arguments
|
||||
cfg = get_merged_config("%s/core.conf" % constants.CORE_CONF_DIR)
|
||||
cfg = get_merged_config(f"{CORE_CONF_DIR}/core.conf")
|
||||
|
||||
# load logging configuration
|
||||
load_logging_config(cfg["logfile"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue