2012-06-18 63 views
1

我想用Infoblox API更改Infoblox設備中nsgroup的輔助DNS服務器。原始的nsgroup包含兩個輔助DNS服務器,我想放置一個DNS輔助服務器(當然有一個主服務器)。修改Infoblox :: Grid :: DNS的輔助DNS服務器:: Nsgroup

以下代碼更改nsgroup的註釋,但不會更改NS組的輔助服務器!我總是有兩個輔助DNS服務器。該代碼不會觸發任何錯誤。

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(); 
} 

回答

2

啊,Infoblox API的樂趣。這是它的一個細微之處。您不能使用現有的成員對象來創建新對象。但你可以使用你已經檢索到的次要對象的值...

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

希望這會有所幫助。

相關問題