-
Notifications
You must be signed in to change notification settings - Fork 183
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
feat: Add datasource and parser for nmcli_conn_show_uuid #4273
Changes from 3 commits
d43de4d
c96124e
5e89c42
c470eb1
441c816
0fe9c0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
from insights.core import CommandParser | ||
from insights.core.exceptions import SkipComponent | ||
from insights.core.filters import add_filter | ||
from insights.core.plugins import parser | ||
from insights.parsers import get_active_lines, parse_fixed_table | ||
from insights.specs import Specs | ||
|
@@ -191,3 +192,39 @@ def parse_content(self, content): | |
def disconnected_connection(self): | ||
"""(list): It will return all the disconnected static route connections.""" | ||
return self._disconnected_connection | ||
|
||
|
||
add_filter(Specs.nmcli_conn_show_uuids, ["connection.uuid", "connection.id"]) | ||
|
||
|
||
@parser(Specs.nmcli_conn_show_uuids) | ||
class NmcliConnShowUuids(CommandParser, dict): | ||
""" | ||
This file will parse the output of nmcli connection detail information. | ||
|
||
Sample configuration from an interface in file ``/usr/bin/nmcli conn show XXX``:: | ||
|
||
connection.id: System eth0 | ||
connection.uuid: 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid any miss-understanding, please explicitly obfuscate this uuid, e.g. 5fb06bd0-0bb0-7ffb-45f1-ffffffffffff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiangce - updated |
||
connection.stable-id: -- | ||
connection.type: 802-3-ethernet | ||
connection.interface-name: eth0 | ||
connection.autoconnect: yes | ||
|
||
Examples: | ||
>>> type(conn_show_uuids) | ||
<class 'insights.parsers.nmcli.NmcliConnShowUuids'> | ||
>>> conn_show_uuids["connection.uuid"] | ||
'5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03' | ||
|
||
Attributes: | ||
data (dict): parameter-value format | ||
|
||
""" | ||
def parse_content(self, content): | ||
if not content: | ||
raise SkipComponent() | ||
JoySnow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for line in get_active_lines(content): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This spec is based on a command, which won't output any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiangce - removed |
||
key, val = line.split(": ") | ||
self[key.strip()] = val.strip() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Custom datasources for ``nmcli`` command | ||
""" | ||
from insights.core.plugins import datasource | ||
from insights.parsers.nmcli import NmcliConnShow | ||
|
||
|
||
@datasource(NmcliConnShow) | ||
def nmcli_conn_show_uuids(broker): | ||
""" Return a list of connection uuids """ | ||
nmcli_conn_show = broker[NmcliConnShow] | ||
JoySnow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return [item["UUID"] for item in nmcli_conn_show.data] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from insights.parsers.nmcli import NmcliConnShow | ||
from insights.specs.datasources.nmcli import nmcli_conn_show_uuids | ||
from insights.tests import context_wrap | ||
|
||
|
||
NMCLI_CONN_SHOW = ''' | ||
NAME UUID TYPE DEVICE | ||
Wired connection 2 5fb06bd0-b09a-4573-b393-b54e832ddce9 ethernet enp0s20f0u5c2 | ||
lo 10f69a0f-0bb0-409f-831f-b5b729ba81af loopback lo | ||
Wired connection 1 9dc5d4c5-71ae-44fb-804a-d6edd65f3e03 ethernet -- | ||
enp0s29f2 bb30e099-8220-3eba-45f1-47fb09a4ec80 ethernet -- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above, please obfuscate these uuids by hand explicitly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiangce - updated |
||
'''.strip() | ||
|
||
|
||
def test_nmcli_conn_show_uuids(): | ||
nmcli_conn_show = NmcliConnShow(context_wrap(NMCLI_CONN_SHOW)) | ||
broker = {NmcliConnShow: nmcli_conn_show} | ||
result = nmcli_conn_show_uuids(broker) | ||
assert result == ['5fb06bd0-b09a-4573-b393-b54e832ddce9', '10f69a0f-0bb0-409f-831f-b5b729ba81af', '9dc5d4c5-71ae-44fb-804a-d6edd65f3e03', 'bb30e099-8220-3eba-45f1-47fb09a4ec80'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required to add in the parser? If so, the spec will be 100% collected. It would be good to add them in the rules, so, when such rules were retire, we do not need to collect this spec in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiangce - removed filter