-
Notifications
You must be signed in to change notification settings - Fork 23
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
7839f2b
98af278
f3b4073
c410dc4
2b812ec
04e1ce7
0df4b84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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.9 python3-pip vim curl sudo | ||
|
||
RUN python3.9 -m pip install -r ${BASE_PATH}/${SRC_BASE_DIR}/src/${PLUGIN_NAME}/requirements.txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not python3 (which is usually symlink to python3.x available) |
||
|
||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. yes, all other plugins use mellanox as prefix |
||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
port=8686 |
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 | ||
|
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.9 /opt/ufm/ufm_plugin_events_history/events_history_plugin/src/events_history_plugin/app.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. python3? |
||
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 |
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 |
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 |
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 | ||
# |
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 |
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 | ||
|
||
|
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.
value for plugin name?
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.
Done