Skip to content

Commit

Permalink
Jls dev feb28 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyschulman authored Feb 28, 2023
1 parent 137b1f0 commit f8b8f59
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 15 deletions.
4 changes: 2 additions & 2 deletions netcam/cli/config/cli_config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from netcad.cli.common_opts import opt_devices, opt_designs, opt_configs_dir

from netcam.cli.netcam_filter_devices import netcam_filter_devices
from .config_main import clig_config
from .task_backup_config import backup_device_config
from netcam.config import backup_device_config
from .cli_config_main import clig_config

# -----------------------------------------------------------------------------
# Exports (None)
Expand Down
24 changes: 20 additions & 4 deletions netcam/cli/config/cli_config_check.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
# Copyright (c) 2021 Jeremy Schulman
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

# -----------------------------------------------------------------------------
# System Imports
# -----------------------------------------------------------------------------

import os
from typing import Tuple
from pathlib import Path
import asyncio

# -----------------------------------------------------------------------------
# Private Imports
# -----------------------------------------------------------------------------

from netcad.config import netcad_globals
from netcad.logger import get_logger
from netcad.device import Device, DeviceNonExclusive
from netcam.dcfg import AsyncDeviceConfigurable
from netcad.cli.device_inventory import get_devices_from_designs
from netcad.cli.common_opts import opt_devices, opt_designs, opt_configs_dir
from netcam.dcfg import AsyncDeviceConfigurable
from netcam.config import check_device_config
from netcam.cli.netcam_filter_devices import netcam_filter_devices

from .config_main import clig_config
from .task_config_check import check_device_config
from .cli_config_main import clig_config

# -----------------------------------------------------------------------------
#
# CODE BEGINS
#
# -----------------------------------------------------------------------------


@clig_config.command("check")
Expand Down Expand Up @@ -70,13 +84,15 @@ async def run_check_configs(device_objs: list[Device], configs_dir: Path):
dev_cfg.config_file = (
configs_dir / dev_obj.design.name / (dev_obj.name + ".cfg")
)
dev_cfg.config_id = f"{dev_cfg.device.name}-{os.getpid()}-check"

# TODO: for now, we are usin the fact that the device in the design is
# either exclusive or non-exclusive to determine whether or not
# to check the config with replacing or merging the built config.

dev_cfg.replace = not isinstance(dev_obj, DeviceNonExclusive)
dev_cfg.config_id = (
f"netcam-{'replace' if dev_cfg.replace else 'merge'}-{os.getpid()}"
)
tasks.append(asyncio.create_task(check_device_config(dev_cfg)))

# TODO: need to check for excpeitons
Expand Down
File renamed without changes.
26 changes: 23 additions & 3 deletions netcam/cli/config/cli_config_push.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Copyright (c) 2021 Jeremy Schulman
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

# -----------------------------------------------------------------------------
# System Imports
# -----------------------------------------------------------------------------

import os
from typing import Tuple
from pathlib import Path
import asyncio

# -----------------------------------------------------------------------------
# Public Imports
# -----------------------------------------------------------------------------

import click

# -----------------------------------------------------------------------------
# Private Imports
# -----------------------------------------------------------------------------

from netcad.config import netcad_globals
from netcad.logger import get_logger
from netcad.device import Device, DeviceNonExclusive
Expand All @@ -16,8 +28,14 @@
from netcad.cli.common_opts import opt_devices, opt_designs, opt_configs_dir
from netcam.cli.netcam_filter_devices import netcam_filter_devices

from .config_main import clig_config
from .task_config_push import push_device_config
from .cli_config_main import clig_config
from netcam.config import push_device_config

# -----------------------------------------------------------------------------
#
# CODE BEGINS
#
# -----------------------------------------------------------------------------


@clig_config.command("push")
Expand Down Expand Up @@ -77,13 +95,15 @@ async def run_deploy_configs(
dev_cfg.config_file = (
configs_dir / dev_obj.design.name / (dev_obj.name + ".cfg")
)
dev_cfg.config_id = f"{dev_cfg.device.name}-{os.getpid()}"

# TODO: for now, we are usin the fact that the device in the design is
# either exclusive or non-exclusive to determine whether or not
# to check the config with replacing or merging the built config.

dev_cfg.replace = not isinstance(dev_obj, DeviceNonExclusive)
dev_cfg.config_id = (
f"netcam-{'replace' if dev_cfg.replace else 'merge'}-{os.getpid()}"
)

# TODO: need to check for exceptions
await push_device_config(dev_cfg, rollback_timeout=rollback_timeout)
3 changes: 3 additions & 0 deletions netcam/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .task_backup_config import backup_device_config
from .task_config_check import check_device_config
from .task_config_push import push_device_config
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from netcad.logger import get_logger
from netcam.dcfg import AsyncDeviceConfigurable
from .deco_temp_file import temp_file
from netcam.config.deco_temp_file import temp_file

_OK_ = "[green]OK:[/green]"
_CHANGED_ = "[blue]CHANGED:[/blue]"
Expand All @@ -24,8 +24,10 @@ async def check_device_config(dev_cfg: AsyncDeviceConfigurable):
# Run the config check based on the capabiltiies of the device driver
# -------------------------------------------------------------------------

config_mode = "replace" if dev_cfg.replace else "merge"

if dev_cfg.Capabilities.check in dev_cfg.capabilities:
log.info(f"{name}: config-check ...")
log.info(f"{name}: config-check {config_mode} ...")

if errors := await dev_cfg.config_check():
log.warning(f"{name}: {_FAIL_} config-check failed: {errors}")
Expand All @@ -35,7 +37,7 @@ async def check_device_config(dev_cfg: AsyncDeviceConfigurable):
config_diff = dev_cfg.config_diff_contents

elif dev_cfg.Capabilities.diff in dev_cfg.capabilities:
log.info(f"{name}: config-diff ...")
log.info(f"{name}: config-diff {config_mode} ...")
config_diff = await dev_cfg.config_diff()

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from netcam.dcfg import AsyncDeviceConfigurable


from .deco_temp_file import temp_file
from netcam.config.deco_temp_file import temp_file

_OK_ = "[green]OK:[/green]"
_CHANGED_ = "[blue]CHANGED:[/blue]"
Expand All @@ -18,7 +18,9 @@
async def push_device_config(dev_cfg: AsyncDeviceConfigurable, rollback_timeout: int):
name = dev_cfg.device.name
log = get_logger()
log.info(f"{name}: deploying config ...")
config_mode = "replace" if dev_cfg.replace else "merge"

log.info(f"{name}: deploying config {config_mode} ...")

try:
await dev_cfg.config_push(rollback_timeout=rollback_timeout)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "netcad"
version = "0.5.0"
version = "0.6.0"
description = "NetCAD/CAM - Network Automation by Design"
authors = ["Jeremy Schulman"]
readme = "README.md"
Expand Down

0 comments on commit f8b8f59

Please sign in to comment.