]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
6261764ffb5cb9d7b2bc865704ac74663790d860
1 package PVE
::Network
::SDN
::Ipams
::PhpIpamPlugin
;
9 use base
('PVE::Network::SDN::Ipams::Plugin');
32 url
=> { optional
=> 0},
33 token
=> { optional
=> 0 },
34 section
=> { optional
=> 0 },
38 # Plugin implementation
41 my ($class, $plugin_config, $subnetid, $subnet) = @_;
43 my $cidr = $subnet->{cidr
};
44 my $network = $subnet->{network
};
45 my $mask = $subnet->{mask
};
47 my $gateway = $subnet->{gateway
};
48 my $url = $plugin_config->{url
};
49 my $token = $plugin_config->{token
};
50 my $section = $plugin_config->{section
};
51 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
54 my $internalid = get_internalid
($url, $cidr, $headers);
59 my $params = { subnet
=> $network,
61 sectionId
=> $section,
65 PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("POST", "$url/subnets/", $headers, $params);
68 die "error add subnet to ipam: $@";
75 my ($class, $plugin_config, $subnetid, $subnet) = @_;
77 my $cidr = $subnet->{cidr
};
78 my $url = $plugin_config->{url
};
79 my $token = $plugin_config->{token
};
80 my $section = $plugin_config->{section
};
81 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
83 my $internalid = get_internalid
($url, $cidr, $headers);
84 return if !$internalid;
86 return; #fixme: check that prefix is empty exluding gateway, before delete
89 PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("DELETE", "$url/subnets/$internalid", $headers);
92 die "error deleting subnet from ipam: $@";
98 my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_;
100 my $cidr = $subnet->{cidr
};
101 my $url = $plugin_config->{url
};
102 my $token = $plugin_config->{token
};
103 my $section = $plugin_config->{section
};
104 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
106 my $internalid = get_internalid
($url, $cidr, $headers);
108 my $params = { ip
=> $ip,
109 subnetId
=> $internalid,
110 is_gateway
=> $is_gateway,
111 hostname
=> $hostname,
112 description
=> $description,
116 PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("POST", "$url/addresses/", $headers, $params);
120 die "error add subnet ip to ipam: ip $ip already exist: $@";
124 sub add_next_freeip
{
125 my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_;
127 my $cidr = $subnet->{cidr
};
128 my $mask = $subnet->{mask
};
129 my $url = $plugin_config->{url
};
130 my $token = $plugin_config->{token
};
131 my $section = $plugin_config->{section
};
132 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
134 my $internalid = get_internalid
($url, $cidr, $headers);
136 my $params = { hostname
=> $hostname,
137 description
=> $description,
142 my $result = PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("POST", "$url/addresses/first_free/$internalid/", $headers, $params);
143 $ip = $result->{data
};
147 die "can't find free ip in subnet $cidr: $@";
154 my ($class, $plugin_config, $subnetid, $subnet, $ip) = @_;
158 my $url = $plugin_config->{url
};
159 my $token = $plugin_config->{token
};
160 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
162 my $ip_id = get_ip_id
($url, $ip, $headers);
166 PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("DELETE", "$url/addresses/$ip_id", $headers);
169 die "error delete ip $ip: $@";
174 my ($class, $plugin_config) = @_;
176 my $url = $plugin_config->{url
};
177 my $token = $plugin_config->{token
};
178 my $sectionid = $plugin_config->{section
};
179 my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
182 PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("GET", "$url/sections/$sectionid", $headers);
185 die "Can't connect to phpipam api: $@";
190 my ($class, $plugin_config) = @_;
192 PVE
::Network
::SDN
::Ipams
::PhpIpamPlugin
::verify_api
($class, $plugin_config);
199 my ($url, $cidr, $headers) = @_;
201 my $result = PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("GET", "$url/subnets/cidr/$cidr", $headers);
202 my $data = @{$result->{data
}}[0];
203 my $internalid = $data->{id
};
208 my ($url, $ip, $headers) = @_;
209 my $result = PVE
::Network
::SDN
::Ipams
::Plugin
::api_request
("GET", "$url/addresses/search/$ip", $headers);
210 my $data = @{$result->{data
}}[0];
211 my $ip_id = $data->{id
};