forked from archiver_config/sf_databuffer
add imagebuffer restart script
This commit is contained in:
@@ -98,6 +98,10 @@ def remove_labeled_source(sources, label):
|
||||
return {"sources": [x for x in sources["sources"] if "labels" not in x or (label not in x['labels'])]}
|
||||
|
||||
|
||||
def remove_image_source(sources):
|
||||
return {"sources": [x for x in sources["sources"] if "backend" not in x or x['backend'] != "sf-imagebuffer"]}
|
||||
|
||||
|
||||
def get_labels(sources):
|
||||
"""
|
||||
Retrieve all used labels in the source configurations
|
||||
@@ -118,6 +122,15 @@ def get_labeled_sources(sources, label):
|
||||
return [x for x in sources["sources"] if "labels" in x and label in x['labels']]
|
||||
|
||||
|
||||
def get_image_sources(sources):
|
||||
"""
|
||||
Get image source(s)
|
||||
:param sources:
|
||||
:return: list of source config that are images
|
||||
"""
|
||||
return [x for x in sources["sources"] if "backend" in x and x['backend'] == "sf-imagebuffer"]
|
||||
|
||||
|
||||
def read_files(files_dir, file_type):
|
||||
"""
|
||||
Read sources or policies files
|
||||
@@ -198,6 +211,11 @@ def main():
|
||||
default=None,
|
||||
help="label that identifies the source(s) to stop")
|
||||
|
||||
parser_stop.add_argument('-t',
|
||||
'--type',
|
||||
default=None,
|
||||
help="type of to stop")
|
||||
|
||||
parser_list = subparsers.add_parser('list',
|
||||
help="list",
|
||||
formatter_class=argparse.RawTextHelpFormatter)
|
||||
@@ -267,12 +285,33 @@ def main():
|
||||
# Only for debugging purposes
|
||||
labeled_sources = get_labeled_sources(sources, label)
|
||||
for s in labeled_sources:
|
||||
logging.info(f"Restarting {s['stream']}")
|
||||
logging.info(f"Stop {s['stream']}")
|
||||
|
||||
sources_new = remove_labeled_source(sources, label)
|
||||
|
||||
# Stopping the removed source(s)
|
||||
upload_sources_and_policies(sources_new, policies)
|
||||
elif arguments.type:
|
||||
type = arguments.type
|
||||
if type != "image":
|
||||
logging.warning(f"Type {type} currently not supported")
|
||||
return
|
||||
logging.info(f"Stop: {type}")
|
||||
|
||||
policies = read_files(base_directory / Path("policies"), "policies")
|
||||
sources = read_files(base_directory / Path("sources"), "sources")
|
||||
|
||||
# Only for debugging purposes
|
||||
image_sources = get_image_sources(sources)
|
||||
for s in image_sources:
|
||||
logging.info(f"Stop {s['stream']}")
|
||||
|
||||
sources_new = remove_image_source(sources)
|
||||
|
||||
# Stopping the removed source(s)
|
||||
upload_sources_and_policies(sources_new, policies)
|
||||
|
||||
|
||||
else:
|
||||
logging.warning("Not yet implemented")
|
||||
parser_stop.print_usage()
|
||||
|
||||
Reference in New Issue
Block a user