]>
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>,... ]",
70 description
=> "dns api server",
74 description
=> "reverse dns api server",
77 type
=> 'string', format
=> 'dns-name',
78 description
=> "dns domain zone ex: mydomain.com",
81 type
=> 'string', format
=> 'dns-name',
82 description
=> "reverse dns zone ex: 0.168.192.in-addr.arpa",
85 type
=> 'string', format
=> 'dns-name',
86 description
=> "dns domain zone prefix ex: 'adm' -> <hostname>.adm.mydomain.com",
90 description
=> "use a specific ipam",
97 gateway
=> { optional
=> 1 },
98 # routes => { optional => 1 },
99 snat
=> { optional
=> 1 },
100 dns
=> { optional
=> 1 },
101 reversedns
=> { optional
=> 1 },
102 dnszone
=> { optional
=> 1 },
103 reversednszone
=> { optional
=> 1 },
104 dnszoneprefix
=> { optional
=> 1 },
105 ipam
=> { optional
=> 1 },
110 my ($class, $subnetid, $subnet_cfg) = @_;
112 my $cidr = $subnetid =~ s/-/\//r
;
113 my $subnet_matcher = subnet_matcher
($cidr);
115 my $subnet = $subnet_cfg->{ids
}->{$subnetid};
117 my $gateway = $subnet->{gateway
};
118 my $dns = $subnet->{dns
};
119 my $dnszone = $subnet->{dnszone
};
120 my $reversedns = $subnet->{reversedns
};
121 my $reversednszone = $subnet->{reversednszone
};
123 #to: for /32 pointotoping, allow gateway outside the subnet
124 raise_param_exc
({ gateway
=> "$gateway is not in subnet $subnet"}) if $gateway && !$subnet_matcher->($gateway);
126 raise_param_exc
({ dns
=> "missing dns provider"}) if $dnszone && !$dns;
127 raise_param_exc
({ dnszone
=> "missing dns zone"}) if $dns && !$dnszone;
128 raise_param_exc
({ reversedns
=> "missing dns provider"}) if $reversednszone && !$reversedns;
129 raise_param_exc
({ reversednszone
=> "missing dns zone"}) if $reversedns && !$reversednszone;
130 raise_param_exc
({ reversedns
=> "missing forward dns zone"}) if $reversednszone && !$dnszone;
135 my ($class, $subnetid, $subnet_cfg, $vnet_cfg) = @_;
137 #verify if vnets have subnet
138 foreach my $vnetid (keys %{$vnet_cfg->{ids
}}) {
139 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
140 my @subnets = PVE
::Tools
::split_list
($vnet->{subnets
}) if $vnet->{subnets
};
141 foreach my $subnet (@subnets) {
142 my $id = $subnet =~ s/\//-/r
;
143 raise_param_exc
({ subnet
=> "$subnet is attached to vnet $vnetid"}) if $id eq $subnetid;