]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/SubnetPlugin.pm
1 package PVE
::Network
::SDN
::SubnetPlugin
;
6 use PVE
::Cluster
qw(cfs_read_file cfs_write_file cfs_lock_file);
7 use base
qw(PVE::SectionConfig);
8 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::Exception
qw(raise raise_param_exc);
10 use Net
::Subnet
qw(subnet_matcher);
12 PVE
::Cluster
::cfs_register_file
('sdn/subnets.cfg',
13 sub { __PACKAGE__-
>parse_config(@_); },
14 sub { __PACKAGE__-
>write_config(@_); });
16 PVE
::JSONSchema
::register_standard_option
('pve-sdn-subnet-id', {
17 description
=> "The SDN subnet object identifier.",
18 type
=> 'string', format
=> 'pve-sdn-subnet-id',
22 PVE
::JSONSchema
::register_format
('pve-sdn-subnet-id', \
&parse_sdn_subnet_id
);
23 sub parse_sdn_subnet_id
{
24 my ($id, $noerr) = @_;
26 my $cidr = $id =~ s/-/\//r
;
28 if (!(PVE
::JSONSchema
::pve_verify_cidrv4
($cidr, 1) ||
29 PVE
::JSONSchema
::pve_verify_cidrv6
($cidr, 1)))
31 return undef if $noerr;
32 die "value does not look like a valid CIDR network\n";
40 subnet
=> get_standard_option
('pve-sdn-subnet-id',
41 { completion
=> \
&PVE
::Network
::SDN
::Subnets
::complete_sdn_subnet
}),
56 type
=> 'string', format
=> 'ip',
57 description
=> "Subnet Gateway: Will be assign on vnet for layer3 zones",
61 description
=> "enable masquerade for this subnet if pve-firewall",
63 #cloudinit, dhcp options
66 description
=> "static routes [network=<network>:gateway=<ip>,network=<network>:gateway=<ip>,... ]",
68 #cloudinit, dhcp options
70 type
=> 'string', format
=> 'address-list',
71 description
=> " dns nameserver",
73 #cloudinit, dhcp options
79 description
=> "enable dhcp for this subnet",
83 description
=> "Develop some dns registrations plugins (powerdns,...)",
87 description
=> "use a specific ipam",
94 gateway
=> { optional
=> 1 },
95 routes
=> { optional
=> 1 },
96 nameservers
=> { optional
=> 1 },
97 searchdomain
=> { optional
=> 1 },
98 snat
=> { optional
=> 1 },
99 dhcp
=> { optional
=> 1 },
100 dns_driver
=> { optional
=> 1 },
101 ipam
=> { optional
=> 1 },
106 my ($class, $subnetid, $subnet_cfg) = @_;
108 my $subnet = $subnetid =~ s/-/\//r
;
109 my $subnet_matcher = subnet_matcher
($subnet);
111 my $gateway = $subnet_cfg->{ids
}->{$subnetid}->{gateway
};
112 raise_param_exc
({ gateway
=> "$gateway is not in subnet $subnet"}) if $gateway && !$subnet_matcher->($gateway);
117 my ($class, $subnetid, $subnet_cfg, $vnet_cfg) = @_;
119 #verify if vnets have subnet
120 foreach my $vnetid (keys %{$vnet_cfg->{ids
}}) {
121 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
122 my @subnets = PVE
::Tools
::split_list
($vnet->{subnets
}) if $vnet->{subnets
};
123 foreach my $subnet (@subnets) {
124 my $id = $subnet =~ s/\//-/r
;
125 raise_param_exc
({ subnet
=> "$subnet is attached to vnet $vnetid"}) if $id eq $subnetid;