-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue:3563885:UFM Enterprise network reports #123
Open
Abeer-Moghrabi
wants to merge
7
commits into
Mellanox:main
Choose a base branch
from
Abeer-Moghrabi:3563885-events-histroy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7839f2b
issue:3572586: create events history plugin basic structure
Abeer-Moghrabi 98af278
issue:3574823: create event basic structure (event, event resource an…
Abeer-Moghrabi f3b4073
issue:3083189: add missing copyrights
Abeer-Moghrabi c410dc4
issue:3576752: Create a collection for each supported event and add t…
Abeer-Moghrabi 2b812ec
issue:3572590: add file watcher to watch event.log on file modified
Abeer-Moghrabi 04e1ce7
issue:3572590: add value to PLUGIN_NAME in Dockerfile
Abeer-Moghrabi 0df4b84
issue:3572590: replace python3.9 with python3 which is usually symlin…
Abeer-Moghrabi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM ubuntu:20.04 | ||
|
||
LABEL maintainer="[email protected]" | ||
|
||
ARG PLUGIN_NAME=events_history | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
ARG BASE_PATH=/opt/ufm/ufm_plugin_${PLUGIN_NAME} | ||
ARG SRC_BASE_DIR=${PLUGIN_NAME}_plugin | ||
|
||
COPY ${SRC_BASE_DIR}/ ${BASE_PATH}/${SRC_BASE_DIR}/ | ||
COPY utils/ ${BASE_PATH}/utils/ | ||
|
||
COPY ${SRC_BASE_DIR}/conf/supervisord.conf /etc/supervisor/conf.d/ | ||
COPY ${SRC_BASE_DIR}/scripts/init.sh ${SRC_BASE_DIR}/scripts/deinit.sh / | ||
|
||
RUN apt-get update && apt-get -y install supervisor python3 python3-pip vim curl sudo | ||
|
||
RUN python3 -m pip install -r ${BASE_PATH}/${SRC_BASE_DIR}/src/${PLUGIN_NAME}/requirements.txt | ||
|
||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] |
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
|
||
set -eE | ||
|
||
if [ "$EUID" -ne 0 ] | ||
then echo "Please run the script as root" | ||
exit | ||
fi | ||
|
||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
PARENT_DIR=$(realpath "${SCRIPT_DIR}/../../../") | ||
|
||
PLUGIN_NAME=events_history | ||
IMAGE_NAME="ufm-plugin-${PLUGIN_NAME}" | ||
IMAGE_VERSION=$1 | ||
OUT_DIR=$2 | ||
RANDOM_HASH=$3 | ||
|
||
echo "RANDOM_HASH : [${RANDOM_HASH}]" | ||
echo "SCRIPT_DIR : [${SCRIPT_DIR}]" | ||
echo " " | ||
echo "IMAGE_VERSION: [${IMAGE_VERSION}]" | ||
echo "IMAGE_NAME : [${IMAGE_NAME}]" | ||
echo "OUT_DIR : [${OUT_DIR}]" | ||
echo " " | ||
|
||
if [ -z "${OUT_DIR}" ]; then | ||
OUT_DIR="." | ||
fi | ||
if [ -z "${IMAGE_VERSION}" ]; then | ||
IMAGE_VERSION="latest" | ||
fi | ||
|
||
function create_out_dir() | ||
{ | ||
build_dir=$(mktemp --tmpdir -d ${IMAGE_NAME}_output_XXXXXXXX) | ||
chmod 777 ${build_dir} | ||
echo ${build_dir} | ||
} | ||
|
||
function build_docker_image() | ||
{ | ||
build_dir=$1 | ||
image_name=$2 | ||
image_version=$3 | ||
out_dir=$4 | ||
random_hash=$5 | ||
keep_image=$6 | ||
prefix="mellanox" | ||
|
||
echo "build_docker_image" | ||
echo " build_dir : [${build_dir}]" | ||
echo " image_name : [${image_name}]" | ||
echo " image_version : [${image_version}]" | ||
echo " random_hash : [${random_hash}]" | ||
echo " out_dir : [${out_dir}]" | ||
echo " keep_image : [${keep_image}]" | ||
echo " prefix : [${prefix}]" | ||
echo " " | ||
if [ "${IMAGE_VERSION}" == "0.0.00-0" ]; then | ||
full_image_version="${image_name}_${image_version}-${random_hash}" | ||
else | ||
full_image_version="${image_name}_${image_version}" | ||
fi | ||
|
||
echo " full_image_version : [${full_image_version}]" | ||
|
||
image_with_prefix="${prefix}/${image_name}" | ||
image_with_prefix_and_version="${prefix}/${image_name}:${image_version}" | ||
|
||
pushd ${build_dir} | ||
|
||
echo "docker build --network host --no-cache --pull -t ${image_with_prefix_and_version} . --compress --build-arg PLUGIN_NAME=${PLUGIN_NAME}" | ||
|
||
docker build --network host --no-cache --pull -t ${image_with_prefix_and_version} . --compress --build-arg PLUGIN_NAME=${PLUGIN_NAME} | ||
exit_code=$? | ||
popd | ||
if [ $exit_code -ne 0 ]; then | ||
echo "Failed to build image" | ||
return $exit_code | ||
fi | ||
|
||
printf "\n\n\n" | ||
echo "docker images | grep ${image_with_prefix}" | ||
docker images | grep ${image_with_prefix} | ||
printf "\n\n\n" | ||
|
||
echo "docker save ${image_with_prefix_and_version} | gzip > ${out_dir}/${full_image_version}-docker.img.gz" | ||
docker save ${image_with_prefix_and_version} | gzip > ${out_dir}/${full_image_version}-docker.img.gz | ||
exit_code=$? | ||
if [ $exit_code -ne 0 ]; then | ||
echo "Failed to save image" | ||
return $exit_code | ||
fi | ||
if [ "$keep_image" != "y" -a "$keep_image" != "Y" ]; then | ||
docker image rm -f ${image_with_prefix_and_version} | ||
fi | ||
return 0 | ||
} | ||
|
||
|
||
pushd ${SCRIPT_DIR} | ||
|
||
echo ${IMAGE_VERSION} > ../../${PLUGIN_NAME}_plugin/version | ||
|
||
BUILD_DIR=$(create_out_dir) | ||
cp Dockerfile ${BUILD_DIR} | ||
cp -r ../../../utils ${BUILD_DIR} | ||
cp -r ../../${PLUGIN_NAME}_plugin ${BUILD_DIR} | ||
|
||
echo "BUILD_DIR : [${BUILD_DIR}]" | ||
|
||
build_docker_image $BUILD_DIR $IMAGE_NAME $IMAGE_VERSION $OUT_DIR ${RANDOM_HASH} | ||
exit_code=$? | ||
rm -rf ${BUILD_DIR} | ||
popd | ||
exit $exit_code |
1 change: 1 addition & 0 deletions
1
plugins/events_history_plugin/conf/events_history_httpd_proxy.conf
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
port=8686 |
6 changes: 6 additions & 0 deletions
6
plugins/events_history_plugin/conf/events_history_plugin.conf
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[logs-config] | ||
logs_file_name = /log/events_history_plugin.log | ||
logs_level = INFO | ||
log_file_max_size = 10485760 | ||
log_file_backup_count = 5 | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
[unix_http_server] | ||
username = dummy | ||
password = dummy | ||
|
||
[supervisorctl] | ||
username = dummy | ||
password = dummy | ||
|
||
[supervisord] | ||
user=root | ||
nodaemon = true | ||
environment = PLACEHOLDER=true | ||
stdout_logfile=/dev/stdout | ||
stdout_logfile_maxbytes=0 | ||
stderr_logfile=/dev/stderr | ||
stderr_logfile_maxbytes=0 | ||
|
||
[program:events_history_service] | ||
directory=/opt/ufm/ufm_plugin_events_history | ||
command=python3 /opt/ufm/ufm_plugin_events_history/events_history_plugin/src/events_history_plugin/app.py | ||
autostart=true | ||
autorestart=true | ||
startretries=1 | ||
startsecs=1 | ||
user=root | ||
killasgroup=true | ||
stopasgroup=true | ||
stdout_logfile=/dev/stdout | ||
stdout_logfile_maxbytes=0 | ||
stderr_logfile=/dev/stderr | ||
stderr_logfile_maxbytes=0 |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright © 2013-2022 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | ||
# | ||
# This software product is a proprietary product of Nvidia Corporation and its affiliates | ||
# (the "Company") and all right, title, and interest in and to the software | ||
# product, including all associated intellectual property rights, are and | ||
# shall remain exclusively with the Company. | ||
# | ||
# This software product is governed by the End User License Agreement | ||
# provided with the software product. | ||
# @author: Abeer Moghrabi | ||
# @date: Aug 14, 2023 | ||
# | ||
|
||
set -eE | ||
|
||
# removing log file | ||
rm -rf /log/events_history_plugin*.log* | ||
|
||
exit 0 |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright © 2013-2023 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | ||
# | ||
# This software product is a proprietary product of Nvidia Corporation and its affiliates | ||
# (the "Company") and all right, title, and interest in and to the software | ||
# product, including all associated intellectual property rights, are and | ||
# shall remain exclusively with the Company. | ||
# | ||
# This software product is governed by the End User License Agreement | ||
# provided with the software product. | ||
# @author: Abeer Moghrabi | ||
# @date: Aug 14, 2023 | ||
# | ||
# ================================================================ | ||
# This script prepares and checks events_history docker container Environment | ||
# ================================================================ | ||
|
||
set -eE | ||
PLUGIN_NAME=events_history | ||
SRC_DIR_PATH=/opt/ufm/ufm_plugin_${PLUGIN_NAME}/${PLUGIN_NAME}_plugin | ||
CONFIG_PATH=/config | ||
|
||
touch ${CONFIG_PATH}/${PLUGIN_NAME}_shared_volumes.conf | ||
|
||
echo /opt/ufm/files/log/:/log > ${CONFIG_PATH}/${PLUGIN_NAME}_shared_volumes.conf | ||
|
||
# UFM version test | ||
required_ufm_version=(6 12 0) | ||
echo "Required UFM version: ${required_ufm_version[0]}.${required_ufm_version[1]}.${required_ufm_version[2]}" | ||
|
||
if [ "$1" == "-ufm_version" ]; then | ||
actual_ufm_version_string=$2 | ||
actual_ufm_version=(${actual_ufm_version_string//./ }) | ||
echo "Actual UFM version: ${actual_ufm_version[0]}.${actual_ufm_version[1]}.${actual_ufm_version[2]}" | ||
if [ ${actual_ufm_version[0]} -ge ${required_ufm_version[0]} ] \ | ||
&& [ ${actual_ufm_version[1]} -ge ${required_ufm_version[1]} ] \ | ||
&& [ ${actual_ufm_version[2]} -ge ${required_ufm_version[2]} ]; then | ||
echo "UFM version meets the requirements" | ||
exit 0 | ||
else | ||
echo "UFM version is older than required" | ||
exit 1 | ||
fi | ||
else | ||
exit 1 | ||
fi | ||
|
||
exit 1 |
13 changes: 13 additions & 0 deletions
13
plugins/events_history_plugin/src/events_history/api/__init__.py
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# Copyright © 2013-2022 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | ||
# | ||
# This software product is a proprietary product of Nvidia Corporation and its affiliates | ||
# (the "Company") and all right, title, and interest in and to the software | ||
# product, including all associated intellectual property rights, are and | ||
# shall remain exclusively with the Company. | ||
# | ||
# This software product is governed by the End User License Agreement | ||
# provided with the software product. | ||
# @author: Abeer Moghrabi | ||
# @date: Aug 9, 2023 | ||
# |
77 changes: 77 additions & 0 deletions
77
plugins/events_history_plugin/src/events_history/api/conf_api.py
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# Copyright © 2013-2023 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | ||
# | ||
# This software product is a proprietary product of Nvidia Corporation and its affiliates | ||
# (the "Company") and all right, title, and interest in and to the software | ||
# product, including all associated intellectual property rights, are and | ||
# shall remain exclusively with the Company. | ||
# | ||
# This software product is governed by the End User License Agreement | ||
# provided with the software product. | ||
# @author: Abeer Moghrabi | ||
# @date: Aug 9, 2023 | ||
# | ||
from flask import make_response, request | ||
from http import HTTPStatus | ||
|
||
from utils.flask_server.base_flask_api_server import BaseAPIApplication | ||
from utils.config_parser import InvalidConfRequest | ||
from utils.logger import Logger, LOG_LEVELS | ||
from utils.json_schema_validator import validate_schema | ||
|
||
from mgr.events_history_configurations_mgr import EventsHistoryConfigParser | ||
|
||
|
||
class EventsHistoryPluginConfigurationsAPI(BaseAPIApplication): | ||
""" | ||
This class was designed to support retrieving and editing config file. | ||
""" | ||
|
||
def __init__(self): | ||
super(EventsHistoryPluginConfigurationsAPI, self).__init__() | ||
self.conf = EventsHistoryConfigParser.getInstance() | ||
|
||
# for debugging | ||
# self.conf_schema_path = "plugins/events_history/src/events_history/schemas/set_conf.schema.json" | ||
|
||
# for production with docker | ||
self.conf_schema_path = "events_history/src/events_history/schemas/set_conf.schema.json" | ||
|
||
def _get_error_handlers(self): | ||
return [ | ||
(InvalidConfRequest, | ||
lambda e: (str(e), HTTPStatus.BAD_REQUEST)) | ||
] | ||
|
||
def _get_routes(self): | ||
return { | ||
self.get_conf: dict(urls=["/"], methods=["GET"]), | ||
self.update_conf: dict(urls=["/"], methods=["PUT"]) | ||
} | ||
|
||
def get_conf(self): | ||
try: | ||
_response = self.conf.conf_to_dict(self.conf_schema_path) | ||
return make_response(_response) | ||
except Exception as e: | ||
Logger.log_message("Error occurred while getting the current plugin configurations: " + str(e), | ||
LOG_LEVELS.ERROR) | ||
raise e | ||
|
||
def update_conf(self): | ||
Logger.log_message('Updating the plugin configurations', | ||
LOG_LEVELS.DEBUG) | ||
try: | ||
request_data = request.json | ||
# validate the new data | ||
validate_schema(self.conf_schema_path, request_data) | ||
# update the new values | ||
self.conf.update_config_file_values(request_data) | ||
self.conf.update_config_file(self.conf.config_file) | ||
#### | ||
_response = self.conf.conf_to_dict(self.conf_schema_path) | ||
return make_response(_response) | ||
except Exception as ex: | ||
Logger.log_message(f'Updating the plugin configurations has been failed: {str(ex)}', | ||
LOG_LEVELS.ERROR) | ||
raise ex |
50 changes: 50 additions & 0 deletions
50
plugins/events_history_plugin/src/events_history/api/events_history_api.py
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Copyright © 2013-2023 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. | ||
# | ||
# This software product is a proprietary product of Nvidia Corporation and its affiliates | ||
# (the "Company") and all right, title, and interest in and to the software | ||
# product, including all associated intellectual property rights, are and | ||
# shall remain exclusively with the Company. | ||
# | ||
# This software product is governed by the End User License Agreement | ||
# provided with the software product. | ||
# @author: Abeer Moghrabi | ||
# @date: Aug 9, 2023 | ||
# | ||
from flask import make_response, request | ||
from http import HTTPStatus | ||
|
||
from utils.flask_server.base_flask_api_server import BaseAPIApplication | ||
from utils.config_parser import InvalidConfRequest | ||
from utils.logger import Logger, LOG_LEVELS | ||
from mgr.events_history_mgr import EventsHistoryMgr | ||
|
||
|
||
class EventsHistoryApi(BaseAPIApplication): | ||
|
||
def __init__(self): | ||
super(EventsHistoryApi, self).__init__() | ||
self.event_mgr = EventsHistoryMgr.getInstance() | ||
|
||
|
||
def _get_error_handlers(self): | ||
return [ | ||
(InvalidConfRequest, | ||
lambda e: (str(e), HTTPStatus.BAD_REQUEST)) | ||
] | ||
|
||
def _get_routes(self): | ||
return { | ||
self.get_events_history: dict(urls=["/"], methods=["GET"]), | ||
} | ||
|
||
def get_events_history(self): | ||
try: | ||
# TODO implement get events history | ||
return make_response({}) | ||
except Exception as e: | ||
Logger.log_message("Error occurred while getting events history: " + str(e), | ||
LOG_LEVELS.ERROR) | ||
raise e | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still mellanox?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, all other plugins use mellanox as prefix