Add a new VRF.

            * `auth` [BaseAuth]
                AAA options.
            * `attr` [vrf_attr]
                The news VRF's attributes.

            Add a VRF based on the values stored in the `attr` dict.

            Returns a dict describing the VRF which was added.

            This is the documentation of the internal backend function. It's
            exposed over XML-RPC, please also see the XML-RPC documentation for
            :py:func:`nipap.xmlrpc.NipapXMLRPC.add_vrf` for full understanding.

def add_vrf(self, auth, attr):
        """ Add a new VRF.

            * `auth` [BaseAuth]
                AAA options.
            * `attr` [vrf_attr]
                The news VRF's attributes.

            Add a VRF based on the values stored in the `attr` dict.

            Returns a dict describing the VRF which was added.

            This is the documentation of the internal backend function. It's
            exposed over XML-RPC, please also see the XML-RPC documentation for
            :py:func:`nipap.xmlrpc.NipapXMLRPC.add_vrf` for full understanding.
        """

        self._logger.debug("add_vrf called; attr: %s" % unicode(attr))

        # sanity check - do we have all attributes?
        req_attr = [ 'rt', 'name' ]
        self._check_attr(attr, req_attr, _vrf_attrs)

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

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

        # write to audit table
        audit_params = {
            'vrf_id': vrf['id'],
            'vrf_rt': vrf['rt'],
            'vrf_name': vrf['name'],
            'username': auth.username,
            'authenticated_as': auth.authenticated_as,
            'full_name': auth.full_name,
            'authoritative_source': auth.authoritative_source,
            'description': 'Added VRF %s with attr: %s' % (vrf['rt'], unicode(vrf))
        }

        sql, params = self._sql_expand_insert(audit_params)
        self._execute('INSERT INTO ip_net_log %s' % sql, params)

        return vrf