Skip to content

Commit

Permalink
dropping virl v1 code - p1
Browse files Browse the repository at this point in the history
Dropped most of the (obvious) v1 code
Some v1 related stuff may remain
That would require a bit of fine combing
  • Loading branch information
sgherdao committed Nov 1, 2023
1 parent 626c2f2 commit da9c707
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 1,096 deletions.
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
include README.md
recursive-include virl/templates *
recursive-include virl/swagger/templates *
recursive-include virl/swagger/static *
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def readme():
author="Joe Clarke", # With a big thanks to its original author, Kevin Corbin
author_email="[email protected]",
url="https://github.com/CiscoDevNet/virlutils",
entry_points={"console_scripts": ["virl=virl.cli.main:virl", "cml=virl.cli.main:virl"]},
entry_points={"console_scripts": ["cml=virl.cli.main:virl"]},
packages=find_packages(),
package_data={"virl": ["templates/**/*.j2", "swagger/templates/*", "swagger/static/*", "examples/plugins/*"]},
include_package_data=True,
Expand Down
67 changes: 2 additions & 65 deletions virl/cli/console/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from virl.api import VIRLServer, ViewerPlugin, NoPluginError
from subprocess import call
from virl import helpers
from virl.helpers import get_cml_client, get_current_lab, safe_join_existing_lab, get_command
from virl.cli.views.console import console_table, console_table1
from virl.helpers import get_cml_client, get_current_lab, safe_join_existing_lab
from virl.cli.views.console import console_table
from virl2_client.exceptions import NodeNotFound
import platform

Expand Down Expand Up @@ -72,66 +72,3 @@ def console(node, display, **kwargs):
else:
click.secho("No current lab set", fg="red")
exit(1)


@click.command()
@click.argument("node", nargs=-1)
@click.option("--display/--none", default="False", help="Display Console information")
def console1(node, display, **kwargs):
"""
console for node
"""
server = VIRLServer()

if len(node) == 2:
# we received env and node name
env = node[0]
running = helpers.check_sim_running(env)
node = node[1]
elif display:
# only displaying output
env = "default"
running = helpers.check_sim_running(env)
node = None

elif len(node) == 1:
# assume default env
env = "default"
running = helpers.check_sim_running(env)
node = node[0]
else:
# node was not specified, display usage
exit(call([get_command(), "console", "--help"]))

if running:

sim_name = running

resp = server.get_node_console(sim_name, node=node)
if node:
click.secho("Attempting to connect to console " "of {}".format(node))
try:
ip, port = resp.json()[node].split(":")

# use user specified telnet command
if "VIRL_CONSOLE_COMMAND" in server.config:
cmd = server.config["VIRL_CONSOLE_COMMAND"]
cmd = cmd.format(host=ip, port=port)
print("Calling user specified command: {}".format(cmd))
exit(call(cmd.split()))

# someone still uses windows
elif platform.system() == "Windows":
with helpers.disable_file_system_redirection():
exit(call(["telnet", ip, port]))

