Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions nipap/nipap/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,6 @@ def _execute(self, sql, opt=None, callno=0):
except psycopg2.Warning as warn:
self._logger.warning(warn)

def _lastrowid(self):
""" Get ID of last inserted column.
"""

# TODO: hmm, we can do this by doing fetchone() on our cursor
self._execute("SELECT lastval() AS last")
for row in self._curs_pg:
return row['last']

def _sql_expand_insert(self, spec, key_prefix='', col_prefix=''):
""" Expand a dict so it fits in a INSERT clause
"""
Expand Down Expand Up @@ -1196,10 +1187,10 @@ def add_vrf(self, auth, attr):
self._check_attr(attr, req_attr, _vrf_attrs)

insert, params = self._sql_expand_insert(attr)
sql = "INSERT INTO ip_net_vrf " + insert
sql = "INSERT INTO ip_net_vrf " + insert + " RETURNING id"

self._execute(sql, params)
vrf_id = self._lastrowid()
vrf_id = self._curs_pg.fetchone()[0]
vrf = self.list_vrf(auth, {'id': vrf_id})[0]

# write to audit table
Expand Down Expand Up @@ -1722,10 +1713,10 @@ def add_pool(self, auth, attr):
self._check_pool_attr(attr, req_attr)

insert, params = self._sql_expand_insert(attr)
sql = "INSERT INTO ip_net_pool " + insert
sql = "INSERT INTO ip_net_pool " + insert + " RETURNING id"

self._execute(sql, params)
pool_id = self._lastrowid()
pool_id = self._curs_pg.fetchone()[0]
pool = self.list_pool(auth, {'id': pool_id})[0]

# write to audit table
Expand Down Expand Up @@ -2502,10 +2493,10 @@ def add_prefix(self, auth, attr, args=None):
attr['expires'] = _parse_expires(attr['expires'])

insert, params = self._sql_expand_insert(attr)
sql = "INSERT INTO ip_net_plan " + insert
sql = "INSERT INTO ip_net_plan " + insert + " RETURNING id"

self._execute(sql, params)
prefix_id = self._lastrowid()
prefix_id = self._curs_pg.fetchone()[0]
prefix = self.list_prefix(auth, {'id': prefix_id})[0]

# write to audit table
Expand Down
Loading