Skip to content

Commit

Permalink
changes in good practice and error control
Browse files Browse the repository at this point in the history
  • Loading branch information
pencinarsanz-atos committed Oct 27, 2021
1 parent 1fcfb70 commit de84a76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
7 changes: 4 additions & 3 deletions evolved5g/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
40 changes: 19 additions & 21 deletions evolved5g/cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de84a76

Please sign in to comment.