Question

I want to change the secondary DNS servers of a nsgroup in an Infoblox appliance with the Infoblox API. The original nsgroup contains two secondary DNS servers and I want to put a single DNS secondary server (with one master of course).

The following code change the comment of nsgroup but does not alter the secondary servers of NS Group! I always have two secondary DNS servers. The code does not trigger any errors.

sub nsGroupSlave {
    # https://ipam.illinois.edu/api/doc/Infoblox/Grid/DNS/Nsgroup.html

    my @retrieved_obj = $session->get(
        object => "Infoblox::Grid::DNS::Nsgroup",
        name => "Interne"); 
    my $nsg1 = $retrieved_obj[0]; 

    unless ($nsg1){
        msg(t() . "ERROR : " . Infoblox::status_code() . ":" . Infoblox::status_detail(),$v);
    } else {
        msg(t() . "OK",$v);
    }

    my @retrieved_objsp = $session->get(
        object => "Infoblox::Grid::Member",
        name => "ns1.intra.example.com"
    ); 
    my $nsp = $retrieved_objsp[0]; 

    my @retrieved_objssi = $session->get(
        object => "Infoblox::Grid::Member",
        name => "nsZ.intra.example.com"
    ); 
    my $nssi = $retrieved_objssi[0]; 


    my @result_array = $session->get(
        "object" => "Infoblox::Grid::DNS" , 
        "grid" => "infoblox" 
    );


    my $object = $result_array[0];

    $nsg1->primary($nsp);
    $nsg1->secondaries([$nssi]);
    $nsg1->comment("Modify by restore-backup");

    my $response1 = $session->modify($nsg1);
    unless ($response1) {
        msg(t() . "FAIL : ", $session->status_code() . ":" . $session->status_detail(),$v);
    }

    $object->nsgroups( [ $nsg1 ] );

    my $response3 = $session->modify($object);
    unless ($response3) {
        msg(t() . "FAIL : ", $session->status_code() . ":" . $session->status_detail(),$v);
    }

    $session->restart();
}
Was it helpful?

Solution

Ah the joys of Infoblox API. This is one of it's nuances. You can't use an existing member object you have to create a new one. But you can use the value from the secondary object that you have already retrieved...

my $newMember = Infoblox::DNS::Member->new(
    name     => $nssi->name(),
    ipv4addr => $nssi->ipv4addr(),
);
$nsg1->primary($nsp);
$nsg1->secondaries([$newMember]);
$nsg1->comment("Modify by restore-backup");

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top