Skip to content

Commit

Permalink
Add support for live EVE to CML conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jclarke-csco committed Oct 21, 2024
1 parent e9f87f4 commit caef53f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = cmlutils,venv*,.git,.eggs,__pycache__,docs/source/conf.py,old,build,dist
ignore = E731
max-complexity = 20
max-complexity = 25
max-line-length = 140
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ Technical Support: http://www.cisco.com/techsupport
```
#### EVE-NG Lab Support
The `cml up` command can convert EVE-NG labs to CML labs on the fly (".unl" to ".yaml" conversion) if you install the
[eve2cml](https://pypi.org/project/eve2cml/) Python library. With that library installed, a command such as
`cml up -f my-lab.unl` will convert `my-lab.unl` to `my-lab.yaml` in the same directory and import it into CML.
#### Ansible Inventory Generation
quickly turn your simulations into an inventory file that can be used to run your playbooks
Expand Down Expand Up @@ -686,7 +692,6 @@ User bob successfully updated
Check the cli help for more options.
To delete one or multiple users.
``` sh
Expand All @@ -707,7 +712,6 @@ User bob successfully deleted
╘════════════╧═════════════════╧═════════════╧═════════╧════════════╧════════════════════════╛
```
#### Groups
To manage groups you can use the `cml groups` command
Expand Down
2 changes: 1 addition & 1 deletion virl/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.1"
__version__ = "2.3.0"
28 changes: 24 additions & 4 deletions virl/cli/up/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
import click

from virl.api import CachedLab, VIRLServer
from virl.helpers import (cache_lab, check_lab_cache, clear_current_lab,
get_cml_client, get_command, get_current_lab,
safe_join_existing_lab,
safe_join_existing_lab_by_title, set_current_lab)
from virl.helpers import (
cache_lab,
check_lab_cache,
clear_current_lab,
get_cml_client,
get_command,
get_current_lab,
safe_join_existing_lab,
safe_join_existing_lab_by_title,
set_current_lab,
)


def get_lab_title(fname):
Expand Down Expand Up @@ -127,6 +134,19 @@ def up(repo=None, provision=False, start=True, **kwargs):
lab = safe_join_existing_lab_by_title(lab_name, client)

if not lab and os.path.isfile(fname):
(lfname, lfext) = os.path.splitext(fname)
if lfext.lower() == ".unl":
# This is an EVE-NG lab. Convert it if we can.
rc = call(["eve2cml", fname])
if rc != 0:
click.secho(
"ERROR: Failed to convert {} from EVE-NG to CML. Is https://pypi.org/project/eve2cml/ installed?".format(fname),
fg="red",
)
exit(rc)

fname = "{}.yaml".format(lfname)

lname = get_lab_title(fname)
click.secho("Importing lab {} from file {}".format(lname, fname))
lab = client.import_lab_from_path(fname, title=lname)
Expand Down

0 comments on commit caef53f

Please sign in to comment.