Distribute python package with script wrapper 30/2930/3
authorZhe <zhehuang@research.att.com>
Mon, 23 Mar 2020 19:15:28 +0000 (15:15 -0400)
committerZhe Huang <zhehuang@research.att.com>
Thu, 26 Mar 2020 17:22:18 +0000 (17:22 +0000)
Issue-ID: RIC-215
Signed-off-by: Zhe <zhehuang@research.att.com>
Change-Id: Ib82e4e13b48d2b91e2c42f7be680dfb8624d063a

ci/xapp_onboarder/Dockerfile
xapp_onboarder/setup.py
xapp_onboarder/xapp_onboarder/cli [deleted file]
xapp_onboarder/xapp_onboarder/helm_controller/xApp_builder.py
xapp_onboarder/xapp_onboarder/server/cli.py
xapp_onboarder/xapp_onboarder/server/server.py
xapp_onboarder/xapp_onboarder/server/settings.py
xapp_onboarder/xapp_onboarder/xapp_onboarder [deleted file]

index d9c9d3b..28a72b1 100644 (file)
@@ -18,7 +18,7 @@ FROM python:3.7-alpine
 
 ADD ./xapp_onboarder /opt/xapp_onboarder
 
-RUN cd /opt/xapp_onboarder && pip3 install . && ln -s $(pip show xapp_onboarder | grep Location | awk '{printf  $2 "/xapp_onboarder/xapp_onboarder"}') /usr/local/bin/xapp_onboarder && ln -s $(pip show xapp_onboarder | grep Location | awk '{printf  $2 "/xapp_onboarder/cli"}') /usr/local/bin/cli && rm -r /opt/xapp_onboarder
+RUN cd /opt/xapp_onboarder && pip3 install . && rm -r /opt/xapp_onboarder
 
 ARG HELM_VERSION="2.12.3"
 
index b6c9578..41bce12 100644 (file)
@@ -41,4 +41,10 @@ setup(
     ],
     python_requires='>=3.6',
     install_requires=requirements,
+    entry_points={
+        'console_scripts': [
+            'xapp_onboarder = xapp_onboarder.server.server:main',
+            'cli = xapp_onboarder.server.cli:run'
+        ]
+    },
 )
diff --git a/xapp_onboarder/xapp_onboarder/cli b/xapp_onboarder/xapp_onboarder/cli
deleted file mode 100755 (executable)
index 8e1c62b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env python3
-################################################################################
-#   Copyright (c) 2020 AT&T Intellectual Property.                             #
-#                                                                              #
-#   Licensed under the Apache License, Version 2.0 (the "License");            #
-#   you may not use this file except in compliance with the License.           #
-#   You may obtain a copy of the License at                                    #
-#                                                                              #
-#       http://www.apache.org/licenses/LICENSE-2.0                             #
-#                                                                              #
-#   Unless required by applicable law or agreed to in writing, software        #
-#   distributed under the License is distributed on an "AS IS" BASIS,          #
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
-#   See the License for the specific language governing permissions and        #
-#   limitations under the License.                                             #
-################################################################################
-import logging.config
-import pkg_resources
-from xapp_onboarder.server.cli import run
-
-if __name__ == "__main__":
-
-    logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
-    logging.config.fileConfig(logger_config)
-    run()
index 9506a46..1018f40 100644 (file)
@@ -67,10 +67,19 @@ class xApp():
             shutil.rmtree(self.chart_workspace_path)
         os.makedirs(self.chart_workspace_path)
         shutil.copytree(resource_filename( 'xapp_onboarder', 'resources/xapp-std'), self.chart_workspace_path + '/' + self.chart_name)
-        self.helm_client_path = settings.CHART_WORKSPACE_PATH + '/helm'
         self.setup_helm()
 
     def setup_helm(self):
+        self.helm_client_path = 'helm'
+        try:
+            process = subprocess.run([self.helm_client_path], stdout=PIPE, stderr=PIPE, check=True)
+
+        except Exception as err:
+            print(err)
+            self.download_helm()
+            self.helm_client_path = settings.CHART_WORKSPACE_PATH + '/helm'
+
+    def download_helm(self):
         if not os.path.isfile(settings.CHART_WORKSPACE_PATH + '/helm'):
             log.info("Helm client missing. Trying to download it.")
             helm_file_name = "helm-v{}-{}-amd64.tar.gz".format(settings.HELM_VERSION, platform.system().lower())
