Skip to content

Commit

Permalink
CLI: Refactoring to avoid namespace clash with public bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
slyon committed Aug 1, 2023
1 parent c188d56 commit e65fbfb
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -8,5 +8,5 @@ __pycache__
.coverage
.vscode
src/_features.h
netplan/_features.py
netplan_cli/_features.py
dbus/io.netplan.Netplan.service
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -3,7 +3,7 @@
DESTDIR ?= ../tmproot

default: _build
meson compile -C _build
meson compile -C _build --verbose

_build:
meson setup _build --prefix=/usr
Expand All @@ -12,7 +12,7 @@ _build-cov:
meson setup _build-cov --prefix=/usr -Db_coverage=true

clean:
rm -f netplan/_features.py src/_features.h src/_features.h.gch
rm -f netplan_cli/_features.py src/_features.h src/_features.h.gch
rm -f generate doc/*.html doc/*.[1-9]
rm -f *.o *.so*
rm -f netplan-dbus dbus/*.service
Expand All @@ -35,7 +35,7 @@ linting: _build
meson test -C _build --verbose codestyle

pre-coverage: _build-cov
meson compile -C _build-cov
meson compile -C _build-cov --verbose

check-coverage: pre-coverage
meson test -C _build-cov
Expand Down
2 changes: 1 addition & 1 deletion features_py_generator.sh
@@ -1,6 +1,6 @@
#!/bin/sh
BASE=$(dirname $0)
OUTPUT=$BASE/netplan/_features.py
OUTPUT=$BASE/netplan_cli/_features.py
INPUT=$BASE/src/[!_]*.[hc]
echo "# Generated file" > $OUTPUT
echo "NETPLAN_FEATURE_FLAGS = [" >> $OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Expand Up @@ -39,7 +39,7 @@ inc = include_directories('include')
subdir('include')
subdir('src')
subdir('dbus')
subdir('netplan')
subdir('netplan_cli')
subdir('examples')
subdir('doc')

Expand Down
2 changes: 1 addition & 1 deletion netplan/__init__.py → netplan_cli/__init__.py
Expand Up @@ -15,6 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from netplan.cli.core import Netplan
from .cli.core import Netplan

__all__ = [Netplan]
File renamed without changes.
Expand Up @@ -15,16 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from netplan.cli.commands.apply import NetplanApply
from netplan.cli.commands.generate import NetplanGenerate
from netplan.cli.commands.ip import NetplanIp
from netplan.cli.commands.migrate import NetplanMigrate
from netplan.cli.commands.try_command import NetplanTry
from netplan.cli.commands.info import NetplanInfo
from netplan.cli.commands.set import NetplanSet
from netplan.cli.commands.get import NetplanGet
from netplan.cli.commands.sriov_rebind import NetplanSriovRebind
from netplan.cli.commands.status import NetplanStatus
from .apply import NetplanApply
from .generate import NetplanGenerate
from .ip import NetplanIp
from .migrate import NetplanMigrate
from .try_command import NetplanTry
from .info import NetplanInfo
from .set import NetplanSet
from .get import NetplanGet
from .sriov_rebind import NetplanSriovRebind
from .status import NetplanStatus

__all__ = [
'NetplanApply',
Expand Down
Expand Up @@ -28,10 +28,10 @@
import netifaces
import time

import netplan.cli.utils as utils
from netplan.configmanager import ConfigManager, ConfigurationError
from netplan.cli.sriov import apply_sriov_config
from netplan.cli.ovs import OvsDbServerNotRunning, apply_ovs_cleanup
from .. import utils
from ...configmanager import ConfigManager, ConfigurationError
from ..sriov import apply_sriov_config
from ..ovs import OvsDbServerNotRunning, apply_ovs_cleanup


OVS_CLEANUP_SERVICE = 'netplan-ovs-cleanup.service'
Expand Down
Expand Up @@ -23,7 +23,7 @@
import subprocess
import shutil

import netplan.cli.utils as utils
from .. import utils


class NetplanGenerate(utils.NetplanCommand):
Expand Down
@@ -1,7 +1,7 @@
#!/usr/bin/python3
#
# Copyright (C) 2020 Canonical, Ltd.
# Author: Lukas Märdian <lukas.maerdian@canonical.com>
# Copyright (C) 2020-2023 Canonical, Ltd.
# Author: Lukas Märdian <slyon@ubuntu.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -17,8 +17,8 @@

'''netplan get command line'''

from netplan.cli.state import NetplanConfigState
import netplan.cli.utils as utils
from ..state import NetplanConfigState
from .. import utils


class NetplanGet(utils.NetplanCommand):
Expand Down
Expand Up @@ -17,8 +17,8 @@

'''netplan info command line'''

import netplan.cli.utils as utils
import netplan._features
from .. import utils
from ... import _features


class NetplanInfo(utils.NetplanCommand):
Expand Down Expand Up @@ -49,7 +49,7 @@ def command_info(self):
}
}

flags = netplan._features.NETPLAN_FEATURE_FLAGS
flags = _features.NETPLAN_FEATURE_FLAGS
netplan_version['netplan.io'].update({'features': flags})

# Default to output in YAML format.
Expand All @@ -64,5 +64,5 @@ def command_info(self):
print('''netplan.io:
website: "{}"
features:'''.format(netplan_version['netplan.io']['website']))
for feature in netplan._features.NETPLAN_FEATURE_FLAGS:
for feature in _features.NETPLAN_FEATURE_FLAGS:
print(' - ' + feature)
Expand Up @@ -23,7 +23,7 @@
import subprocess
from subprocess import CalledProcessError

import netplan.cli.utils as utils
from .. import utils

lease_path = {
'networkd': {
Expand Down
Expand Up @@ -30,7 +30,7 @@
from collections import OrderedDict
import ipaddress

import netplan.cli.utils as utils
from .. import utils


class NetplanMigrate(utils.NetplanCommand):
Expand Down
Expand Up @@ -21,8 +21,8 @@
import re
import io

from netplan.cli.utils import NetplanCommand
import netplan.libnetplan as libnetplan
from ..utils import NetplanCommand
from ... import libnetplan

FALLBACK_FILENAME = '70-netplan-set.yaml'
GLOBAL_KEYS = ['renderer', 'version']
Expand Down
Expand Up @@ -19,8 +19,8 @@

import logging

import netplan.cli.utils as utils
from netplan.cli.sriov import PCIDevice, bind_vfs, _get_pci_slot_name
from .. import utils
from ..sriov import PCIDevice, bind_vfs, _get_pci_slot_name


class NetplanSriovRebind(utils.NetplanCommand):
Expand Down
Expand Up @@ -24,8 +24,8 @@
from rich.highlighter import RegexHighlighter
from rich.theme import Theme

import netplan.cli.utils as utils
from netplan.cli.state import SystemConfigState, JSON
from .. import utils
from ..state import SystemConfigState, JSON


class NetplanHighlighter(RegexHighlighter):
Expand Down
Expand Up @@ -25,11 +25,11 @@
import sys
import tempfile

from netplan.configmanager import ConfigManager
import netplan.cli.utils as utils
from netplan.cli.commands.apply import NetplanApply
import netplan.terminal
import netplan.libnetplan as libnetplan
from ...configmanager import ConfigManager
from .. import utils
from .apply import NetplanApply
from ... import terminal
from ... import libnetplan

# Keep a timeout long enough to allow the network to converge, 60 seconds may
# be slightly short given some complex configs, i.e. if STP must reconverge.
Expand Down Expand Up @@ -88,7 +88,7 @@ def command_try(self): # pragma: nocover (requires user input)

try:
fd = sys.stdin.fileno()
self.t = netplan.terminal.Terminal(fd)
self.t = terminal.Terminal(fd)
self.t.save(self.t_settings)

# we really don't want to be interrupted while doing backup/revert operations
Expand All @@ -104,10 +104,10 @@ def command_try(self): # pragma: nocover (requires user input)
# ready to accept any Accept/Reject input (like SIGUSR1 or SIGTERM)
self.touch_ready_stamp()
self.t.get_confirmation_input(timeout=self.timeout)
except netplan.terminal.InputRejected:
except terminal.InputRejected:
print("\nReverting.")
self.revert()
except netplan.terminal.InputAccepted:
except terminal.InputAccepted:
print("\nConfiguration accepted.")
except Exception as e:
print("\nAn error occurred: %s" % e)
Expand Down Expand Up @@ -196,7 +196,7 @@ def is_revertable(self):

def _signal_handler(self, sig, frame): # pragma: nocover (requires user input)
if sig == signal.SIGUSR1:
raise netplan.terminal.InputAccepted()
raise terminal.InputAccepted()
else:
if self.configuration_changed:
raise netplan.terminal.InputRejected()
raise terminal.InputRejected()
8 changes: 4 additions & 4 deletions netplan/cli/core.py → netplan_cli/cli/core.py
Expand Up @@ -21,8 +21,8 @@
import logging
import os

import netplan.cli.utils as utils
from netplan.libnetplan import NetplanException, NetplanValidationException, NetplanParserException
from . import utils
from ..libnetplan import NetplanException, NetplanValidationException, NetplanParserException


FALLBACK_PATH = '/usr/bin:/snap/bin'
Expand All @@ -39,9 +39,9 @@ def __init__(self):
'PATH': os.getenv('PATH', FALLBACK_PATH)})

def parse_args(self):
import netplan.cli.commands
from . import commands as cli_commands

self._import_subcommands(netplan.cli.commands)
self._import_subcommands(cli_commands)

super().parse_args()

Expand Down
2 changes: 1 addition & 1 deletion netplan/cli/ovs.py → netplan_cli/cli/ovs.py
Expand Up @@ -20,7 +20,7 @@
import subprocess
import re

from netplan.cli.utils import systemctl_is_active
from .utils import systemctl_is_active

OPENVSWITCH_OVS_VSCTL = '/usr/bin/ovs-vsctl'
OPENVSWITCH_OVSDB_SERVER_UNIT = 'ovsdb-server.service'
Expand Down
6 changes: 3 additions & 3 deletions netplan/cli/sriov.py → netplan_cli/cli/sriov.py
Expand Up @@ -23,9 +23,9 @@

from collections import defaultdict

import netplan.cli.utils as utils
import netplan.libnetplan as libnetplan
from netplan.configmanager import ConfigurationError
from . import utils
from .. import libnetplan
from ..configmanager import ConfigurationError

import netifaces

Expand Down
4 changes: 2 additions & 2 deletions netplan/cli/state.py → netplan_cli/cli/state.py
Expand Up @@ -31,8 +31,8 @@

import dbus

import netplan.cli.utils as utils
import netplan.libnetplan as libnetplan
from . import utils
from .. import libnetplan

JSON = Union[Dict[str, 'JSON'], List['JSON'], int, str, float, bool, Type[None]]

Expand Down
6 changes: 3 additions & 3 deletions netplan/cli/utils.py → netplan_cli/cli/utils.py
Expand Up @@ -24,9 +24,9 @@
import fnmatch
import re

import netplan.libnetplan as np
from netplan.configmanager import ConfigurationError
from netplan.libnetplan import NetplanException
from .. import libnetplan as np
from ..configmanager import ConfigurationError
from ..libnetplan import NetplanException


NM_SERVICE_NAME = 'NetworkManager.service'
Expand Down
2 changes: 1 addition & 1 deletion netplan/configmanager.py → netplan_cli/configmanager.py
Expand Up @@ -25,7 +25,7 @@

from typing import Optional

from netplan import libnetplan
from . import libnetplan


class ConfigManager(object):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion netplan/meson.build → netplan_cli/meson.build
Expand Up @@ -4,7 +4,7 @@ install_symlink(
pointing_to: '../share/netplan/netplan.script',
install_dir: get_option('sbindir'))

netplan_module = join_paths(get_option('datadir'), meson.project_name(), 'netplan')
netplan_module = join_paths(get_option('datadir'), meson.project_name(), 'netplan_cli')
features_py = custom_target(
build_always_stale: true,
output: '_features.py',
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/netplan.script
Expand Up @@ -17,7 +17,7 @@

'''netplan command line'''

from netplan import Netplan
from netplan_cli import Netplan

netplan = Netplan()
netplan.main()
2 changes: 1 addition & 1 deletion tools/keyfile_to_yaml.py
Expand Up @@ -6,7 +6,7 @@
import io
import sys

from netplan import libnetplan
from netplan_cli import libnetplan

if len(sys.argv) < 2:
print("Pass the NM keyfile as parameter")
Expand Down

0 comments on commit e65fbfb

Please sign in to comment.