Ejemplo n.º 1
0
    def add_prefix_to_vrf(self, vrfrt, prefix, type, description, status, tags=[]):
        """
        Note: This function adds a prefix to a given VRF, if the prefix is used or
        invalid, it will return None
        :param vrfrt: String like "209:123"
        :param prefix: String like "1.0.0.0/29"
        :param type: String, must be on of the following: 'reservation', 'assignment', 'host'
        :param description: String
        :param status: String, must be "assigned" or "reserved"
        :param tags: Array of Strings
        :return: Prefix object or None
        """
        myvrf = None
        p = None

        # get the vrf
        myvrf = self.find_vrf('rt', vrfrt)
        p = Prefix()
        p.prefix = prefix
        p.type = type
        p.status = status
        p.description = description
        p.vrf = myvrf
        p.tags = tags

        try:
            p.save()
        except:
            e = sys.exc_info()[0]
            logging.error("Error: could not add prefix: %s" % e)
        return p
Ejemplo n.º 2
0
 def add_prefix_from_pool(self, pool, family, description):
     p = Prefix()
     args = {}
     args['from-pool'] = pool
     args['family'] = family
     p.type = pool.default_type
     p.status = 'assigned'
     try:
         p.save(args)
         return p
     except NipapError as exc:
         print("Error: could not add prefix: %s" % str(exc))
         return None