예제 #1
0
def database_pre_save(sender, **kwargs):
    database = kwargs.get('instance')
    if database.is_in_quarantine:
        if database.quarantine_dt is None:
            database.quarantine_dt = datetime.datetime.now().date()

        if not database.quarantine_user:
            from dbaas.middleware import UserMiddleware
            database.quarantine_user = UserMiddleware.current_user()
    else:
        database.quarantine_dt = None
        database.quarantine_user = None

    if database.id:
        saved_object = Database.objects.get(id=database.id)
        if database.name != saved_object.name:
            raise AttributeError(_("Attribute name cannot be edited"))
    else:
        # new database
        if database_name_evironment_constraint(database.name,
                                               database.environment.name):
            raise AttributeError(
                _('%s already exists in production!') % database.name)

        LOG.debug("slugfying database's name for %s" % database.name)
        database.name = slugify(database.name)
예제 #2
0
def database_pre_save(sender, **kwargs):
    from notification.tasks import TaskRegister

    database = kwargs.get('instance')
    if database.is_in_quarantine:
        if database.quarantine_dt is None:
            database.quarantine_dt = datetime.datetime.now().date()

        if not database.quarantine_user:
            from dbaas.middleware import UserMiddleware
            database.quarantine_user = UserMiddleware.current_user()
    else:
        database.quarantine_dt = None
        database.quarantine_user = None

    if database.id:
        saved_object = Database.objects.get(id=database.id)
        if database.name != saved_object.name:
            raise AttributeError(_("Attribute name cannot be edited"))

        if database.team and saved_object.team:
            if database.team.organization != saved_object.team.organization:
                TaskRegister.update_organization_name_monitoring(
                    database=database,
                    organization_name=database.team.organization.name)
                if saved_object.team.external:
                    TaskRegister.update_database_monitoring(
                        database=database,
                        hostgroup=(saved_object.team.organization
                                   .grafana_hostgroup),
                        action='remove')
                if database.team.external:
                    TaskRegister.update_database_monitoring(
                        database=database,
                        hostgroup=database.team.organization.grafana_hostgroup,
                        action='add')

    else:
        # new database
        if database_name_evironment_constraint(
           database.name, database.environment.name):
            raise AttributeError(
                _('%s already exists in production!') % database.name
            )

        LOG.debug("slugfying database's name for %s" % database.name)
        database.name = slugify(database.name)
예제 #3
0
def database_pre_save(sender, **kwargs):
    from notification.tasks import TaskRegister

    database = kwargs.get('instance')
    if database.is_in_quarantine:
        if database.quarantine_dt is None:
            database.quarantine_dt = datetime.datetime.now().date()

        if not database.quarantine_user:
            from dbaas.middleware import UserMiddleware
            database.quarantine_user = UserMiddleware.current_user()
    else:
        database.quarantine_dt = None
        database.quarantine_user = None

    if database.id:
        saved_object = Database.objects.get(id=database.id)
        if database.name != saved_object.name:
            raise AttributeError(_("Attribute name cannot be edited"))

        if database.team and saved_object.team:
            if database.team.organization != saved_object.team.organization:
                TaskRegister.update_organization_name_monitoring(
                    database=database,
                    organization_name=database.team.organization.name)
                if saved_object.team.external:
                    TaskRegister.update_database_monitoring(
                        database=database,
                        hostgroup=saved_object.team.organization.grafana_hostgroup,
                        action='remove')
                if database.team.external:
                    TaskRegister.update_database_monitoring(
                        database=database,
                        hostgroup=database.team.organization.grafana_hostgroup,
                        action='add')

    else:
        # new database
        if database_name_evironment_constraint(
           database.name, database.environment.name):
            raise AttributeError(
                _('%s already exists in production!') % database.name
            )

        LOG.debug("slugfying database's name for %s" % database.name)
        database.name = slugify(database.name)