1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

76 lines
1.8 KiB
Python
Raw Normal View History

2019-05-13 12:48:25 -07:00
#!/usr/bin/env python3
2019-05-12 19:22:17 -07:00
import os
import sys
import click
import random
import string
2019-05-12 19:22:17 -07:00
from logzero import logger
from passlib.hash import pbkdf2_sha256
2019-05-12 19:22:17 -07:00
from hyperglass import render as render
from hyperglass import hyperglass
@click.group()
def main():
pass
@main.command()
def clearcache():
try:
hyperglass.clearCache()
logger.info("Successfully cleared cache.")
except:
raise
logger.error("Failed to clear cache.")
@main.command()
def generatekey(string_length=16):
ld = string.ascii_letters + string.digits
api_key = "".join(random.choice(ld) for i in range(string_length))
key_hash = pbkdf2_sha256.hash(api_key)
click.echo(
"""
Your API Key is: {api_key}
Place your API Key in the `configuration.py` of your API module. For example, in: `hyperglass-frr/configuration.py`
Your Key Hash is: {key_hash}
Use this hash as the password for the device using the API module. For example, in: `hyperglass/hyperglass/configuration/devices.toml`
""".format(
api_key=api_key, key_hash=key_hash
)
)
2019-05-12 19:22:17 -07:00
@main.command()
def testserver():
try:
2019-05-14 12:03:58 -07:00
hyperglass.render.css.renderTemplate()
2019-05-12 19:22:17 -07:00
hyperglass.app.run(host="0.0.0.0", debug=True, port=5000)
logger.error("Started test server.")
except:
logger.error("Failed to start test server.")
raise
@main.command()
def render():
try:
hyperglass.render.css.renderTemplate()
logger.info("Successfully rendered CSS templates.")
except:
raise
logger.error("Failed to render CSS templates.")
try:
hyperglass.render.html.renderTemplate("index")
logger.info("Successfully rendered HTML templates.")
except:
raise
logger.error("Failed to render HTML templates.")
2019-05-12 19:22:17 -07:00
if __name__ == "__main__":
main()