add nodes option to zones

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2019-11-26 10:00:23 +01:00 committed by Thomas Lamprecht
parent a069f0b4a4
commit c2b9c1734f
8 changed files with 46 additions and 0 deletions

View File

@ -32,6 +32,10 @@ my $api_sdn_zones_config = sub {
$scfg->{zone} = $id;
$scfg->{digest} = $cfg->{digest};
if ($scfg->{nodes}) {
$scfg->{nodes} = PVE::Storage::Plugin->encode_value($scfg->{type}, 'nodes', $scfg->{nodes});
}
return $scfg;
};

View File

@ -97,6 +97,8 @@ sub generate_etc_network_config {
#generate configuration
my $config = {};
my $nodename = PVE::INotify::nodename();
foreach my $id (keys %{$vnet_cfg->{ids}}) {
my $vnet = $vnet_cfg->{ids}->{$id};
my $zone = $vnet->{zone};
@ -113,6 +115,8 @@ sub generate_etc_network_config {
next;
}
next if defined($plugin_config->{nodes}) && !$plugin_config->{nodes}->{$nodename};
my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
$plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $uplinks, $config);
}
@ -196,12 +200,16 @@ sub status {
my $status = ifquery_check();
my $vnet_cfg = PVE::Cluster::cfs_read_file('sdn/vnets.cfg');
my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
my $nodename = PVE::INotify::nodename();
my $vnet_status = {};
my $transport_status = {};
foreach my $id (keys %{$vnet_cfg->{ids}}) {
my $zone = $vnet_cfg->{ids}->{$id}->{zone};
next if defined($zone_cfg->{ids}->{$zone}->{nodes}) && !$zone_cfg->{ids}->{$zone}->{nodes}->{$nodename};
$vnet_status->{$id}->{zone} = $zone;
$transport_status->{$zone}->{status} = 'available' if !defined($transport_status->{$zone}->{status});

View File

@ -38,6 +38,7 @@ sub properties {
sub options {
return {
nodes => { optional => 1},
'uplink-id' => { optional => 0 },
'vrf' => { optional => 0 },
'vrf-vxlan' => { optional => 0 },

View File

@ -28,6 +28,7 @@ sub properties {
sub options {
return {
nodes => { optional => 1},
'dp-id' => { optional => 0 },
'uplink-id' => { optional => 0 },
'controller' => { optional => 0 },

View File

@ -42,6 +42,7 @@ my $defaultData = {
type => 'string', format => 'pve-configid',
type => 'string',
},
nodes => get_standard_option('pve-node-list', { optional => 1 }),
zone => get_standard_option('pve-sdn-zone-id',
{ completion => \&PVE::Network::SDN::Zones::complete_sdn_zone }),
},
@ -51,6 +52,34 @@ sub private {
return $defaultData;
}
sub decode_value {
my ($class, $type, $key, $value) = @_;
if ($key eq 'nodes') {
my $res = {};
foreach my $node (PVE::Tools::split_list($value)) {
if (PVE::JSONSchema::pve_verify_node_name($node)) {
$res->{$node} = 1;
}
}
return $res;
}
return $value;
}
sub encode_value {
my ($class, $type, $key, $value) = @_;
if ($key eq 'nodes') {
return join(',', keys(%$value));
}
return $value;
}
sub parse_section_header {
my ($class, $line) = @_;

View File

@ -29,6 +29,7 @@ sub properties {
sub options {
return {
nodes => { optional => 1},
'uplink-id' => { optional => 0 },
'tag' => { optional => 0 },
'vlan-protocol' => { optional => 1 },

View File

@ -32,6 +32,7 @@ sub properties {
sub options {
return {
nodes => { optional => 1},
'uplink-id' => { optional => 0 },
};
}

View File

@ -56,6 +56,7 @@ sub properties {
sub options {
return {
nodes => { optional => 1},
'uplink-id' => { optional => 0 },
'multicast-address' => { optional => 1 },
'unicast-address' => { optional => 1 },