sub add_subnet {
my ($class, $plugin_config, $subnetid, $subnet) = @_;
- my $cidr = $subnetid =~ s/-/\//r;
+ my $cidr = $subnet->{cidr};
my $gateway = $subnet->{gateway};
my $url = $plugin_config->{url};
my $token = $plugin_config->{token};
#create subnet
if (!$internalid) {
- my ($network, $mask) = split(/-/, $subnetid);
my $params = { prefix => $cidr };
eval {
my $result = PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/ipam/prefixes/", $headers, $params);
- $subnet->{ipamid} = $result->{id} if defined($result->{id});
};
if ($@) {
die "error add subnet to ipam: $@";
sub del_subnet {
my ($class, $plugin_config, $subnetid, $subnet) = @_;
- my $cidr = $subnetid =~ s/-/\//r;
+ my $cidr = $subnet->{cidr};
my $url = $plugin_config->{url};
my $token = $plugin_config->{token};
my $gateway = $subnet->{gateway};
my $internalid = get_prefix_id($url, $cidr, $headers);
return if !$internalid;
- #fixme: check that prefix is empty exluding gateway, before delete
- PVE::Network::SDN::Ipams::NetboxPlugin::del_ip($class, $plugin_config, $subnetid, $gateway) if $gateway;
+ return; #fixme: check that prefix is empty exluding gateway, before delete
eval {
PVE::Network::SDN::Ipams::Plugin::api_request("DELETE", "$url/ipam/prefixes/$internalid/", $headers);
}
sub add_ip {
- my ($class, $plugin_config, $subnetid, $ip, $is_gateway) = @_;
+ my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
- my ($network, $mask) = split(/-/, $subnetid);
+ my $mask = $subnet->{mask};
my $url = $plugin_config->{url};
my $token = $plugin_config->{token};
my $section = $plugin_config->{section};
my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"];
+ $description .= " mac:$mac" if $mac && $description;
- my $params = { address => "$ip/$mask" };
+ my $params = { address => "$ip/$mask", dns_name => $hostname, description => $description };
eval {
PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/ipam/ip-addresses/", $headers, $params);
}
sub add_next_freeip {
- my ($class, $plugin_config, $subnetid, $subnet) = @_;
+ my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
+
+ my $cidr = $subnet->{cidr};
- my $cidr = $subnetid =~ s/-/\//r;
my $url = $plugin_config->{url};
my $token = $plugin_config->{token};
my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"];
my $internalid = get_prefix_id($url, $cidr, $headers);
+ $description .= " mac:$mac" if $mac && $description;
- my $params = {};
+ my $params = { dns_name => $hostname, description => $description };
my $ip = undef;
eval {
}
sub del_ip {
- my ($class, $plugin_config, $subnetid, $ip) = @_;
+ my ($class, $plugin_config, $subnetid, $subnet, $ip) = @_;
return if !$ip;