Skip to content

Commit

Permalink
initial, beta release
Browse files Browse the repository at this point in the history
- added GH action
- added iol-l2 "detection"
- added auto version detection and command line option
- added some updated README and CHANGELOG
  • Loading branch information
rschmied committed Mar 12, 2024
1 parent 6f91fb7 commit e2c6236
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 13 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will install Python dependencies, run tests and lint with a
# variety of Python versions
#
# In addition, code coverage is reported to Coveralls
#
# For more information see:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi
- name: Check code
run: |
make check
- name: Test with pytest
run: |
coverage run -m pytest
coverage lcov
- name: Code Coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CHANGELOG

- v0.1.0b0 initial release

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Ralph Schmieder
Copyright (c) 2024 Cisco, Inc. and Ralph Schmieder

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
# eve2cml

![](./assets/header.png)

Convert EVE-NG topology files either in ZIP format or in plain-text XML (.unl) to CML2 YAML format.

> [!CAUTION]
>
> This is considered "beta" as in "it works for me but might have bugs or things don't work as you expect them to do." So, use with care and at your own risk.
### Mapping node types

There's some default node type mappings which can be dumped into a file using the `--dump` flag.

The mapper uses three lists:
The mapper defines three elements:

- `interface_lists`: A map with a list of interface names for each mapped CML node definitions. The key is the CML node definition ID

- `unknown_type`: Which node definition ID should be inserted into the topology if the EVE node type is not defined in the mapper (a string like "desktop")

- `interface_lists`: A map with a list of interface names for each mapped CML node definitions. The key is the CML node definition ID.
- `unknown_type`: Which node definition ID should be inserted into the topology if the EVE node type is not defined in the mapper
- `map`: Maps EVE node types into CML node and image definitions. The map key is an EVE node type where the format is "eve-node-type:eve-node-template:eve-node-image" (separated by colons). An example is `qemu:linux`. When the image part is missing then the CML default image for the mapped node type is used. The value for each key is of the form:
- `image_def`: the CML image definition ID for this node definition ID (can safely be null/undefined).
- `node_def`: the mapped CML node definition ID.
- `override`: a boolean. It determines whether values like CPU or memory should be taken from the EVE definition. If `true` then the EVE values will not be used, the default values from CML for this particular node type will then be used instead.

- `image_def`: the CML image definition ID for this node definition ID (can safely be null/undefined)
- `node_def`: the mapped CML node definition ID
- `override`: a boolean. It determines whether values like CPU or memory should be taken from the EVE definition. If `true` then the EVE values will not be used, the default values from CML for this particular node type will then be used instead

There's a specific "corner case" where the type is identical to the template (e.g. "iol:iol" or "docker:docker"). In this particular case, mapper keys are searched for partial matches where the map key matches the beginning of the provided EVE image. For example, "iol:iol:i86bi_linux_l2-ipbasek9:" matches all IOL images that start with `i86bi_linux-ipbasek9` and maps the (by default) into `ioll2-xe`.

After modification / adding more or different node type mappings to the exported map YAML, use the file via the `--mapper modified_map.yaml` flag.

Expand Down Expand Up @@ -45,4 +56,3 @@ Example: eve2cml exportedlabs.zip
$
```

5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# TODOs

### Configuration sets

- need to provide a command line flag to specify which config set, if present, should be included in the resulting CML YAML file
- alternatively, if config sets are present, write multiple files, one for each config set

They need to be mapped to bridgeN using ext conns. Insert an intermediate UMS if the number of connected ports is greater than 1.

## Annotations
- add "dashed" property for squares and circles
- add transparency conversion

## Done

### Handle pnet0, pnet1, ...
Expand Down
Binary file added assets/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "eve2cml"
version = "0.1.0"
dynamic = [ "version" ]
description = "A CLI tool to convert EVE-NG XML topology data into CML2 topology data as YAML"
authors = [
{name = "Ralph Schmieder", email = "[email protected]"},
Expand All @@ -24,6 +24,11 @@ build-backend = "pdm.backend"
[tool.pdm]
distribution = true

[tool.pdm.version]
source = "scm"
write_to = "eve2cml/_version.py"
write_template = "__version__ = '{}'"

[tool.pdm.dev-dependencies]
dev = [
"mypy>=1.8.0",
Expand Down
1 change: 1 addition & 0 deletions src/eve2cml/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0b0"
2 changes: 1 addition & 1 deletion src/eve2cml/eve/lab.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from typing import Any, Dict, List, Tuple

from ..mapper import Eve2CMLmapper
from .interface import Interface
from eve2cml.mapper import Eve2CMLmapper
from .network import Network
from .node import Node
from .objects import Objects
Expand Down
7 changes: 6 additions & 1 deletion src/eve2cml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

import yaml

from .mapper import Eve2CMLmapper
from ._version import __version__
from .eve import Lab, Network, Node, Objects, Topology
from .log import initialize_logging
from .mapper import Eve2CMLmapper

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -134,6 +135,10 @@ def main():
description="Convert UNL/XML topologies to CML2 topologies"
)
parser.epilog = f"Example: {parser.prog} exportedlabs.zip"
parser.add_argument(
"-V", "--version", action="version", version=f"%(prog)s {__version__}"
)

parser.add_argument(
"--level",
default="warning",
Expand Down
21 changes: 21 additions & 0 deletions src/eve2cml/map_data/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ interface_lists:
- Ethernet3/1
- Ethernet3/2
- Ethernet3/3
ioll2-xe:
- Ethernet0/0
- Ethernet0/1
- Ethernet0/2
- Ethernet0/3
- Ethernet1/0
- Ethernet1/1
- Ethernet1/2
- Ethernet1/3
- Ethernet2/0
- Ethernet2/1
- Ethernet2/2
- Ethernet2/3
- Ethernet3/0
- Ethernet3/1
- Ethernet3/2
- Ethernet3/3
iosv:
- GigabitEthernet0/0
- GigabitEthernet0/1
Expand Down Expand Up @@ -254,6 +271,10 @@ map:
image_def: null
node_def: desktop
override: true
iol:iol:i86bi_linux_l2-ipbasek9:
image_def: null
node_def: ioll2-xe
override: false
iol:iol:
image_def: null
node_def: iol-xe
Expand Down
11 changes: 9 additions & 2 deletions src/eve2cml/mapper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import yaml
import logging
import sys
from importlib import resources
from pathlib import Path
from typing import Dict, List, Optional

import yaml

from . import map_data as md

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -72,8 +73,14 @@ def load(cls, filename="") -> "Eve2CMLmapper":
return mapper

def node_def(self, obj_type: str, template: str, image: str) -> CMLdef:
found = self.map.get(f"{obj_type}:{template}:{image}")
lookup = f"{obj_type}:{template}:{image}"
found = self.map.get(lookup)
if not found:
# special case for non-template images like IOL or Docker
if image and template == obj_type:
for key, cmldef in self.map.items():
if lookup.startswith(key):
return cmldef
found = self.map.get(f"{obj_type}:{template}")
if not found:
_LOGGER.warning(
Expand Down

0 comments on commit e2c6236

Please sign in to comment.