networkctl: add verb edit and cat to operate on network configs

This adds two verbs, edit and cat, to networkctl for
operating on network configs (namely .network, .netdev
and .link files). Specially, if the config name is
prefixed by @, it will be treated as network interface
name, and operations will be performed on config files
associated with the link.

Closes #26906
This commit is contained in:
Mike Yuan
2023-04-01 19:44:29 +08:00
parent 35c0e3444d
commit 96bab8fd63
2 changed files with 560 additions and 1 deletions

View File

@@ -355,6 +355,38 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
which match the file are reconfigured.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>edit</command>
<replaceable>FILE</replaceable>|<replaceable>@DEVICE</replaceable>
</term>
<listitem><para>Edit network configuration files, which include <filename>.network</filename>,
<filename>.netdev</filename>, and <filename>.link</filename> files. If no network config file
matching the given name is found, a new one will be created under <filename>/etc/</filename>.
Specially, if the name is prefixed by <literal>@</literal>, it will be treated as
a network interface, and editing will be performed on the network config files associated
with it. Additionally, the interface name can be suffixed with <literal>:network</literal> (default)
or <literal>:link</literal>, in order to choose the type of network config to operate on.</para>
<para>If <option>--drop-in=</option> is specified, edit the drop-in file instead of
the main configuration file. Unless <option>--no-reload</option> is specified,
<command>systemd-networkd</command> will be reloaded after the edit of the
<filename>.network</filename> or <filename>.netdev</filename> files finishes.
The same applies for <filename>.link</filename> files and <command>systemd-udevd</command>.
Note that the changed link settings are not automatically applied after reloading.
To achieve that, trigger uevents for the corresponding interface. Refer to
<citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<command>cat</command>
<replaceable>FILE</replaceable>|<replaceable>@DEVICE</replaceable>
</term>
<listitem><para>Show network configuration files. This command honors
the <literal>@</literal> prefix in the same way as <command>edit</command>.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
@@ -405,6 +437,25 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
</listitem>
</varlistentry>
<varlistentry>
<term><option>--drop-in=</option></term>
<replaceable>NAME</replaceable>
<listitem>
<para>When used with <command>edit</command>, edit the drop-in file <replaceable>NAME</replaceable>
instead of the main configuration file.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--no-reload</option></term>
<listitem>
<para>When used with <command>edit</command>, <command>systemd-networkd</command>
or <command>systemd-udevd</command> will not be reloaded after the editing finishes.</para>
</listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="json" />
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />

File diff suppressed because it is too large Load Diff