Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.5.0 #75

Merged
merged 7 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: develop action

on: [push]
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
build:
Expand Down
117 changes: 60 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
nmcli
=====
# nmcli

nmcli is a python wrapper library for the network-manager cli client.

Expand Down Expand Up @@ -31,62 +30,61 @@ except Exception as e:

## Dependency

* NetworkManager
* `sudo apt install network-manager` (Debian)
* User who can execute nmcli with sudo with NOPASSWD
* If sudo is not needed (like root user), use `disable_use_sudo` at the beginning of the process.
- NetworkManager
- `sudo apt install network-manager` (Debian)
- User who can execute nmcli with sudo with NOPASSWD
- If sudo is not needed (like root user), use `disable_use_sudo` at the beginning of the process.

## Compatibility table

| Object | Command | Status |
|--------|---------|--------|
| general | | supported |
| general | status | supported |
| general | hostname | supported |
| general | permissions | not supported |
| general | logging | not supported |
| networking | | supported |
| networking | on | supported |
| networking | off | supported |
| networking | connectivity | supported |
| radio | | supported |
| radio | all | supported |
| radio | wifi | supported |
| radio | wwan | supported |
| connection | | supported |
| connection | show | supported |
| connection | up | supported |
| connection | down | supported |
| connection | add | supported |
| connection | modify | supported |
| connection | clone | not supported |
| connection | edit | not supported |
| connection | delete | supported |
| connection | reload | supported |
| connection | load | not supported |
| connection | import | not supported |
| connection | export | not supported |
| device | | supported |
| device | status | supported |
| device | show | supported |
| device | set | not supported |
| device | connect | supported |
| device | reapply | supported |
| device | modify | not supported |
| device | disconnect | supported |
| device | delete | supported |
| device | monitor | not supported |
| device | wifi | supported |
| device | wifi connect | supported |
| device | wifi rescan | supported |
| device | wifi hotspot | supported |
| device | lldp | not supported |
| agent | | not supported |
| agent | secret | not supported |
| agent | polkit | not supported |
| agent | all | not supported |
| monitor | | not supported |

| Object | Command | Status |
| ---------- | ------------ | ------------- |
| general | | supported |
| general | status | supported |
| general | hostname | supported |
| general | permissions | not supported |
| general | logging | not supported |
| networking | | supported |
| networking | on | supported |
| networking | off | supported |
| networking | connectivity | supported |
| radio | | supported |
| radio | all | supported |
| radio | wifi | supported |
| radio | wwan | supported |
| connection | | supported |
| connection | show | supported |
| connection | up | supported |
| connection | down | supported |
| connection | add | supported |
| connection | modify | supported |
| connection | clone | not supported |
| connection | edit | not supported |
| connection | delete | supported |
| connection | reload | supported |
| connection | load | not supported |
| connection | import | not supported |
| connection | export | not supported |
| device | | supported |
| device | status | supported |
| device | show | supported |
| device | set | not supported |
| device | connect | supported |
| device | reapply | supported |
| device | modify | not supported |
| device | disconnect | supported |
| device | delete | supported |
| device | monitor | not supported |
| device | wifi | supported |
| device | wifi connect | supported |
| device | wifi rescan | supported |
| device | wifi hotspot | supported |
| device | lldp | not supported |
| agent | | not supported |
| agent | secret | not supported |
| agent | polkit | not supported |
| agent | all | not supported |
| monitor | | not supported |

## API

Expand Down Expand Up @@ -155,8 +153,10 @@ nmcli.connection.down(name: str, wait: int = None) -> None

Show details for specified connections.

Use `show_secrets` argument to reveal associated secrets as well.

```
nmcli.connection.show(name: str) -> ConnectionDetails
nmcli.connection.show(name: str, show_secrets: bool = False) -> ConnectionDetails
```

#### nmcli.connection.reload
Expand Down Expand Up @@ -239,7 +239,6 @@ Delete the software devices.

The `wait` argument applies the same effect to the command as the `--wait` option. If it is omitted, the default behavior is followed.


```
nmcli.device.delete(ifname: str, wait: int = None) -> None
```
Expand Down Expand Up @@ -459,6 +458,10 @@ nmcli.set_lang(lang: str) -> None

## Change Log

### 1.5.0

- Added show_secrets option to `nmcli.connection.show`

### 1.4.0

- Supported unsupported cases of `DeviceWifi.parse`.
Expand Down
9 changes: 6 additions & 3 deletions nmcli/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def up(self, name: str, wait: int = None) -> None:
def down(self, name: str, wait: int = None) -> None:
raise NotImplementedError

def show(self, name: str) -> ConnectionDetails:
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
raise NotImplementedError

def reload(self) -> None:
Expand Down Expand Up @@ -88,8 +88,11 @@ def down(self, name: str, wait: int = None) -> None:
wait) + ['connection', 'down', name]
self._syscmd.nmcli(cmd)

def show(self, name: str) -> ConnectionDetails:
r = self._syscmd.nmcli(['connection', 'show', name])
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
cmd = ['connection', 'show', name]
if show_secrets:
cmd += ["--show-secrets"]
r = self._syscmd.nmcli(cmd)
results = {}
for row in r.split('\n'):
m = re.search(r'^(\S+):\s*([\S\s]+)\s*', row)
Expand Down
8 changes: 7 additions & 1 deletion nmcli/dummy/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def up_args(self):
def down_args(self):
return self._down_args

@property
def show_args(self):
return self._show_args

@property
def called_reload(self) -> int:
return self._called_reload
Expand All @@ -43,6 +47,7 @@ def __init__(self,
self._delete_args: List[Tuple] = []
self._up_args: List[Tuple] = []
self._down_args: List[Tuple] = []
self._show_args: List[Tuple] = []
self._called_reload = 0

def __call__(self) -> List[Connection]:
Expand Down Expand Up @@ -74,8 +79,9 @@ def down(self, name: str, wait: int = None) -> None:
self._raise_error_if_needed()
self._down_args.append((name, wait))

def show(self, name: str) -> ConnectionDetails:
def show(self, name: str, show_secrets: bool = False) -> ConnectionDetails:
self._raise_error_if_needed()
self._show_args.append((name, show_secrets))
if not self._result_show is None:
return self._result_show
raise ValueError("'result_show' is not properly initialized")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_tests(self):

setup(
name='nmcli',
version='1.4.0',
version='1.5.0',
author='ushiboy',
license='MIT',
license_files = ('LICENSE.txt',),
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ def test_show():
'key': 'value'
}
c = DummyConnectionControl(result_show=result_show)

name = 'MyHome'
assert c.show(name) == result_show
assert c.show_args[0] == (name, False)

c.show(name, show_secrets=True)
assert c.show_args[1] == (name, True)


def test_show_when_raise_error():
Expand Down
9 changes: 8 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,21 @@ def test_show():
buf = f.read()
s = DummySystemCommand(buf)
connection = ConnectionControl(s)
r = connection.show('Wired connection 1')
name = 'Wired connection 1'

r = connection.show(name)
assert s.passed_parameters == ['connection', 'show', name]
assert len(r.keys()) == 114
assert r['connection.id'] == 'Wired connection 1'
assert r['connection.stable-id'] is None
assert r['ipv4.dns-options'] is None
assert r['IP4.ADDRESS[1]'] == '192.168.1.10/24'
assert r['DHCP6.OPTION[8]'] == 'requested_dhcp6_name_servers = 1'

connection.show(name, show_secrets=True)
assert s.passed_parameters == [
'connection', 'show', name, "--show-secrets"]


def test_reload():
s = DummySystemCommand()
Expand Down
Loading