• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CiscoDevNet / virlutils / 8258184534

24 Feb 2024 03:37PM UTC coverage: 73.942%. Remained the same
8258184534

push

github

jclarke-csco
Pet markdown lint.

1694 of 2291 relevant lines covered (73.94%)

3.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.28
/virl/cli/command/commands.py
1
import click
5✔
2
import os
5✔
3
from virl.api import VIRLServer
5✔
4
from virl.helpers import get_cml_client, get_current_lab, safe_join_existing_lab
5✔
5
from virl2_client.models.cl_pyats import ClPyats, PyatsNotInstalled, PyatsDeviceNotFound
5✔
6

7

8
@click.command()
5✔
9
@click.argument("node", nargs=1)
5✔
10
@click.argument("command", nargs=1)
5✔
11
@click.option("--config/--no-config", default=False, show_default=False, help="Command is a configuration command (default: False)")
5✔
12
def command(node, command, config, **kwargs):
5✔
13
    """
14
    send a command or config to a node (requires pyATS)
15
    """
16
    server = VIRLServer()
×
17
    client = get_cml_client(server)
×
18

19
    current_lab = get_current_lab()
×
20
    if current_lab:
×
21
        lab = safe_join_existing_lab(current_lab, client)
×
22
        if lab:
×
23
            pylab = None
×
24
            try:
×
25
                pylab = ClPyats(lab)
×
26
            except PyatsNotInstalled:
×
27
                click.secho("pyATS is not installed, run 'pip install pyats'", fg="red")
×
28
                exit(1)
×
29

30
            pyats_username = server.config.get("CML_DEVICE_USERNAME")
×
31
            pyats_password = server.config.get("CML_DEVICE_PASSWORD")
×
32
            pyats_auth_password = server.config.get("CML_DEVICE_ENABLE_PASSWORD")
×
33

34
            if pyats_username:
×
35
                os.environ["PYATS_USERNAME"] = pyats_username
×
36
            if pyats_password:
×
37
                os.environ["PYATS_PASSWORD"] = pyats_password
×
38
            if pyats_auth_password:
×
39
                os.environ["PYATS_AUTH_PASS"] = pyats_auth_password
×
40

41
            pylab.sync_testbed(server.user, server.passwd)
×
42

43
            try:
×
44
                result = ""
×
45
                if config:
×
46
                    result = pylab.run_config_command(node, command)
×
47
                else:
48
                    result = pylab.run_command(node, command)
×
49

50
                click.secho(result)
×
51
            except PyatsDeviceNotFound:
×
52
                click.secho("Node '{}' is not supported by pyATS".format(node), fg="yellow")
×
53
            except Exception as e:
×
54
                click.secho("Failed to run '{}' on '{}': {}".format(command, node, e))
×
55
                exit(1)
×
56
        else:
57
            click.secho("Unable to find lab {}".format(current_lab), fg="red")
×
58
            exit(1)
×
59
    else:
60
        click.secho("No current lab set", fg="red")
×
61
        exit(1)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc