예제 #1
0
    def subnet_set_description(self, operator, identifier, new_description):
        raise CerebrumError('Description updates are not allowed for the time beeing.')
        self.ba.assert_dns_superuser(operator.get_entity_id())
        
        s = Subnet(self.db)
        try:
            s.find(identifier)
        except SubnetError:
            s = IPv6Subnet(self.db)
            s.find(identifier)

        s.description = new_description
        s.write_db(perform_checks=False)
        subnet_id = "%s/%s" % (s.subnet_ip, s.subnet_mask)
        return "OK; description for subnet %s updated to '%s'" % (subnet_id, new_description)
예제 #2
0
    def subnet_set_description(self, operator, identifier, new_description):
        raise CerebrumError(
            'Description updates are not allowed for the time beeing.')
        self.ba.assert_dns_superuser(operator.get_entity_id())

        s = Subnet(self.db)
        try:
            s.find(identifier)
        except SubnetError:
            s = IPv6Subnet(self.db)
            s.find(identifier)

        s.description = new_description
        s.write_db(perform_checks=False)
        subnet_id = "%s/%s" % (s.subnet_ip, s.subnet_mask)
        return "OK; description for subnet %s updated to '%s'" % (
            subnet_id, new_description)
예제 #3
0
def compare_file_to_db(subnets_in_file, force):
    """Analyzes the info obtained from the files that are to be
    imported, compares to content of database and makes changes were
    needed to bring the database in sync with the datafile.

    TODO: parameter doc.
    
    """
    errors = []
    changes = []
    perform_checks = not force

    s = Subnet(db)
    subnets_in_db = s.search()

    for row in subnets_in_db:
        subnet_ID = "%s/%s" % (row['subnet_ip'], row['subnet_mask'])

        if subnet_ID in subnets_in_file:
            # Subnet is in file; nothing should be done with it
            if row['description'] != subnets_in_file[subnet_ID][1]:
                s.clear()
                s.find(row['entity_id'])
                s.description = subnets_in_file[subnet_ID][1]
                s.write_db(perform_checks=False)
                logger.debug("Updating description of subnet '%s'" % subnet_ID)
                changes.append("Updated description of subnet '%s'" %
                               subnet_ID)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet_ID +
                             "no description update")
            del subnets_in_file[subnet_ID]
        else:
            # Subnet is in DB, but not in file; try to remove it from DB
            try:
                logger.info("Deleting subnet '%s'" % subnet_ID)
                s.clear()
                s.find(subnet_ID)
                description = s.description
                s.delete(perform_checks=perform_checks)
                changes.append("Deleted subnet '%s' (%s)" %
                               (subnet_ID, description))
            except CerebrumError, ce:
                logger.error(str(ce))
                errors.append(str(ce))
예제 #4
0
def compare_file_to_db(subnets_in_file, force):
    """Analyzes the info obtained from the files that are to be
    imported, compares to content of database and makes changes were
    needed to bring the database in sync with the datafile.

    TODO: parameter doc.
    
    """
    errors = []
    changes = []
    perform_checks = not force
        
    s = Subnet(db)
    subnets_in_db = s.search()
    
    for row in subnets_in_db:
        subnet_ID = "%s/%s" % (row['subnet_ip'], row['subnet_mask'])

        if subnet_ID in subnets_in_file:
            # Subnet is in file; nothing should be done with it
            if row['description'] != subnets_in_file[subnet_ID][1]:
                s.clear()
                s.find(row['entity_id'])
                s.description = subnets_in_file[subnet_ID][1]
                s.write_db(perform_checks=False)
                logger.debug("Updating description of subnet '%s'" % subnet_ID)
                changes.append("Updated description of subnet '%s'" %subnet_ID)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet_ID +
                                "no description update")
            del subnets_in_file[subnet_ID]
        else:
            # Subnet is in DB, but not in file; try to remove it from DB
            try:
                logger.info("Deleting subnet '%s'" % subnet_ID)
                s.clear()
                s.find(subnet_ID)
                description = s.description
                s.delete(perform_checks=perform_checks)
                changes.append("Deleted subnet '%s' (%s)" % (subnet_ID,
                                                                description))
            except CerebrumError, ce:
                logger.error(str(ce))
                errors.append(str(ce))
예제 #5
0
def compare_file_to_db(subnets_in_file, force):
    """Analyzes the info obtained from the files that are to be
    imported, compares to content of database and makes changes were
    needed to bring the database in sync with the datafile.

    TODO: parameter doc.
    """
    errors = []
    changes = []
    perform_checks = not force
    s = Subnet(db)
    subnets_in_db = s.search()
    for row in subnets_in_db:
        subnet = "%s/%s" % (row['subnet_ip'], row['subnet_mask'])

        if subnet in subnets_in_file:
            (description, vlan) = subnets_in_file[subnet]
            # Subnet is in file. Check if description or vlan have changed
            if row['description'] != description:
                s.clear()
                s.find(row['entity_id'])
                s.description = description
                s.write_db(perform_checks=False)
                logger.debug("Updating description of subnet '%s'" % subnet)
                changes.append("Updated description of subnet '%s'" % subnet)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet +
                             "no description update")
            if vlan and row['vlan_number'] != vlan:
                s.clear()
                s.find(row['entity_id'])
                s.vlan_number = vlan
                s.write_db(perform_checks=False)
                logger.debug("Updating vlan for subnet '%s'" % subnet)
                changes.append("Updated vlan for subnet '%s'" % subnet)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet +
                             "no vlan update")
            del subnets_in_file[subnet]
        else:
            # Subnet is in DB, but not in file; try to remove it from DB
            try:
                logger.info("Deleting subnet '%s'" % subnet)
                s.clear()
                s.find(subnet)
                description = s.description
                s.delete(perform_checks=perform_checks)
                changes.append("Deleted subnet '%s' (%s)" % (subnet,
                                                             description))
            except CerebrumError as ce:
                logger.error(str(ce))
                errors.append(str(ce))

    # What is left in subnets_in_file now are subnets that should be added
    for subnet in subnets_in_file:
        try:
            description, vlan = subnets_in_file[subnet]
            logger.info("Adding subnet '%s' (%s)" % (subnet, description))
            add_subnet(subnet, description, vlan,
                       perform_checks=perform_checks)
            changes.append("Added subnet '%s' (%s)" % (subnet, description))
        except CerebrumError as ce:
            logger.error(str(ce))
            errors.append(str(ce))

    return changes, errors
예제 #6
0
def compare_file_to_db(subnets_in_file, force):
    """Analyzes the info obtained from the files that are to be
    imported, compares to content of database and makes changes were
    needed to bring the database in sync with the datafile.

    TODO: parameter doc.
    """
    errors = []
    changes = []
    perform_checks = not force
    s = Subnet(db)
    subnets_in_db = s.search()
    for row in subnets_in_db:
        subnet = "%s/%s" % (row['subnet_ip'], row['subnet_mask'])

        if subnet in subnets_in_file:
            (description, vlan) = subnets_in_file[subnet]
            # Subnet is in file. Check if description or vlan have changed
            if row['description'] != description:
                s.clear()
                s.find(row['entity_id'])
                s.description = description
                s.write_db(perform_checks=False)
                logger.debug("Updating description of subnet '%s'" % subnet)
                changes.append("Updated description of subnet '%s'" % subnet)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet +
                             "no description update")
            if vlan and row['vlan_number'] != vlan:
                s.clear()
                s.find(row['entity_id'])
                s.vlan_number = vlan
                s.write_db(perform_checks=False)
                logger.debug("Updating vlan for subnet '%s'" % subnet)
                changes.append("Updated vlan for subnet '%s'" % subnet)
            else:
                logger.debug("Subnet '%s' in both DB and file; " % subnet +
                             "no vlan update")
            del subnets_in_file[subnet]
        else:
            # Subnet is in DB, but not in file; try to remove it from DB
            try:
                logger.info("Deleting subnet '%s'" % subnet)
                s.clear()
                s.find(subnet)
                description = s.description
                s.delete(perform_checks=perform_checks)
                changes.append("Deleted subnet '%s' (%s)" %
                               (subnet, description))
            except CerebrumError as ce:
                logger.error(str(ce))
                errors.append(str(ce))

    # What is left in subnets_in_file now are subnets that should be added
    for subnet in subnets_in_file:
        try:
            description, vlan = subnets_in_file[subnet]
            logger.info("Adding subnet '%s' (%s)" % (subnet, description))
            add_subnet(subnet,
                       description,
                       vlan,
                       perform_checks=perform_checks)
            changes.append("Added subnet '%s' (%s)" % (subnet, description))
        except CerebrumError as ce:
            logger.error(str(ce))
            errors.append(str(ce))

    return changes, errors