From e5fbed3341237481793d36307ef217ab2053bee2 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Thu, 21 Oct 2021 10:11:36 +0000 Subject: [PATCH 1/8] Packages in requirements updated (invoke+requests added) --- requirements.txt | 4 +++- requirements_dev.txt | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b628b95..dc7e918 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,6 @@ flake8==3.9.2 coverage==4.5.4 Click==8.0.1 pytest==6.2.4 -cookiecutter==1.7.3 \ No newline at end of file +cookiecutter==1.7.3 +invoke==1.6.0 +requests==2.26.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 3bf2b36..b079ef5 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -10,3 +10,5 @@ twine Click==8.0.1 pytest==6.2.4 cookiecutter==1.7.3 +invoke==1.6.0 +requests==2.26.0 From 2242729b6e084abf9b4581a2843ab9680d2222f6 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Thu, 21 Oct 2021 14:25:16 +0000 Subject: [PATCH 2/8] some changes in setup.py --- setup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b165b26..6cd10ea 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ """The setup script.""" from setuptools import setup, find_packages +from pathlib import Path with open('README.rst') as readme_file: readme = readme_file.read() @@ -10,7 +11,8 @@ with open('HISTORY.rst') as history_file: history = history_file.read() -requirements = ['Click>=7.0', 'Cookiecutter', ] +with Path('requirements.txt').open() as file: + INSTALL_REQUIERES = file.readlines() test_requirements = ['pytest>=3', ] @@ -33,7 +35,7 @@ 'evolved5g=evolved5g.cli:cli', ], }, - install_requires=requirements, + install_requires=INSTALL_REQUIERES, license="Apache Software License 2.0", long_description=readme + '\n\n' + history, include_package_data=True, From a6ff93f3d283a14e754a1084c125e2595a7e97d4 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Tue, 26 Oct 2021 14:39:24 +0000 Subject: [PATCH 3/8] Add changes made by ATOS. Add new class, and pipeline command --- evolved5g/cli.py | 74 +++++++++-------------------- evolved5g/cli_helper.py | 101 ++++++++++++++++++++++++++++++++++++++++ evolved5g/utils.py | 4 +- files.txt | 34 ++++++++++++++ setup.py | 1 + 5 files changed, 161 insertions(+), 53 deletions(-) create mode 100644 evolved5g/cli_helper.py create mode 100644 files.txt diff --git a/evolved5g/cli.py b/evolved5g/cli.py index 96dc748..6a0234b 100644 --- a/evolved5g/cli.py +++ b/evolved5g/cli.py @@ -1,67 +1,39 @@ """Console script for evolved5g.""" import click from .utils import cookiecutter_generate -import os - - -@click.command() -def main(args=None): - """Console script for evolved5g.""" - click.echo( - "The console script for Evolved5G, this messages comes from evolved5g.cli.main") - click.echo("See click documentation at https://click.palletsprojects.com/") - return 0 - -# Creating Command group +from evolved5g.cli_helper import CLI_helper @click.group() @click.version_option() -def cli(): +@click.pass_context +def cli(ctx): """Console interface for EVOLVED-5G H2020 project""" - pass + ctx.ensure_object(dict) + ctx.obj["helper"] = CLI_helper() -@click.command() +@cli.command() @click.option('--no-input', type=bool, is_flag=True, help='Enables no prompt from the CLI during template generation', default=False) @click.option('-r', '--repo-name', type=str, help='Enter Repository name') @click.option('-p', '--package-name', type=str, help='Enter package name') @click.option('-t', '--template', type=str, help="Provide template location for custom package") -def generate(no_input, repo_name, package_name, template): +@click.pass_context +def generate(ctx,no_input, repo_name, package_name, template): """Generate EVOLVED-5G compliant NetApp from template""" - # __location__ = os.path.realpath(os.path.join( - # os.getcwd(), os.path.dirname(__file__), "..")) - # location = (__location__ + '/cookiecutter_template/') - # click.echo(__location__) # -- for debug - extra = {} - if repo_name: - extra['repoName'] = repo_name - if package_name: - extra['packageName'] = package_name - if template: - cookiecutter_generate(template,no_input=no_input,extra_context=extra) - return - location = "gh:EVOLVED-5G/template" # location to github package - # Create project from the github package template - cookiecutter_generate(location, no_input=no_input, extra_context=extra) - - -# @click.command() -# def connect(): -# """Connect repository to CI/CD""" -# # Connect repository to CI/CD TODO -# click.echo("Connecting Repo to CI/CD") - -# @click.command() -# @click.option('-r', '--repeat', type=int, help='times to repeat', default=1) -# @click.option('-n', '--name', type=str, help='Name to greet', default='World') -# def test(repeat, name): -# """For Testing purposes, TODO Delete""" -# for i in range(repeat): -# click.echo(f'Hello {name}. This is a test') - -#cli.add_command(test) -# cli.add_command(connect) - -cli.add_command(generate) \ No newline at end of file + ctx.obj["helper"].generate(no_input, repo_name, package_name, template) + +@cli.command() +def run_pipeline(): + """ + """ + cli_helper = CLI_helper() + cli_helper.run_pipeline() + +@cli.command() +def check_pipeline(): + """ + """ + cli_helper = CLI_helper() + cli_helper.check_pipeline() diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py new file mode 100644 index 0000000..515c0bd --- /dev/null +++ b/evolved5g/cli_helper.py @@ -0,0 +1,101 @@ +from .utils import cookiecutter_generate +import requests +import json +import json.decoder + + + +class CLI_helper: + + def __init__(self): + + self.url_curl = "https://epg-api.tid.es/api/executions" + self.url_token = "https://epg-api.tid.es/api/auth" + self.username_token = "usu_Evolved5g" + self.password_token = "evolved5g" + self.branch = "nginx-unprivileged" + self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": None } + + def generate(self, no_input, repo_name, package_name, template): + """Generate EVOLVED-5G compliant NetApp from template""" + # extra = {} + # if repo_name: + # extra['repoName'] = repo_name + # if package_name: + # extra['packageName'] = package_name + # if template: + # cookiecutter_generate(template,no_input=no_input,extra_context=extra) + # return + location = "gh:EVOLVED-5G/template" + cookiecutter_generate(location, no_input=no_input) #extra_context=extra) + + def curl(self, tokeng, branchorpipe, mode): + + self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": tokeng } + + if mode == "build" or mode == "deploy" or mode == "destroy": + repo = input("Please write down your repo:\n") + data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + branchorpipe + '"} }' + resp = requests.post(self.url_curl, headers=self.header, data=data) + + return (resp.json()["id"]) + + if mode == "check": + resp = requests.get(f"{self.url_curl}/{branchorpipe}", headers=self.header) + + return (resp.json()) + + def generate_token(self): + + self.header = { "content-Type":"application/json", "accept": None, "Authorization": None } + data = '{ "username": "usu_Evolved5g", "password": "evolved5g" }' + resp = requests.post(self.url_token, headers=self.header, data=data) + + # print ("This is your token:\n", resp.json()["access_token"] + "\n") + return(resp.json()["access_token"]) + + + def run_pipeline(self): + """Run the build pipeline for the EVOLVED-5G NetApp""" + mode = input("Type in which pipeline you want to run: build, deploy or destroy:\n ") + result = self.curl(self.generate_token(), self.branch, mode) + + print ("The ID of your pipeline is:\n", result,"\n") + + + def check_pipeline(self): + + """Check the status of the pipeline for the EVOLVED-5G NetApp""" + pipelineid = input("Please write down the pipeline ID you want to check:\n") + + result = self.curl(self.generate_token(), pipelineid, "check") + + if result["status"] == "QUEUED": + print(result) + else: + console = (json.dumps(result["console_log"]).split('\\n')) + + for element in console: + if "] { (" in element: + print (element) + elif "[Pipeline]" not in element: + print (element) + elif "] stage" in element: + print (element) + + + # if "message" in result: + # print (result["message"]) + + # else: + # console = (json.dumps(result["console_log"]).split('\\n')) + + # for element in console: + # if "] { (" in element: + # print (element) + # elif "[Pipeline]" not in element: + # print (element) + # elif "] stage" in element: + # print (element) + + diff --git a/evolved5g/utils.py b/evolved5g/utils.py index 8b391d3..ada1215 100644 --- a/evolved5g/utils.py +++ b/evolved5g/utils.py @@ -4,5 +4,5 @@ def cookiecutter_generate(location, no_input=False, **kwargs): """ Create project from the cookiecutter template in location given with the appropriate arguments. """ - extra_context = kwargs['extra_context'] - cookiecutter(location, no_input=no_input, extra_context=extra_context) + # extra_context = kwargs['extra_context'] + cookiecutter(location, no_input=no_input) #, extra_context=extra_context) diff --git a/files.txt b/files.txt new file mode 100644 index 0000000..b60c181 --- /dev/null +++ b/files.txt @@ -0,0 +1,34 @@ +/usr/local/bin/chardetect +/usr/local/bin/cookiecutter +/usr/local/bin/coverage +/usr/local/bin/coverage-3.6 +/usr/local/bin/coverage3 +/usr/local/bin/evolved5g +/usr/local/bin/flake8 +/usr/local/bin/inv +/usr/local/bin/invoke +/usr/local/bin/normalizer +/usr/local/bin/py.test +/usr/local/bin/pycodestyle +/usr/local/bin/pyflakes +/usr/local/bin/pytest +/usr/local/bin/slugify +/usr/local/bin/watchmedo +/usr/local/bin/wheel +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/PKG-INFO +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/SOURCES.txt +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/dependency_links.txt +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/entry_points.txt +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/not-zip-safe +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/requires.txt +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/top_level.txt +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__init__.py +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/__init__.cpython-36.pyc +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/cli.cpython-36.pyc +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/cli_helper.cpython-36.pyc +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/sdk.cpython-36.pyc +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/utils.cpython-36.pyc +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/cli.py +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/cli_helper.py +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/sdk.py +/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/utils.py diff --git a/setup.py b/setup.py index 6cd10ea..522506c 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ entry_points={ 'console_scripts': [ 'evolved5g=evolved5g.cli:cli', + 'cli_helper= evolved5g.cli:cli_helper', ], }, install_requires=INSTALL_REQUIERES, From e788119277629a5b6809f3b257a02cc51cf3a547 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Tue, 26 Oct 2021 14:44:54 +0000 Subject: [PATCH 4/8] Minor changes --- files.txt | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 files.txt diff --git a/files.txt b/files.txt deleted file mode 100644 index b60c181..0000000 --- a/files.txt +++ /dev/null @@ -1,34 +0,0 @@ -/usr/local/bin/chardetect -/usr/local/bin/cookiecutter -/usr/local/bin/coverage -/usr/local/bin/coverage-3.6 -/usr/local/bin/coverage3 -/usr/local/bin/evolved5g -/usr/local/bin/flake8 -/usr/local/bin/inv -/usr/local/bin/invoke -/usr/local/bin/normalizer -/usr/local/bin/py.test -/usr/local/bin/pycodestyle -/usr/local/bin/pyflakes -/usr/local/bin/pytest -/usr/local/bin/slugify -/usr/local/bin/watchmedo -/usr/local/bin/wheel -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/PKG-INFO -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/SOURCES.txt -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/dependency_links.txt -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/entry_points.txt -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/not-zip-safe -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/requires.txt -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/EGG-INFO/top_level.txt -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__init__.py -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/__init__.cpython-36.pyc -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/cli.cpython-36.pyc -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/cli_helper.cpython-36.pyc -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/sdk.cpython-36.pyc -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/__pycache__/utils.cpython-36.pyc -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/cli.py -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/cli_helper.py -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/sdk.py -/usr/local/lib/python3.6/dist-packages/evolved5g-0.2.5-py3.6.egg/evolved5g/utils.py From ea1b097ce73d690c7a5318b0d376519de6352d88 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Tue, 26 Oct 2021 14:45:43 +0000 Subject: [PATCH 5/8] Minor changes --- evolved5g/cli_helper.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py index 515c0bd..752cffb 100644 --- a/evolved5g/cli_helper.py +++ b/evolved5g/cli_helper.py @@ -82,20 +82,6 @@ def check_pipeline(self): print (element) elif "] stage" in element: print (element) - - - # if "message" in result: - # print (result["message"]) - - # else: - # console = (json.dumps(result["console_log"]).split('\\n')) - - # for element in console: - # if "] { (" in element: - # print (element) - # elif "[Pipeline]" not in element: - # print (element) - # elif "] stage" in element: - # print (element) + From 5ae8a36ca6370bf7d2506b84fd5f8d06afe6b5e1 Mon Sep 17 00:00:00 2001 From: Stavros Kolometsos <stkolome@gmail.com> Date: Wed, 27 Oct 2021 12:51:36 +0300 Subject: [PATCH 6/8] Replace print with click.echo() Click has already a function integrated, that works a little better than print. Justification: https://click.palletsprojects.com/en/5.x/quickstart/#echoing . Minor detail but maybe useful. --- evolved5g/cli_helper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py index 752cffb..cf45c33 100644 --- a/evolved5g/cli_helper.py +++ b/evolved5g/cli_helper.py @@ -2,6 +2,7 @@ import requests import json import json.decoder +from click import echo @@ -60,7 +61,7 @@ def run_pipeline(self): mode = input("Type in which pipeline you want to run: build, deploy or destroy:\n ") result = self.curl(self.generate_token(), self.branch, mode) - print ("The ID of your pipeline is:\n", result,"\n") + echo("The ID of your pipeline is:\n", result,"\n") def check_pipeline(self): @@ -71,17 +72,17 @@ def check_pipeline(self): result = self.curl(self.generate_token(), pipelineid, "check") if result["status"] == "QUEUED": - print(result) + echo(result) else: console = (json.dumps(result["console_log"]).split('\\n')) for element in console: if "] { (" in element: - print (element) + echo(element) elif "[Pipeline]" not in element: - print (element) + echo(element) elif "] stage" in element: - print (element) + echo(element) From de84a76fba57aca3b0fa4807a51d49d4cebbd175 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Wed, 27 Oct 2021 12:03:00 +0000 Subject: [PATCH 7/8] changes in good practice and error control --- evolved5g/cli.py | 7 ++++--- evolved5g/cli_helper.py | 40 +++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/evolved5g/cli.py b/evolved5g/cli.py index 6a0234b..f048757 100644 --- a/evolved5g/cli.py +++ b/evolved5g/cli.py @@ -25,11 +25,12 @@ def generate(ctx,no_input, repo_name, package_name, template): ctx.obj["helper"].generate(no_input, repo_name, package_name, template) @cli.command() -def run_pipeline(): +@click.option('--mode',type=click.Choice(['build', 'deploy','destroy'], case_sensitive=False)) +@click.pass_context +def run_pipeline(ctx, mode): """ """ - cli_helper = CLI_helper() - cli_helper.run_pipeline() + ctx.obj["helper"].run_pipeline(mode) @cli.command() def check_pipeline(): diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py index cf45c33..55e3783 100644 --- a/evolved5g/cli_helper.py +++ b/evolved5g/cli_helper.py @@ -30,46 +30,44 @@ def generate(self, no_input, repo_name, package_name, template): location = "gh:EVOLVED-5G/template" cookiecutter_generate(location, no_input=no_input) #extra_context=extra) - def curl(self, tokeng, branchorpipe, mode): + # def curl(self, tokeng, branchorpipe, mode): - self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": tokeng } + # self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": tokeng } - if mode == "build" or mode == "deploy" or mode == "destroy": - repo = input("Please write down your repo:\n") - data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + branchorpipe + '"} }' - resp = requests.post(self.url_curl, headers=self.header, data=data) + # if mode == "build" or mode == "deploy" or mode == "destroy": + # repo = input("Please write down your repo:\n") + # data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + branchorpipe + '"} }' + # resp = requests.post(self.url_curl, headers=self.header, data=data) - return (resp.json()["id"]) + # return (resp.json()["id"]) - if mode == "check": - resp = requests.get(f"{self.url_curl}/{branchorpipe}", headers=self.header) + # if mode == "check": + # resp = requests.get(f"{self.url_curl}/{branchorpipe}", headers=self.header) - return (resp.json()) + # return (resp.json()) def generate_token(self): self.header = { "content-Type":"application/json", "accept": None, "Authorization": None } data = '{ "username": "usu_Evolved5g", "password": "evolved5g" }' resp = requests.post(self.url_token, headers=self.header, data=data) - - # print ("This is your token:\n", resp.json()["access_token"] + "\n") return(resp.json()["access_token"]) - - def run_pipeline(self): + def run_pipeline(self, mode): """Run the build pipeline for the EVOLVED-5G NetApp""" - mode = input("Type in which pipeline you want to run: build, deploy or destroy:\n ") - result = self.curl(self.generate_token(), self.branch, mode) - - echo("The ID of your pipeline is:\n", result,"\n") + self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } + repo = input("Please write down your repo:\n") + data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + self.branch + '"} }' + resp = requests.post(self.url_curl, headers=self.header, data=data) + echo(resp.json()["id"]) - def check_pipeline(self): """Check the status of the pipeline for the EVOLVED-5G NetApp""" + self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } pipelineid = input("Please write down the pipeline ID you want to check:\n") - - result = self.curl(self.generate_token(), pipelineid, "check") + resp = requests.get(f"{self.url_curl}/{pipelineid}", headers=self.header) + result = resp.json() if result["status"] == "QUEUED": echo(result) From c63c51eec46ccccab61aa821362dd0811abddc3f Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos <paula.encinar@atos.net> Date: Wed, 27 Oct 2021 15:41:27 +0000 Subject: [PATCH 8/8] ADD new fields --- evolved5g/cli.py | 12 +++++++----- evolved5g/cli_helper.py | 26 +++++--------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/evolved5g/cli.py b/evolved5g/cli.py index f048757..08b4080 100644 --- a/evolved5g/cli.py +++ b/evolved5g/cli.py @@ -26,15 +26,17 @@ def generate(ctx,no_input, repo_name, package_name, template): @cli.command() @click.option('--mode',type=click.Choice(['build', 'deploy','destroy'], case_sensitive=False)) +@click.option('--repo',type=str, help='Enter repo name') @click.pass_context -def run_pipeline(ctx, mode): +def run_pipeline(ctx, mode, repo): """ """ - ctx.obj["helper"].run_pipeline(mode) + ctx.obj["helper"].run_pipeline(mode,repo) @cli.command() -def check_pipeline(): +@click.option('--id',type=int, help='Enter pipeline id') +@click.pass_context +def check_pipeline(ctx, id): """ """ - cli_helper = CLI_helper() - cli_helper.check_pipeline() + ctx.obj["helper"].check_pipeline(id) diff --git a/evolved5g/cli_helper.py b/evolved5g/cli_helper.py index 55e3783..569882f 100644 --- a/evolved5g/cli_helper.py +++ b/evolved5g/cli_helper.py @@ -30,22 +30,6 @@ def generate(self, no_input, repo_name, package_name, template): location = "gh:EVOLVED-5G/template" cookiecutter_generate(location, no_input=no_input) #extra_context=extra) - # def curl(self, tokeng, branchorpipe, mode): - - # self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": tokeng } - - # if mode == "build" or mode == "deploy" or mode == "destroy": - # repo = input("Please write down your repo:\n") - # data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + branchorpipe + '"} }' - # resp = requests.post(self.url_curl, headers=self.header, data=data) - - # return (resp.json()["id"]) - - # if mode == "check": - # resp = requests.get(f"{self.url_curl}/{branchorpipe}", headers=self.header) - - # return (resp.json()) - def generate_token(self): self.header = { "content-Type":"application/json", "accept": None, "Authorization": None } @@ -53,20 +37,20 @@ def generate_token(self): resp = requests.post(self.url_token, headers=self.header, data=data) return(resp.json()["access_token"]) - def run_pipeline(self, mode): + def run_pipeline(self, mode, repo): """Run the build pipeline for the EVOLVED-5G NetApp""" self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } - repo = input("Please write down your repo:\n") + # repo = input("Please write down your repo:\n") data = '{ "instance": "pro-dcip-evol5-01.hi.inet", "job": "dummy-netapp/'+ mode +'", "parameters": { "VERSION": "1.0", "GIT_URL": "https://github.com/EVOLVED-5G/' + repo +'", "GIT_BRANCH": "' + self.branch + '"} }' resp = requests.post(self.url_curl, headers=self.header, data=data) echo(resp.json()["id"]) - def check_pipeline(self): + def check_pipeline(self, id): """Check the status of the pipeline for the EVOLVED-5G NetApp""" self.header = { "content-Type":"application/json", "accept": "application/json", "Authorization": self.generate_token() } - pipelineid = input("Please write down the pipeline ID you want to check:\n") - resp = requests.get(f"{self.url_curl}/{pipelineid}", headers=self.header) + # pipelineid = input("Please write down the pipeline ID you want to check:\n") + resp = requests.get(f"{self.url_curl}/{id}", headers=self.header) result = resp.json() if result["status"] == "QUEUED":