cvicente / Netdot

Network Documentation Tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot create CNAME from REST API

mzagrabe opened this issue · comments

Using the following REST client code:

#!/usr/bin/perl

use Netdot::Client::REST;

my $netdot = Netdot::Client::REST->new(
username => 'netdot-services-test',
password => 'CHANGEME',
server => 'https://netdot-test.example.com',
);

my $new_cname = $netdot->post(
'rrcname',
{
cname => 'foo.example.com',
rr => 34,
ttl => 28800,
},
);

Getting the following error:

Cannot add CNAME records when other records exist

from the lib/Netdot/Model/RRCNAME.pm insert subroutine.

Looking at a dump of the %linksfrom...
my %linksfrom = RR->meta_data->get_links_from;

shows some questionable data:

$VAR1 = {
'cnames' => {
'RRCNAME' => 'rr'
},
'ns_records' => {
'RRNS' => 'rr'
},
'srv_records' => {
'RRSRV' => 'rr'
},
'devices' => {
'Device' => 'name'
},
'a_records' => {
'RRADDR' => 'rr'
},
'loc_records' => {
'RRLOC' => 'rr'
},
'txt_records' => {
'RRTXT' => 'rr'
},
'hinfo_records' => {
'RRHINFO' => 'rr'
},
'naptr_records' => {
'RRNAPTR' => 'rr'
},
'mx_records' => {
'RRMX' => 'rr'
},
'ds_records' => {
'RRDS' => 'rr'
},
'ptr_records' => {
'RRPTR' => 'rr'
}
};

And the conditional check fails:

foreach my $i ( keys %linksfrom ){
if ( $rr->$i ){
$class->throw_user("Cannot add CNAME records when other records exist");
}
}

I don't know what the check is exactly trying to do.

Let me know if you need further info to help with this bug.

Thanks!

False alarm. I didn't understand how the creation of an RRCNAME worked.

You need to first create the RR, then you can pass along the id of the newly created RR to the REST call of creating the RRCNAME.

Here is some python code that works.

`#!/usr/bin/python3

import pynetdot

pynetdot.setup(
username = 'netdot-services-test',
password = 'CHANGEME',
url = 'https://netdot-test.example.com',
)

zone = pynetdot.Zone.get_first(
name = 'example.com',
)

new_rr = pynetdot.RR()
new_rr.name = 'super-convient-record-1'
new_rr.zone = zone.id
new_rr.save()

new_cname = pynetdot.RRCNAME()
new_cname.cname = 'web-server-01.hosting-company.com'
new_cname.rr = new_rr.id
new_cname.save()`