]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/Network.pm
api2 : network : add mtu
[pve-manager.git] / PVE / API2 / Network.pm
index 5e2abda134540478bcbbeef82d0a73b090866be8..20e377813fd25e483b6d10774e0112a1c9cefc39 100644 (file)
@@ -16,6 +16,13 @@ use IO::File;
 
 use base qw(PVE::RESTHandler);
 
+my $have_sdn;
+eval {
+    require PVE::Network::SDN::Zones;
+    require PVE::Network::SDN::Controllers;
+    $have_sdn = 1;
+};
+
 my $iflockfn = "/etc/network/.pve-interfaces.lock";
 
 my $bond_mode_enum = [
@@ -103,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,
@@ -131,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',
@@ -548,13 +567,34 @@ __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 $cmd = ['ifreload', '-a'];
+           if ($have_sdn) {
+               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;
@@ -562,8 +602,13 @@ __PACKAGE__->register_method({
                    print "$2 : $line \n";
                }
            };
+           PVE::Tools::run_command(['ifreload', '-a'], errfunc => $err);
 
-           PVE::Tools::run_command($cmd,errfunc => $err);
+           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);
    }});