index 344541d..8888576 100755 (executable)
@@ -112,9 +112,10 @@ class cli():
         return json.dumps(message, indent=4, sort_keys=True)
 
 def run():
+    logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
+    logging.config.fileConfig(logger_config)
     fire.Fire(cli(), name='xapp_onboarder')
 
 if __name__ == "__main__":
-    logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
-    logging.config.fileConfig(logger_config)
+
     run()
index a07a7ba..838aba7 100644 (file)
@@ -29,7 +29,6 @@ log = logging.getLogger(__name__)
 class server(object):
     def __init__(self):
         self.app = Flask(__name__)
-        self.app.config['SERVER_NAME'] = settings.FLASK_SERVER_NAME
         self.app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
         self.app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
         self.app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
@@ -46,9 +45,17 @@ class server(object):
 
     def run(self):
         log.info('>>>>> Starting development xapp_onboarder at http://{}/api/v1/ <<<<<'.format(self.app.config['SERVER_NAME']))
-        self.app.run(debug=settings.FLASK_DEBUG)
+        self.app.run(debug=settings.FLASK_DEBUG, host='0.0.0.0', port=settings.FLASK_PORT)
 
-if __name__ == "__main__":
+
+
+
+
+def main():
     logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
     logging.config.fileConfig(logger_config)
     server().run()
+
+if __name__ == "__main__":
+    main()
+
index 58c7392..8bc1a3f 100644 (file)
@@ -17,7 +17,7 @@
 import os
 
 # Flask settings
-FLASK_SERVER_NAME = os.environ.get('FLASK_SERVER_NAME') or '0.0.0.0:8888'
+FLASK_PORT = os.environ.get('FLASK_PORT') or '8888'
 FLASK_DEBUG = os.environ.get('FLASK_DEBUG') or True  # Do not use debug mode in production
 
 # Flask-Restplus settings
@@ -29,7 +29,7 @@ RESTPLUS_ERROR_404_HELP = os.environ.get('RESTPLUS_ERROR_404_HELP') or False
 # xapp_onboarder settings
 CHART_WORKSPACE_PATH = os.environ.get('CHART_WORKSPACE_PATH') or '/tmp/xapp_onboarder'
 CHART_REPO_URL = os.environ.get('CHART_REPO_URL') or 'http://0.0.0.0:8080'
-HTTP_TIME_OUT = os.environ.get('HTTP_TIME_OUT') or 10
+HTTP_TIME_OUT = int(os.environ.get('HTTP_TIME_OUT') or 10)
 HELM_VERSION = os.environ.get('HELM_VERSION') or '2.12.3'
 HTTP_RETRY = os.environ.get('HTTP_RETRY') or 3
 ALLOW_REDEPLOY = os.environ.get('ALLOW_REDEPLOY') or True
diff --git a/xapp_onboarder/xapp_onboarder/xapp_onboarder b/xapp_onboarder/xapp_onboarder/xapp_onboarder
deleted file mode 100755 (executable)
index a0efd4f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env python3
-################################################################################
-#   Copyright (c) 2020 AT&T Intellectual Property.                             #
-#                                                                              #
-#   Licensed under the Apache License, Version 2.0 (the "License");            #
-#   you may not use this file except in compliance with the License.           #
-#   You may obtain a copy of the License at                                    #
-#                                                                              #
-#       http://www.apache.org/licenses/LICENSE-2.0                             #
-#                                                                              #
-#   Unless required by applicable law or agreed to in writing, software        #
-#   distributed under the License is distributed on an "AS IS" BASIS,          #
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
-#   See the License for the specific language governing permissions and        #
-#   limitations under the License.                                             #
-################################################################################
-import logging.config
-import pkg_resources
-from xapp_onboarder.server.server import server
-
-if __name__ == "__main__":
-
-    logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
-    logging.config.fileConfig(logger_config)
-    server().run()
-