return $defaultData;
}
+sub parse_section_header {
+ my ($class, $line) = @_;
+
+ if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
+ my ($type, $id) = (lc($1), $2);
+ my $errmsg = undef; # set if you want to skip whole section
+ eval { PVE::JSONSchema::pve_verify_configid($type); };
+ $errmsg = $@ if $@;
+ my $config = {}; # to return additional attributes
+ return ($type, $id, $errmsg, $config);
+ }
+ return undef;
+}
+
sub decode_value {
my ($class, $type, $key, $value) = @_;
- if ($key eq 'nodes') {
- my $res = {};
+ if ($key eq 'nodes' || $key eq 'exitnodes') {
+ my $res = {};
- foreach my $node (PVE::Tools::split_list($value)) {
- if (PVE::JSONSchema::pve_verify_node_name($node)) {
- $res->{$node} = 1;
- }
- }
+ foreach my $node (PVE::Tools::split_list($value)) {
+ if (PVE::JSONSchema::pve_verify_node_name($node)) {
+ $res->{$node} = 1;
+ }
+ }
- return $res;
+ return $res;
}
- return $value;
+ return $value;
}
sub encode_value {
my ($class, $type, $key, $value) = @_;
- if ($key eq 'nodes') {
- return join(',', keys(%$value));
+ if ($key eq 'nodes' || $key eq 'exitnodes') {
+ return join(',', keys(%$value));
}
return $value;
}
-sub parse_section_header {
- my ($class, $line) = @_;
-
- if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
- my ($type, $id) = (lc($1), $2);
- my $errmsg = undef; # set if you want to skip whole section
- eval { PVE::JSONSchema::pve_verify_configid($type); };
- $errmsg = $@ if $@;
- my $config = {}; # to return additional attributes
- return ($type, $id, $errmsg, $config);
- }
- return undef;
-}
-
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
die "please implement inside plugin";
}
sub find_local_ip_interface_peers {
- my ($peers) = @_;
+ my ($peers, $iface) = @_;
my $network_config = PVE::INotify::read_file('interfaces');
my $ifaces = $network_config->{ifaces};
+
+ #if iface is defined, return ip if exist (if not,try to find it on other ifaces)
+ if ($iface) {
+ my $ip = $ifaces->{$iface}->{address};
+ return ($ip,$iface) if $ip;
+ }
+
#is a local ip member of peers list ?
foreach my $address (@{$peers}) {
while (my $interface = each %$ifaces) {
}
}
+sub find_bridge {
+ my ($bridge) = @_;
+
+ die "can't find bridge $bridge" if !-d "/sys/class/net/$bridge";
+}
+
+sub is_vlanaware {
+ my ($bridge) = @_;
+
+ return PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
+}
+
+sub is_ovs {
+ my ($bridge) = @_;
+
+ my $is_ovs = !-d "/sys/class/net/$bridge/brif";
+ return $is_ovs;
+}
+
+sub get_bridge_ifaces {
+ my ($bridge) = @_;
+
+ my @bridge_ifaces = ();
+ my $dir = "/sys/class/net/$bridge/brif";
+ PVE::Tools::dir_glob_foreach($dir, '(((eth|bond)\d+|en[^.]+)(\.\d+)?)', sub {
+ push @bridge_ifaces, $_[0];
+ });
+
+ return @bridge_ifaces;
+}
1;