]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/Network.pm
api2 : network : add mtu
[pve-manager.git] / PVE / API2 / Network.pm
index ac5571a774eb98741af28f713d5890133ce887d4..20e377813fd25e483b6d10774e0112a1c9cefc39 100644 (file)
@@ -18,7 +18,8 @@ use base qw(PVE::RESTHandler);
 
 my $have_sdn;
 eval {
-    require PVE::API2::Network::SDN;
+    require PVE::Network::SDN::Zones;
+    require PVE::Network::SDN::Controllers;
     $have_sdn = 1;
 };
 
@@ -109,6 +110,11 @@ my $confdesc = {
        optional => 1,
        type => 'string', enum => $bond_mode_enum,
     },
+    'bond-primary' => {
+       description => "Specify the primary interface for active-backup bond.",
+       optional => 1,
+       type => 'string', format => 'pve-iface',
+    },
     bond_xmit_hash_policy => {
        description => "Selects the transmit hash policy to use for slave selection in balance-xor and 802.3ad modes.",
        optional => 1,
@@ -137,6 +143,13 @@ my $confdesc = {
        type => 'string', format => 'CIDRv4',
        optional => 1,
     },
+    mtu => {
+       description => 'MTU.',
+       optional => 1,
+       type => 'integer',
+       minimum => 1280,
+       maximum => 65520,
+    },
     gateway6 => {
        description => 'Default ipv6 gateway address.',
        type => 'string', format => 'ipv6',
@@ -554,22 +567,35 @@ __PACKAGE__->register_method({
        my $new_config_file = "/etc/network/interfaces.new";
 
        die "you need ifupdown2 to reload networking\n" if !-e '/usr/share/ifupdown2';
-       die "ifupdown2 reload is not compatible if openvswitch currently" if -x '/usr/bin/ovs-vsctl';
+
+       if (-x '/usr/bin/ovs-vsctl') {
+           my $ovs_configured = sub {
+               my $ifaces = shift;
+               my @ovstypes = grep { $_->{type} =~ /^ovs\S+/i } values %$ifaces;
+               return scalar(@ovstypes) > 0;
+           };
+           my $tmp = PVE::INotify::read_file('interfaces', 1);
+           my $ifaces = $tmp->{data}->{ifaces};
+           my $changes = $tmp->{changes};
+
+           if ($ovs_configured->($ifaces)) {
+               die "There are OpenVSwitch configured interfaces, but ifupdown2 ".
+                   " reload is not compatible with openvswitch currently\n";
+           } elsif ($changes && $changes =~ /^\s*(?:[+-])?\s*(ovs_type|allow-ovs)/mi) {
+               die "Changes include OpenVSwitch interfaces, but ifupdown2 ".
+                   "reload is not compatible with openvswitch currently\n";
+           }
+       }
 
        my $worker = sub {
 
            rename($new_config_file, $current_config_file) if -e $new_config_file;
 
-           my $frr_config;
            if ($have_sdn) {
-               my $network_config = PVE::Network::SDN::generate_etc_network_config();
-               PVE::Network::SDN::write_etc_network_config($network_config);
-
-               $frr_config = PVE::Network::SDN::generate_frr_config();
-               PVE::Network::SDN::write_frr_config($frr_config) if $frr_config;
+               my $network_sdn_config = PVE::Network::SDN::Zones::generate_etc_network_config();
+               PVE::Network::SDN::Zones::write_etc_network_config($network_sdn_config);
            }
 
-
            my $err = sub {
                my $line = shift;
                if ($line =~ /(warning|error): (\S+):/) {
@@ -578,8 +604,10 @@ __PACKAGE__->register_method({
            };
            PVE::Tools::run_command(['ifreload', '-a'], errfunc => $err);
 
-           if ($frr_config && -e "/usr/lib/frr/frr-reload.py") {
-               PVE::Tools::run_command(['systemctl', 'reload', 'frr']);
+           if ($have_sdn) {
+               my $controller_config = PVE::Network::SDN::Controllers::generate_controller_config();
+               PVE::Network::SDN::Controllers::write_controller_config($controller_config) if ($controller_config);
+               PVE::Network::SDN::Controllers::reload_controller();
            }
        };
        return $rpcenv->fork_worker('srvreload', 'networking', $authuser, $worker);