From de84a76fba57aca3b0fa4807a51d49d4cebbd175 Mon Sep 17 00:00:00 2001 From: pencinarsanz-atos Date: Wed, 27 Oct 2021 12:03:00 +0000 Subject: [PATCH 1/2] 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 Date: Wed, 27 Oct 2021 15:41:27 +0000 Subject: [PATCH 2/2] 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":