Skip to content

Commit

Permalink
Reverting to the state of the project at commit bbde831 (where pipeli…
Browse files Browse the repository at this point in the history
…nes and libraries are working)
  • Loading branch information
rimarala committed Oct 29, 2021
1 parent 31a4f76 commit 08a044c
Show file tree
Hide file tree
Showing 75 changed files with 16,883 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/

# C extensions
*.so

.idea
# Distribution / packaging
.Python
env/
Expand Down
54 changes: 46 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*************
Evolved5G_CLI
Evolved5G CLI & SDK
*************


Expand All @@ -14,7 +14,7 @@ Evolved5G_CLI



Evolved5G CLI prototype
Evolved5G CLI prototype


* Free software: Apache Software License 2.0
Expand All @@ -26,6 +26,7 @@ Features

* Generate a new python NetApp from a template
* Assist in connecting the new NetApp & repo with EVOLVED-5G CI/CD pipeline
* SDK Libraries for interacting with the 5G-API

============
Installation
Expand Down Expand Up @@ -78,10 +79,9 @@ Once you have a copy of the source, you can install it with:
.. _tarball: https://github.com/EVOLVED-5G/SDK-CLI/tarball/master

============
Usage
CLI Usage
============


Run the following command to access the documentation/help page and read about the various options

.. code-block:: console
Expand All @@ -96,18 +96,56 @@ To generate a new NetApp project run the following command. You will be asked fo
.. code-block:: console
$ evolved5g generate
or to learn more about the available options

.. code-block:: console
$ evolved5g generate --help
============
SDK - Libraries
============

At the current release the SDK contains one class "**LocationSubscriber**"
that allows you to track devices and retrieve updates about their location.
You can use LocationSubscriber to create subscriptions, where each one of them can be used to track a device.

Examples of usage /Have a look at the code
----
Have a look at the examples folder for code samples on how to use the SDK Library.

`Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_

Prerequisites / How to start
----

Install the requirements_dev.txt

pip install -r requirements_dev.txt

Make sure you have initiated the NEF_EMULATOR at url http://localhost:8888 (See `here <https://github.com/EVOLVED-5G/NEF_emulator>`_ for instructions),
you have logged in to the interface, clicked on the map and have started the simulation.
Then run a webserver in order to capture the callback post requests from NEF EMULATOR: On the terminal run the following commands to initiaze the webserver.


export FLASK_APP=/home/user/evolved-5g/SDK-CLI/examples/api.py

export FLASK_ENV=development

python -m flask run --host=0.0.0.0

where FLASK_APP should point to the absolute path of the SDK-CLI/examples/api.py file.
These commands will initialize a web server at http://127.0.0.1:5000/

Now you can run `Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_
You should be able to view the location updates, printed in the terminal that runs the FLASK webserver

Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
7 changes: 3 additions & 4 deletions docs/usage.rst → docs/cli.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
============
Usage
CLI
============


Expand All @@ -17,10 +17,9 @@ To generate a new NetApp project run the following command. You will be asked fo
.. code-block:: console
$ evolved5g generate
or to learn more about the available options

.. code-block:: console
$ evolved5g generate --help
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Welcome to Evolved5G_CLI's documentation!

readme
installation
usage
cli
libraries
modules
contributing
history
Expand Down
37 changes: 37 additions & 0 deletions docs/libraries.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SDK - Libraries
============

At the current release the SDK contains one class "**LocationSubscriber**"
that allows you to track devices and retrieve updates about their location.
You can use LocationSubscriber to create subscriptions, where each one of them can be used to track a device.

Examples of usage /Have a look at the code
----
Have a look at the examples folder for code samples on how to use the SDK Library.

`Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_

Prerequisites / How to start
----

Install the requirements_dev.txt

pip install -r requirements_dev.txt

Make sure you have initiated the NEF_EMULATOR at url http://localhost:8888 (See `here <https://github.com/EVOLVED-5G/NEF_emulator>`_ for instructions),
you have logged in to the interface, clicked on the map and have started the simulation.

Then run a webserver in order to capture the callback post requests from NEF EMULATOR: On the terminal run the following commands to initialize the webserver.


export FLASK_APP=/home/user/evolved-5g/SDK-CLI/examples/api.py

export FLASK_ENV=development

python -m flask run --host=0.0.0.0

where FLASK_APP should point to the absolute path of the SDK-CLI/examples/api.py file.
These commands will initialize a web server at http://127.0.0.1:5000/

Now you can run `Location subscriber example <https://github.com/EVOLVED-5G/SDK-CLI/blob/libraries/examples/location_subscriber_examples.py>`_
You should be able to view the location updates, printed in the terminal that runs the FLASK webserver
77 changes: 26 additions & 51 deletions evolved5g/cli.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,42 @@
"""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)
ctx.obj["helper"].generate(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, repo):
"""
"""
ctx.obj["helper"].run_pipeline(mode,repo)

@cli.command()
@click.option('--id',type=int, help='Enter pipeline id')
@click.pass_context
def check_pipeline(ctx, id):
"""
"""
ctx.obj["helper"].check_pipeline(id)
70 changes: 70 additions & 0 deletions evolved5g/cli_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from .utils import cookiecutter_generate
import requests
import json
import json.decoder
from click import echo



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 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)
return(resp.json()["access_token"])

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

if result["status"] == "QUEUED":
echo(result)
else:
console = (json.dumps(result["console_log"]).split('\\n'))

for element in console:
if "] { (" in element:
echo(element)
elif "[Pipeline]" not in element:
echo(element)
elif "] stage" in element:
echo(element)



Loading

0 comments on commit 08a044c

Please sign in to comment.