Skip to content

Commit

Permalink
Merge pull request EVOLVED-5G#12 from EVOLVED-5G/good-practices-clic
Browse files Browse the repository at this point in the history
Good practices cli
  • Loading branch information
rimarala authored Oct 28, 2021
2 parents e4d4bf5 + c63c51e commit 1681976
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
15 changes: 9 additions & 6 deletions evolved5g/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ 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.option('--repo',type=str, help='Enter repo name')
@click.pass_context
def run_pipeline(ctx, mode, repo):
"""
"""
cli_helper = CLI_helper()
cli_helper.run_pipeline()
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)
40 changes: 11 additions & 29 deletions evolved5g/cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,28 @@ 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 }
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, repo):
"""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)
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"])

echo("The ID of your pipeline is:\n", result,"\n")


def check_pipeline(self):
def check_pipeline(self, id):

"""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")
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}/{id}", headers=self.header)
result = resp.json()

if result["status"] == "QUEUED":
echo(result)
Expand Down

0 comments on commit 1681976

Please sign in to comment.