From 9f6571090b203922cabb0382226be0fa48d6e046 Mon Sep 17 00:00:00 2001 From: mirabal Date: Mon, 10 Apr 2017 20:05:40 +0200 Subject: [PATCH] Modify openvim code structure, improve py package - Move python code to osm_openvim folder - Python package install the code in a folder called osm_openvim Change-Id: I09f1cdac84418a6a34ceaec9a69c2315e10296a7 Signed-off-by: mirabal --- MANIFEST.in | 7 +- Makefile | 69 +++++++--- database_utils/migrate_vim_db.sh | 5 +- openflow | 4 +- openvimd.py => openvimd | 9 +- ODL.py => osm_openvim/ODL.py | 0 RADclass.py => osm_openvim/RADclass.py | 0 osm_openvim/__init__.py | 1 + .../auxiliary_functions.py | 0 .../definitionsClass.py | 0 dhcp_thread.py => osm_openvim/dhcp_thread.py | 0 floodlight.py => osm_openvim/floodlight.py | 0 host_thread.py => osm_openvim/host_thread.py | 0 httpserver.py => osm_openvim/httpserver.py | 0 onos.py => osm_openvim/onos.py | 0 .../openflow_conn.py | 0 .../openflow_thread.py | 0 openvimd.cfg => osm_openvim/openvimd.cfg | 0 ovim.py => osm_openvim/ovim.py | 13 +- vim_db.py => osm_openvim/vim_db.py | 0 vim_schema.py => osm_openvim/vim_schema.py | 0 scripts/{openvim-report.sh => openvim-report} | 0 ...rvice-floodlight.sh => service-floodlight} | 0 ...e-opendaylight.sh => service-opendaylight} | 0 .../{service-openvim.sh => service-openvim} | 0 setup.py | 124 +++++------------- setup_lite.py | 61 +++++++++ 27 files changed, 166 insertions(+), 127 deletions(-) rename openvimd.py => openvimd (98%) rename ODL.py => osm_openvim/ODL.py (100%) rename RADclass.py => osm_openvim/RADclass.py (100%) create mode 100644 osm_openvim/__init__.py rename auxiliary_functions.py => osm_openvim/auxiliary_functions.py (100%) rename definitionsClass.py => osm_openvim/definitionsClass.py (100%) rename dhcp_thread.py => osm_openvim/dhcp_thread.py (100%) rename floodlight.py => osm_openvim/floodlight.py (100%) rename host_thread.py => osm_openvim/host_thread.py (100%) rename httpserver.py => osm_openvim/httpserver.py (100%) rename onos.py => osm_openvim/onos.py (100%) rename openflow_conn.py => osm_openvim/openflow_conn.py (100%) rename openflow_thread.py => osm_openvim/openflow_thread.py (100%) rename openvimd.cfg => osm_openvim/openvimd.cfg (100%) rename ovim.py => osm_openvim/ovim.py (99%) rename vim_db.py => osm_openvim/vim_db.py (100%) rename vim_schema.py => osm_openvim/vim_schema.py (100%) rename scripts/{openvim-report.sh => openvim-report} (100%) rename scripts/{service-floodlight.sh => service-floodlight} (100%) rename scripts/{service-opendaylight.sh => service-opendaylight} (100%) rename scripts/{service-openvim.sh => service-openvim} (100%) create mode 100755 setup_lite.py diff --git a/MANIFEST.in b/MANIFEST.in index 8cf96f0..db411b1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ -include openvimd.cfg -recursive-include database_utils * -recursive-include scripts * +include openflow +include openvimd +include openvim +recursive-include osm_openvim * diff --git a/Makefile b/Makefile index 03b2f8b..3f9feff 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,69 @@ #!/usr/bin/env bash SHELL := /bin/bash -all: clean build pip install -lite: clean build pip install_lite +all: clean build pip install +lite: clean build_lite pip_lite install_lite + +clean: + rm -rf build + +prepare_lite: + mkdir -p build + cp -r osm_openvim/ build/lib_osm_openvim + rm build/lib_osm_openvim/httpserver.py + rm build/lib_osm_openvim/openvimd.cfg + cp -r database_utils build/lib_osm_openvim/ + cp -r scripts build/lib_osm_openvim/ + cp MANIFEST.in build/ + cp setup_lite.py build/setup.py + cp openflow build/ + sed -i "s/from osm_openvim/from lib_osm_openvim/g" build/openflow + sed -i "s/import osm_openvim/import lib_osm_openvim/g" build/openflow + sed -i "s/import osm_openvim; print osm_openvim.__path__[0]/import lib_osm_openvim; print lib_osm_openvim.__path__[0]/g" build/lib_osm_openvim/database_utils/migrate_vim_db.sh + sed -i "s/recursive-include osm_openvim */recursive-include lib_osm_openvim */g" build/MANIFEST.in + sed '/include openvimd/d' build/MANIFEST.in + sed '/include openvim/d' build/MANIFEST.in prepare: mkdir -p build - cp *.py build/ + cp -r osm_openvim/ build/ + cp -r scripts build/osm_openvim/ + cp -r database_utils build/osm_openvim/ + cp -r templates build/osm_openvim/ + cp -r test build/osm_openvim/ + cp -r charm build/osm_openvim/ cp MANIFEST.in build/ - cp openvimd.py openvimd; cp openvimd build/openvimd - cp ovim.py ovim; cp ovim build/ovim - cp openvim build/ + cp setup.py build/ cp openflow build/ - cp openvimd.cfg build/ - cp -r scripts build/ - cp -r database_utils build/ + cp openvim build/ + cp openvimd build/ build: prepare - python -m py_compile build/*.py + python -m py_compile build/osm_openvim/*.py -clean: - rm -rf build - rm -rf openvimd ovim +build_lite: prepare_lite + python -m py_compile build/lib_osm_openvim/*.py + +#deb: +# cd build && python setup.py --command-packages=stdeb.command bdist_deb +# +#debianize: +# cd build && python setup.py --command-packages=stdeb.command debianize + +pip: clean build + cd build; ./setup.py sdist -pip: +pip_lite: clean build_lite cd build; ./setup.py sdist -install: - cd build/dist; pip install lib* +install: clean build + cd build/dist; pip install osm_openvim* + +install_lite: clean build_lite + cd build/dist; pip install lib_osm_openvim-* + + -install_lite: - cd build/dist; pip install lib* diff --git a/database_utils/migrate_vim_db.sh b/database_utils/migrate_vim_db.sh index 599938d..6318769 100755 --- a/database_utils/migrate_vim_db.sh +++ b/database_utils/migrate_vim_db.sh @@ -92,8 +92,9 @@ shift $((OPTIND-1)) #GET OPENVIM VERSION OPENVIM_VER="$1" if [ -z "$OPENVIM_VER" ] -then - OPENVIM_VER=`ovim -v` +then + OVIM_PATH=`python -c 'import osm_openvim; print osm_openvim.__path__[0]' 2> /dev/null` + OPENVIM_VER=`python ${OVIM_PATH}/ovim.py -v 2> /dev/null` OPENVIM_VER=${OPENVIM_VER%%-r*} OPENVIM_VER=${OPENVIM_VER##*version } echo " Detected openvim version $OPENVIM_VER" diff --git a/openflow b/openflow index 4df9338..07261df 100755 --- a/openflow +++ b/openflow @@ -40,8 +40,8 @@ import imp import yaml import requests import logging -import openflow_conn -from openflow_thread import change_db2of, FlowBadFormat +import osm_openvim.openflow_conn as openflow_conn +from osm_openvim.openflow_thread import change_db2of, FlowBadFormat def of_switches(args): diff --git a/openvimd.py b/openvimd similarity index 98% rename from openvimd.py rename to openvimd index b9d9d82..0578ba5 100755 --- a/openvimd.py +++ b/openvimd @@ -31,9 +31,8 @@ and host controllers __author__ = "Alfonso Tierno" __date__ = "$10-jul-2014 12:07:15$" - -import httpserver -import auxiliary_functions as af +import osm_openvim.httpserver as httpserver +import osm_openvim.auxiliary_functions as af import sys import getopt import time @@ -44,15 +43,17 @@ from vim_schema import config_schema import logging import logging.handlers as log_handlers import socket -import ovim +import osm_openvim.ovim as ovim global config_dic global logger logger = logging.getLogger('vim') + class LoadConfigurationException(Exception): pass + def load_configuration(configuration_file): default_tokens ={'http_port':9080, 'http_host':'localhost', 'of_controller_nets_with_same_vlan':True, diff --git a/ODL.py b/osm_openvim/ODL.py similarity index 100% rename from ODL.py rename to osm_openvim/ODL.py diff --git a/RADclass.py b/osm_openvim/RADclass.py similarity index 100% rename from RADclass.py rename to osm_openvim/RADclass.py diff --git a/osm_openvim/__init__.py b/osm_openvim/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/osm_openvim/__init__.py @@ -0,0 +1 @@ + diff --git a/auxiliary_functions.py b/osm_openvim/auxiliary_functions.py similarity index 100% rename from auxiliary_functions.py rename to osm_openvim/auxiliary_functions.py diff --git a/definitionsClass.py b/osm_openvim/definitionsClass.py similarity index 100% rename from definitionsClass.py rename to osm_openvim/definitionsClass.py diff --git a/dhcp_thread.py b/osm_openvim/dhcp_thread.py similarity index 100% rename from dhcp_thread.py rename to osm_openvim/dhcp_thread.py diff --git a/floodlight.py b/osm_openvim/floodlight.py similarity index 100% rename from floodlight.py rename to osm_openvim/floodlight.py diff --git a/host_thread.py b/osm_openvim/host_thread.py similarity index 100% rename from host_thread.py rename to osm_openvim/host_thread.py diff --git a/httpserver.py b/osm_openvim/httpserver.py similarity index 100% rename from httpserver.py rename to osm_openvim/httpserver.py diff --git a/onos.py b/osm_openvim/onos.py similarity index 100% rename from onos.py rename to osm_openvim/onos.py diff --git a/openflow_conn.py b/osm_openvim/openflow_conn.py similarity index 100% rename from openflow_conn.py rename to osm_openvim/openflow_conn.py diff --git a/openflow_thread.py b/osm_openvim/openflow_thread.py similarity index 100% rename from openflow_thread.py rename to osm_openvim/openflow_thread.py diff --git a/openvimd.cfg b/osm_openvim/openvimd.cfg similarity index 100% rename from openvimd.cfg rename to osm_openvim/openvimd.cfg diff --git a/ovim.py b/osm_openvim/ovim.py similarity index 99% rename from ovim.py rename to osm_openvim/ovim.py index b369594..39ab578 100755 --- a/ovim.py +++ b/osm_openvim/ovim.py @@ -34,16 +34,17 @@ version_date = "Apr 2017" database_version = "0.17" #expected database schema version import threading -import vim_db +import osm_openvim.vim_db as vim_db import logging import imp -import host_thread as ht -import dhcp_thread as dt -import openflow_thread as oft +import argparse from netaddr import IPNetwork from jsonschema import validate as js_v, exceptions as js_e -import openflow_conn -import argparse +import osm_openvim.host_thread as ht +import osm_openvim.dhcp_thread as dt +import osm_openvim.openflow_thread as oft +import osm_openvim.openflow_conn as openflow_conn + HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 diff --git a/vim_db.py b/osm_openvim/vim_db.py similarity index 100% rename from vim_db.py rename to osm_openvim/vim_db.py diff --git a/vim_schema.py b/osm_openvim/vim_schema.py similarity index 100% rename from vim_schema.py rename to osm_openvim/vim_schema.py diff --git a/scripts/openvim-report.sh b/scripts/openvim-report similarity index 100% rename from scripts/openvim-report.sh rename to scripts/openvim-report diff --git a/scripts/service-floodlight.sh b/scripts/service-floodlight similarity index 100% rename from scripts/service-floodlight.sh rename to scripts/service-floodlight diff --git a/scripts/service-opendaylight.sh b/scripts/service-opendaylight similarity index 100% rename from scripts/service-opendaylight.sh rename to scripts/service-opendaylight diff --git a/scripts/service-openvim.sh b/scripts/service-openvim similarity index 100% rename from scripts/service-openvim.sh rename to scripts/service-openvim diff --git a/setup.py b/setup.py index 1d3138f..fac60ea 100755 --- a/setup.py +++ b/setup.py @@ -1,41 +1,16 @@ #!/usr/bin/env python -from setuptools import setup, find_packages -from setuptools.command.install import install -from os import system from setuptools import setup -__name__ = 'lib-osm-openvim' -__version__ = '1.0.0' -__description__ = 'OSM Openvim library' -__author__ = 'ETSI OSM' -__author_email__ = 'alfonso.tiernosepulveda@telefonica.com' -__maintainer__ = 'mirabal' -__maintainer_email__ = 'leonardo.mirabal@altran.com' -__license__ = 'Apache 2.0' -__url__ = 'https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=summary' - -cmd = 'cp ovim.py ovim' -system(cmd) - -__data_files__ = [('osm/openvim/', ['openvimd.cfg']), - ('osm/openvim/database_utils/', ['database_utils/vim_db_structure.sql', - 'database_utils/nets.sql', - 'database_utils/of_ports_pci_correspondence.sql', - 'database_utils/host_ranking.sql', - 'database_utils/dump_db.sh', - 'database_utils/init_vim_db.sh', - 'database_utils/migrate_vim_db.sh', - 'database_utils/install-db-server.sh' - ]), - ('osm/openvim/scripts/', ['scripts/service-openvim.sh', - 'scripts/openvim-report.sh', - 'scripts/service-floodlight.sh', - 'scripts/service-opendaylight.sh', - 'scripts/initopenvim.sh' - ]), - ] - +__name = 'osm_openvim' +__version = '1.0.0' +__description = 'OSM Openvim library' +__author = 'ETSI OSM' +__author_email = 'alfonso.tiernosepulveda@telefonica.com' +__maintainer = 'mirabal' +__maintainer_email = 'leonardo.mirabal@altran.com' +__license = 'Apache 2.0' +__url = 'https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=summary' _req = [ "asn1crypto", @@ -64,66 +39,31 @@ _req = [ "libvirt-python" ] -__scripts__ = ['openflow', 'openvim', 'ovim'] - - -class LibOpenvimInstaller(install): - lite = None - user_options = install.user_options + [('lite', None, "Don't install without Machine Learning modules.")] - - def initialize_options(self): - self.lite = None - install.initialize_options(self) - - def finalize_options(self): - install.finalize_options(self) - - def run(self): - - cmd = 'ln -sf -v /usr/local/osm/openvim/openvimd.cfg /etc/default/openvimd.cfg' - system(cmd) - cmd = 'ln -sf -v /usr/local/osm/openvim/openflow /usr/bin/openflow' - system(cmd) - cmd = 'ln -sf -v /usr/local/osm/openvim/ovim.py /usr/bin/ovim' - system(cmd) - - install.run(self) - - -setup(name=__name__, - version=__version__, - description=__description__, - long_description=__description__, - author=__author__, - author_email=__author_email__, - license=__license__, - maintainer=__maintainer__, - maintainer_email=__maintainer_email__, - url=__url__, - py_modules=['ovim', - 'openvimd', - 'vim_db', - 'httpserver', - 'RADclass', - 'auxiliary_functions', - 'dhcp_thread', - 'definitionsClass', - 'host_thread', - 'vim_schema', - 'ovim', - 'openflow_thread', - 'openflow_conn', - 'onos', - 'ODL', - 'floodlight', - ], - packages=find_packages() + ['database_utils'] + ['scripts'], - package_dir={__name__: __name__}, - package_data={'database_utils': ['*'], 'scripts': ['*']}, +__scripts__ = ['openflow', + 'openvim', + 'openvimd', + 'osm_openvim/scripts/service-openvim', + 'osm_openvim/scripts/service-opendaylight', + 'osm_openvim/scripts/service-floodlight', + 'osm_openvim/scripts/service-openvim', + 'osm_openvim/scripts/openvim-report', + 'osm_openvim/scripts/get_dhcp_lease.sh'] + +setup(name=__name, + version=__version, + description=__description, + long_description=__description, + author=__author, + author_email=__author_email, + license=__license, + maintainer=__maintainer, + maintainer_email=__maintainer_email, + url=__url, + packages=[__name], + package_dir={__name: __name}, scripts=__scripts__, - data_files=__data_files__, + package_data={'osm_openvim': ['*']}, include_package_data=True, - cmdclass={'install': LibOpenvimInstaller}, install_requires=_req ) diff --git a/setup_lite.py b/setup_lite.py new file mode 100755 index 0000000..cf38014 --- /dev/null +++ b/setup_lite.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +from setuptools import setup + +__name = 'lib_osm_openvim' +__version = '1.0.0' +__description = 'OSM Openvim library' +__author = 'ETSI OSM' +__author_email = 'alfonso.tiernosepulveda@telefonica.com' +__maintainer = 'mirabal' +__maintainer_email = 'leonardo.mirabal@altran.com' +__license = 'Apache 2.0' +__url = 'https://osm.etsi.org/gitweb/?p=osm/openvim.git;a=summary' + +_req = [ + "asn1crypto", + "cffi", + "enum34", + "functools32", + "idna", + "ipaddress", + "packaging", + "pbr", + "pkgconfig", + "pyasn1", + "pycparser", + "pycrypto", + "pyparsing", + "six", + "jsonschema", + "argcomplete", + "requests", + "PyYAML", + "requestsexceptions", + "netaddr", + "bottle", + "MySQL-python", + "paramiko", +] + +__scripts__ = ['openflow'] + +setup(name=__name, + version=__version, + description=__description, + long_description=__description, + author=__author, + author_email=__author_email, + license=__license, + maintainer=__maintainer, + maintainer_email=__maintainer_email, + url=__url, + packages=[__name], + package_dir={__name: __name}, + scripts=__scripts__, + package_data={'lib_osm_openvim': ['*']}, + include_package_data=True, + install_requires=_req + ) + + -- 2.25.1