4 use PVE
::Cluster
qw(cfs_read_file);
6 use PVE
::Network
::Network
::Plugin
;
7 use PVE
::Network
::Network
::VnetPlugin
;
8 use PVE
::Network
::Network
::VlanPlugin
;
9 use PVE
::Network
::Network
::VxlanMulticastPlugin
;
11 PVE
::Network
::Network
::VnetPlugin-
>register();
12 PVE
::Network
::Network
::VlanPlugin-
>register();
13 PVE
::Network
::Network
::VxlanMulticastPlugin-
>register();
14 PVE
::Network
::Network
::Plugin-
>init();
17 my $rawconfig = generate_network_config
();
19 write_final_config
($rawconfig);
21 sub generate_network_config
{
23 #only support ifupdown2
24 die "you need ifupdown2 to reload networking\n" if !-e
'/usr/share/ifupdown2';
26 #read main config for physical interfaces
27 my $current_config_file = "/etc/network/interfaces";
28 my $fh = IO
::File-
>new($current_config_file);
29 my $interfaces_config = PVE
::INotify
::read_etc_network_interfaces
(1,$fh);
34 foreach my $id (keys %{$interfaces_config->{ifaces
}}) {
35 my $interface = $interfaces_config->{ifaces
}->{$id};
36 if (my $uplink = $interface->{'uplink-id'}) {
37 die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
38 $uplinks->{$interface->{'uplink-id'}} = $id;
42 my $network_cfg = PVE
::Cluster
::cfs_read_file
('networks.cfg');
44 my $transport_cfg = undef;
46 foreach my $id (keys %{$network_cfg->{ids
}}) {
47 if ($network_cfg->{ids
}->{$id}->{type
} eq 'vnet') {
48 $vnet_cfg->{ids
}->{$id} = $network_cfg->{ids
}->{$id};
50 $transport_cfg->{ids
}->{$id} = $network_cfg->{ids
}->{$id};
54 #generate configuration
56 foreach my $id (keys %{$vnet_cfg->{ids
}}) {
57 my $vnet = $vnet_cfg->{ids
}->{$id};
58 my $zone = $vnet->{transportzone
};
60 die "zone $zone don't exist" if !$zone;
61 my $plugin_config = $transport_cfg->{ids
}->{$zone};
62 die "zone $zone don't exist" if !defined($plugin_config);
63 my $plugin = PVE
::Network
::Network
::Plugin-
>lookup($plugin_config->{type
});
64 $rawconfig .= $plugin->generate_network_config($plugin_config, $zone, $id, $vnet, $uplinks);
71 sub write_final_config
{
73 #now write final separate filename
74 my $tmp_file = "/var/tmp/pve-vnet.cfg";
76 my $vnet_interfaces_file = "/etc/network/interfaces.d/vnet";
78 my $writefh = IO
::File-
>new($vnet_interfaces_file,">");
79 print $writefh $rawconfig;