Skip to content

Commit

Permalink
ncm-network: Move nmstate options to backend specific schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Sep 20, 2024
1 parent 7f71af6 commit c63d9c0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type network_ipv6 = {
when using ncm-network (unless specified otherwise).
}
type structure_network = {
include structure_network_backend_specific
"domainname" : type_fqdn
"hostname" : type_shorthostname
"realhostname" ? string with is_shorthostname(SELF) || is_fqdn(SELF)
Expand All @@ -63,10 +64,6 @@ type structure_network = {
"set_hwaddr" ? boolean
"nmcontrolled" ? boolean
"allow_nm" ? boolean
@{let NetworkManager manage the dns (only for nmstate)}
"nm_manage_dns" : boolean = false
@{let ncm-network cleanup inactive connections (only for nmstate)}
"nm_clean_inactive_conn" : boolean = true
"primary_ip" ? string
"routers" ? network_router{}
"ipv6" ? network_ipv6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
declaration template components/network/types/network/backend/initscripts;

@{implement types specific for initscripts / network.pm}

type structure_network_backend_specific = {
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
declaration template components/network/types/network/backend/nmstate;

@{implement types specific for nmstate / nmstate.pm}

type structure_network_nmstate = {
@{let NetworkManager manage the dns}
"manage_dns" : boolean = false
@{let ncm-network cleanup inactive connections}
"clean_inactive_conn" : boolean = true
};

type structure_network_backend_specific = {
"nmstate" : structure_network_nmstate
};
12 changes: 6 additions & 6 deletions ncm-network/src/main/perl/nmstate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use Readonly;

Readonly my $NMSTATECTL => '/usr/bin/nmstatectl';
Readonly my $NMCLI_CMD => '/usr/bin/nmcli';
# pick a config name for nmstate yml to configure dns-resolver: settings. if nm_manage_dns=true
# pick a config name for nmstate yml to configure dns-resolver: settings. if nmstate/manage_dns=true
Readonly my $NM_RESOLV_YML => "/etc/nmstate/resolv.yml";
Readonly my $NM_DROPIN_CFG_FILE => "/etc/NetworkManager/conf.d/90-quattor.conf";

Expand Down Expand Up @@ -82,7 +82,7 @@ sub is_valid_interface

# By default, NetworkManager on Red Hat Enterprise Linux (RHEL) 8+ dynamically updates the /etc/resolv.conf
# file with the DNS settings from active NetworkManager connection profiles. we manage this using ncm-resolver.
# so disable this unless nm_manage_dns = true. resolver details can be set using nmstate but not doing this now.
# so disable this unless nmstate/manage_dns = true. resolver details can be set using nmstate but not doing this now.
sub disable_nm_manage_dns
{
my ($self, $manage_dns, $nwsrv) = @_;
Expand Down Expand Up @@ -571,7 +571,7 @@ sub generate_nmstate_config
};

# Generate hash of dns-resolver config for nmstate.
# only used if nm_manage_dns = true.
# only used if nmstate/manage_dns = true.
sub generate_nm_resolver_config
{
my ($self, $net, $manage) = @_;
Expand Down Expand Up @@ -699,7 +699,7 @@ sub nmstate_apply
$action = 0;
}
# apply resolver config if exists.
# this will exist at this stage if nm_manage_dns is set to true.
# this will exist at this stage if nmstate/manage_dns is set to true.
my $resolv_state = $exifiles->{$NM_RESOLV_YML} || 0;
if ($self->file_exists($NM_RESOLV_YML))
{
Expand Down Expand Up @@ -770,7 +770,7 @@ sub Configure
my $nwtree = $config->getTree($NETWORK_PATH);

my $hostname = $nwtree->{realhostname} || "$nwtree->{hostname}.$nwtree->{domainname}";
my $manage_dns = $nwtree->{nm_manage_dns} || 0;
my $manage_dns = $nwtree->{nmstate}->{manage_dns} || 0;
my $dgw = $nwtree->{default_gateway};
if (!$dgw) {
$self->warn ("No default gateway configured");
Expand Down Expand Up @@ -911,7 +911,7 @@ sub Configure

# cleanup dangling inactive connections after ncm network changes are applied.
# defaults to cleanup
my $clean_inactive_conn = $net->{nm_clean_inactive_conn};
my $clean_inactive_conn = $net->{nmstate}->{clean_inactive_conn};
if ($clean_inactive_conn and $stopstart) {
# look to cleanup connections only when something is changed.
$self->clear_inactive_nm_connections;
Expand Down
4 changes: 4 additions & 0 deletions ncm-network/src/test/resources/nmstate_simple.pan
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
object template nmstate_simple;

variable QUATTOR_TYPES_NETWORK_BACKEND = 'nmstate';

include 'simple_base_profile';
"/hardware/cards/nic/eth0/hwaddr" = "6e:a5:1b:55:77:0a";
# the next include is mainly to the profile, it is not used in the tests
# (unless the component gets specific schema things)
include 'components/network/config-nmstate';

"/system/network/nmstate" = dict();

0 comments on commit c63d9c0

Please sign in to comment.