# why is shit so complicated?
else:
exit(call(["telnet", ip, port]))
except AttributeError:
click.secho("Could not find console info for " "{}:{}".format(env, node), fg="red")
except KeyError:
click.secho("Unknown node {}:{}".format(env, node), fg="red")
else:
# defaults to displaying table
console_table1(resp.json())
31 changes: 0 additions & 31 deletions virl/cli/down/commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import click
from virl.api import VIRLServer
from virl.helpers import (
check_sim_running,
remove_sim_info,
get_cml_client,
safe_join_existing_lab_by_title,
safe_join_existing_lab,
Expand Down Expand Up @@ -44,32 +42,3 @@ def down(id=None, lab_name=None):
else:
click.secho("Failed to find lab on server", fg="red")
exit(1)


@click.command()
@click.argument("env", default="default")
@click.option("--sim-name", required=False)
def down1(sim_name=None, env="default", **kwargs):
"""
stop a virl simulation
"""
# by env name
running = check_sim_running(env)
if running:
sim_name = running
# by sim name
elif sim_name:
sim_name = sim_name
else:
click.secho("Could not find sim for environment {}".format(env))
exit(1)
server = VIRLServer()
resp = server.stop_simulation(sim_name)
remove_sim_info(env=env)
if not resp.ok:
cause = resp.json()["cause"]
result = click.style(cause, fg="red")
else:
result = click.style(resp.text, fg="green")
click.secho("Shutting Down Simulation {}.....".format(sim_name)),
click.echo(result)
19 changes: 3 additions & 16 deletions virl/cli/generate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click
from virl.api import plugin, check_valid_plugin, NoPluginError
from virl.cli.generate.ansible.commands import ansible, ansible1
from virl.cli.generate.pyats.commands import pyats, pyats1
from virl.cli.generate.nso.commands import nso, nso1
from virl.cli.generate.ansible.commands import ansible
from virl.cli.generate.pyats.commands import pyats
from virl.cli.generate.nso.commands import nso


@click.group()
Expand All @@ -13,19 +13,6 @@ def generate():
pass


@click.group()
def generate1():
"""
generate inv file for various tools
"""
pass


generate1.add_command(ansible1, name="ansible")
generate1.add_command(pyats1, name="pyats")
generate1.add_command(nso1, name="nso")


def init_generators():
generate.add_command(ansible)
generate.add_command(pyats)
Expand Down
47 changes: 1 addition & 46 deletions virl/cli/generate/ansible/commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import click
from virl.api import VIRLServer
from virl import helpers
from virl.helpers import get_cml_client, get_current_lab, safe_join_existing_lab
from virl.generators import ansible_inventory_generator1, ansible_inventory_generator
from virl.generators import ansible_inventory_generator


@click.command()
Expand All @@ -19,7 +18,6 @@ def ansible(**kwargs):
if current_lab:
lab = safe_join_existing_lab(current_lab, client)
if lab:

if kwargs.get("output"):
file_name = kwargs.get("output")
elif kwargs.get("style") == "ini":
Expand Down Expand Up @@ -47,46 +45,3 @@ def ansible(**kwargs):
else:
click.secho("Current lab is not set", fg="red")
exit(1)


@click.command()
@click.argument("env", default="default")
@click.option("--output", "-o", help="output File name ")
@click.option("--style", help="output format (default is yaml)", type=click.Choice(["ini", "yaml"]))
def ansible1(env, **kwargs):
"""
generate ansible inventory
"""

if kwargs.get("output"):
# user specified output filename
file_name = kwargs.get("output")
elif kwargs.get("style") == "ini":
file_name = "{}_inventory.ini".format(env)
else:
# writes to <env>_testbed.yaml by default
file_name = "{}_inventory.yaml".format(env)

running = helpers.check_sim_running(env)
if running:
sim_name = running
server = VIRLServer()
roster = server.get_sim_roster(sim_name)
# sim_name = "topology-fpyHFs"
virl_data = server.export(sim_name, ip=True).content
interfaces = server.get_interfaces(sim_name).json()
if kwargs.get("style") == "ini":
inventory_ini = ansible_inventory_generator1(sim_name, virl_data, roster=roster, interfaces=interfaces, style="ini")

click.secho("Writing {}".format(file_name))
with open(file_name, "w") as ini_file:
ini_file.write(inventory_ini)
else:
inventory_yaml = ansible_inventory_generator1(sim_name, virl_data, roster=roster, interfaces=interfaces)

click.secho("Writing {}".format(file_name))
with open(file_name, "w") as yaml_file:
yaml_file.write(inventory_yaml)

else:
click.secho("couldnt generate testbed for for env: {}".format(env), fg="red")
55 changes: 1 addition & 54 deletions virl/cli/generate/nso/commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import click
from virl.api import VIRLServer
from virl.cli.views import sync_table
from virl import helpers
from virl.helpers import get_cml_client, safe_join_existing_lab, get_current_lab
from virl.generators import nso_payload_generator1, nso_payload_generator
from virl.generators import nso_payload_generator
from virl.api.nso import NSO


Expand All @@ -22,7 +21,6 @@ def nso(syncfrom, **kwargs):
if current_lab:
lab = safe_join_existing_lab(current_lab, client)
if lab:

if kwargs.get("output"):
file_name = kwargs.get("output")
else:
Expand Down Expand Up @@ -56,54 +54,3 @@ def nso(syncfrom, **kwargs):
else:
click.secho("Current lab is not set", fg="red")
exit(1)


@click.command()
@click.argument("env", default="default")
@click.option("--output", "-o", help="just dump the payload to file without sending")
@click.option("--syncfrom/--no-syncfrom", default=False, help="Perform sync-from after updating devices")
# @click.option('--syncto/--no-syncto', default=False,
# help="Perform sync-to afgter updating devices")
def nso1(env, syncfrom, **kwargs):
"""
generate nso inventory
"""

if kwargs.get("output"):
# user specified output filename
file_name = kwargs.get("output")
else:
# writes to <env>.json by default
file_name = None

running = helpers.check_sim_running(env)
if running:
sim_name = running
server = VIRLServer()
roster = server.get_sim_roster(sim_name)
# sim_name = "topology-fpyHFs"
virl_data = server.export(sim_name, ip=True).content
interfaces = server.get_interfaces(sim_name).json()

payload = nso_payload_generator1(sim_name, virl_data, roster=roster, interfaces=interfaces)

if file_name: # pragma: no cover
click.secho("Writing payload to {}".format(file_name))
with open(file_name, "w") as payload_file:

payload_file.write(payload)
else:
click.secho("Updating NSO....")
nso_obj = NSO()
nso_response = nso_obj.update_devices(payload)
if nso_response.ok:
click.secho("Successfully added VIRL devices to NSO")
else:
click.secho("Error updating NSO: ", fg="red")
click.secho(nso_response.text)
if syncfrom:
resp = nso_obj.perform_sync_from()
sync_table(resp.json())

else:
click.secho("couldnt generate testbed for for env: {}".format(env), fg="red")
35 changes: 1 addition & 34 deletions virl/cli/generate/pyats/commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import click
from virl.api import VIRLServer
from virl import helpers
from virl.helpers import get_cml_client, get_current_lab, safe_join_existing_lab
from virl.generators import pyats_testbed_generator1, pyats_testbed_generator
from virl.generators import pyats_testbed_generator


@click.command()
Expand Down Expand Up @@ -40,35 +39,3 @@ def pyats(**kwargs):
else:
click.secho("Current lab is not set", fg="red")
exit(1)


@click.command()
@click.argument("env", default="default")
@click.option("--output", "-o", help="output File name ")
def pyats1(env, **kwargs):
"""
Generates a pyats testbed config for an environment
"""
if kwargs.get("output"):
# user specified output filename
file_name = kwargs.get("output")
else:
# writes to <env>_testbed.yaml by default
file_name = "{}_testbed.yaml".format(env)

running = helpers.check_sim_running(env)
if running:
sim_name = running
server = VIRLServer()
roster = server.get_sim_roster(sim_name)
# sim_name = "topology-fpyHFs"
virl_data = server.export(sim_name, ip=True).content
interfaces = server.get_interfaces(sim_name).json()
testbed_yaml = pyats_testbed_generator1(sim_name, virl_data, roster=roster, interfaces=interfaces)

click.secho("Writing {}".format(file_name))
with open(file_name, "w") as yaml_file:
yaml_file.write(testbed_yaml)

else:
click.secho("couldnt generate testbed for for env: {}".format(env), fg="red")
21 changes: 0 additions & 21 deletions virl/cli/id/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import click
from virl.api import VIRLServer, CachedLab
from virl.helpers import get_current_lab, get_cml_client, safe_join_existing_lab, get_current_lab_link
Expand All @@ -25,23 +24,3 @@ def lid():
click.echo("{} (ID: {})".format(lab.title, current_lab))
else:
click.secho("Current lab is set to {}, but is not on server or in cache!".format(current_lab), fg="red")


@click.command()
def sid():
"""
gets sim id for local environment
"""

server = VIRLServer()

sim_dict = server.list_simulations()
dirpath = os.getcwd()
foldername = os.path.basename(dirpath)
for k in list(sim_dict):
if not k.startswith(foldername):
sim_dict.pop(k)
# can only accurately determine sim id if there is
# only one sim running with our project name
if len(sim_dict) == 1:
click.echo(list(sim_dict)[0])
6 changes: 5 additions & 1 deletion virl/cli/license/deregister/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

@click.command()
@click.option(
"--confirm/--no-confirm", show_default=False, default=True, help="Do not prompt for confirmation (default: prompt)", required=False,
"--confirm/--no-confirm",
show_default=False,
default=True,
help="Do not prompt for confirmation (default: prompt)",
required=False,
)
def deregister(confirm):
"""
Expand Down
Loading

0 comments on commit da9c707

Please sign in to comment.