]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Ipams/Plugin.pm
1 package PVE
::Network
::SDN
::Ipams
::Plugin
;
6 use PVE
::Tools
qw(run_command);
14 use PVE
::JSONSchema
qw(get_standard_option);
15 use base
qw(PVE::SectionConfig);
17 PVE
::Cluster
::cfs_register_file
('sdn/ipams.cfg',
18 sub { __PACKAGE__-
>parse_config(@_); },
19 sub { __PACKAGE__-
>write_config(@_); });
21 PVE
::JSONSchema
::register_standard_option
('pve-sdn-ipam-id', {
22 description
=> "The SDN ipam object identifier.",
23 type
=> 'string', format
=> 'pve-sdn-ipam-id',
26 PVE
::JSONSchema
::register_format
('pve-sdn-ipam-id', \
&parse_sdn_ipam_id
);
27 sub parse_sdn_ipam_id
{
28 my ($id, $noerr) = @_;
30 if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
31 return undef if $noerr;
32 die "ipam ID '$id' contains illegal characters\n";
41 description
=> "Plugin type.",
42 type
=> 'string', format
=> 'pve-configid',
45 ipam
=> get_standard_option
('pve-sdn-ipam-id',
46 { completion
=> \
&PVE
::Network
::SDN
::Ipams
::complete_sdn_ipam
}),
54 sub parse_section_header
{
55 my ($class, $line) = @_;
57 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
58 my ($type, $id) = (lc($1), $2);
59 my $errmsg = undef; # set if you want to skip whole section
60 eval { PVE
::JSONSchema
::pve_verify_configid
($type); };
62 my $config = {}; # to return additional attributes
63 return ($type, $id, $errmsg, $config);
70 my ($class, $plugin_config, $subnetid, $subnet) = @_;
74 my ($class, $plugin_config, $subnetid, $subnet) = @_;
78 my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
83 my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
87 my ($class, $plugin_config, $subnetid, $subnet, $ip) = @_;
91 my ($class, $plugin_config) = @_;
97 my ($method, $url, $headers, $data) = @_;
99 my $encoded_data = to_json
($data) if $data;
101 my $req = HTTP
::Request-
>new($method,$url, $headers, $encoded_data);
103 my $ua = LWP
::UserAgent-
>new(protocols_allowed
=> ['http', 'https'], timeout
=> 30);
107 $ua->proxy(['http', 'https'], $proxy);
112 $ua->ssl_opts(verify_hostname
=> 0, SSL_verify_mode
=> 0x00);
114 my $response = $ua->request($req);
115 my $code = $response->code;
117 if ($code !~ /^2(\d+)$/) {
118 my $msg = $response->message || 'unknown';
119 die "Invalid response from server: $code $msg\n";
123 if (defined($response->decoded_content)) {
124 $raw = $response->decoded_content;
126 $raw = $response->content;
128 return from_json
($raw) if $raw ne '';