当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.get_by_name_as_list方法代码示例

本文整理汇总了Python中system.models.Configuration.get_by_name_as_list方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_by_name_as_list方法的具体用法?Python Configuration.get_by_name_as_list怎么用?Python Configuration.get_by_name_as_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在system.models.Configuration的用法示例。


在下文中一共展示了Configuration.get_by_name_as_list方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: database_name_evironment_constraint

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
def database_name_evironment_constraint(database_name, environment_name):
    from logical.models import Database
    from system.models import Configuration

    databases = Database.objects.filter(name=database_name)
    if not databases:
        return False

    dev_envs = Configuration.get_by_name_as_list('dev_envs')
    if environment_name in dev_envs:
        return False

    prod_envs = Configuration.get_by_name_as_list('prod_envs')
    return any((
        database.environment.name in prod_envs
        for database in databases))
开发者ID:globocom,项目名称:database-as-a-service,代码行数:18,代码来源:validators.py

示例2: revoke_detail

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
    def revoke_detail(request, id):
        import celery
        from system.models import Configuration
        celery_inpsect = celery.current_app.control.inspect()

        celery_workers = Configuration.get_by_name_as_list('celery_workers',)

        try:
            workers = celery_inpsect.ping().keys()
        except Exception as e:
            LOG.warn("All celery workers are down! {} :(".format(e))
            messages.add_message(request, messages.ERROR,
                                 "Migration can't be revoked because all celery workers are down!",)
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

        if workers and workers != celery_workers:
            LOG.warn("At least one celery worker is down! :(")
            messages.add_message(request, messages.ERROR,
                                 "Migration can't be revoked because at least one celery worker is down!",)
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

        detail = models.DatabaseRegionMigrationDetail.objects.get(id=id)
        if detail.status == detail.WAITING:
            if detail.revoke_maintenance(request):
                messages.add_message(request, messages.SUCCESS,
                                     "Migration revoked!",)
            else:
                messages.add_message(request, messages.ERROR,
                                     "Migration has already started!",)
        else:
            messages.add_message(request, messages.ERROR,
                                 "Migration can't be revoked!",)

        return HttpResponseRedirect(reverse('admin:region_migration_databaseregionmigrationdetail_changelist'))
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:36,代码来源:databaseregionmigrationdetail.py

示例3: databaseinfra_ending

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
def databaseinfra_ending(context={}):
    LOG.info("Notifying DatabaseInfra ending with context %s" % context)
    subject = _("[DBAAS] DatabaseInfra is almost full")
    template = "infra_notification"
    addr_from = Configuration.get_by_name("email_addr_from")
    addr_to = Configuration.get_by_name_as_list("new_user_notify_email")

    context['domain'] = get_domain()

    send_mail_template(subject, template, addr_from, addr_to,
                       fail_silently=False, attachments=None, context=context)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:13,代码来源:email_notifications.py

示例4: revoke_maintenance

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
    def revoke_maintenance(request, id):
        import celery
        from system.models import Configuration
        celery_inpsect = celery.current_app.control.inspect()

        celery_workers = Configuration.get_by_name_as_list('celery_workers',)

        try:
            workers = celery_inpsect.ping().keys()
        except Exception, e:
            LOG.warn("All celery workers are down! {} :(".format(e))
            messages.add_message(request,  messages.ERROR,
                "Maintenance can't be revoked because all celery workers are down!",)
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:16,代码来源:maintenance.py

示例5: notify_new_user_creation

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
def notify_new_user_creation(user=None):
    subject=_("[DBAAS] a new user has just been created: %s" % user.username)
    template="new_user_notification"
    addr_from=Configuration.get_by_name("email_addr_from")
    addr_to=Configuration.get_by_name_as_list("new_user_notify_email")
    context={}
    context['user'] = user
    domain = get_domain()
    context['url'] = domain + reverse('admin:account_team_changelist')
    LOG.debug("user: %s | addr_from: %s | addr_to: %s" % (user, addr_from, addr_to))
    if user and addr_from and addr_to:
        send_mail_template(subject, template, addr_from, addr_to, fail_silently=False, attachments=None, context=context)
    else:
        LOG.warning("could not send email for new user creation")
开发者ID:s2it-globo,项目名称:database-as-a-service,代码行数:16,代码来源:email_notifications.py

示例6: databaseinfra_ending

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
def databaseinfra_ending(plan,environment,used,capacity,percent):
    LOG.info("Notifying DatabaseInfra ending")
    subject=_("[DBAAS] DatabaseInfra is almost full")
    template="infra_notification"
    addr_from=Configuration.get_by_name("email_addr_from")
    addr_to=Configuration.get_by_name_as_list("new_user_notify_email")
    context={}
    context['domain'] = get_domain()
    context['plan'] = plan
    context['environment'] = environment
    context['used'] = used
    context['capacity'] = capacity
    context['percent'] = percent
    send_mail_template(subject, template, addr_from, addr_to, fail_silently=False, attachments=None, context=context)
    
开发者ID:s2it-globo,项目名称:database-as-a-service,代码行数:16,代码来源:email_notifications.py

示例7: make_databases_backup

# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_list [as 别名]
def make_databases_backup(self):
    LOG.info("Making databases backups")
    worker_name = get_worker_name()
    task_history = TaskHistory.register(
        request=self.request, worker_name=worker_name, user=None
    )
    task_history.relevance = TaskHistory.RELEVANCE_ERROR

    waiting_msg = "\nWaiting 5 minutes to start the next backup group"
    status = TaskHistory.STATUS_SUCCESS
    environments = Environment.objects.all()
    prod_envs = Configuration.get_by_name_as_list('prod_envs')
    dev_envs = Configuration.get_by_name_as_list('dev_envs')
    env_names_order = prod_envs + dev_envs
    if not env_names_order:
        env_names_order = [env.name for env in environments]

    infras = DatabaseInfra.objects.filter(plan__has_persistence=True)
    for env_name in env_names_order:
        try:
            env = environments.get(name=env_name)
        except Environment.DoesNotExist:
            continue

        msg = '\nStarting Backup for env {}'.format(env.name)
        task_history.update_details(persist=True, details=msg)
        databaseinfras_by_env = infras.filter(environment=env)
        error = {}
        backup_number = 0
        backups_per_group = len(infras) / 12
        for infra in databaseinfras_by_env:
            if not infra.databases.first():
                continue

            if backups_per_group > 0:
                if backup_number < backups_per_group:
                    backup_number += 1
                else:
                    backup_number = 0
                    task_history.update_details(waiting_msg, True)
                    sleep(300)

            group = BackupGroup()
            group.save()

            for instance in infra.instances.filter(read_only=False):
                try:
                    driver = instance.databaseinfra.get_driver()
                    is_eligible = driver.check_instance_is_eligible_for_backup(
                        instance
                    )
                    if not is_eligible:
                        LOG.info(
                            'Instance {} is not eligible for backup'.format(
                                instance
                            )
                        )
                        continue
                except Exception as e:
                    status = TaskHistory.STATUS_ERROR
                    msg = "Backup for %s was unsuccessful. Error: %s" % (
                        str(instance), str(e))
                    LOG.error(msg)

                time_now = str(strftime("%m/%d/%Y %H:%M:%S"))
                start_msg = "\n{} - Starting backup for {} ...".format(
                    time_now, instance
                )
                task_history.update_details(persist=True, details=start_msg)
                try:
                    snapshot = make_instance_snapshot_backup(
                        instance=instance, error=error, group=group
                    )
                    if snapshot and snapshot.was_successful:
                        msg = "Backup for %s was successful" % (str(instance))
                        LOG.info(msg)
                    elif snapshot and snapshot.has_warning:
                        status = TaskHistory.STATUS_WARNING
                        msg = "Backup for %s has warning" % (str(instance))
                        LOG.info(msg)
                    else:
                        status = TaskHistory.STATUS_ERROR
                        msg = "Backup for %s was unsuccessful. Error: %s" % (
                            str(instance), error['errormsg'])
                        LOG.error(msg)
                    LOG.info(msg)
                except Exception as e:
                    status = TaskHistory.STATUS_ERROR
                    msg = "Backup for %s was unsuccessful. Error: %s" % (
                        str(instance), str(e))
                    LOG.error(msg)

                time_now = str(strftime("%m/%d/%Y %H:%M:%S"))
                msg = "\n{} - {}".format(time_now, msg)
                task_history.update_details(persist=True, details=msg)

    task_history.update_status_for(status, details="\nBackup finished")

    return
开发者ID:globocom,项目名称:database-as-a-service,代码行数:101,代码来源:tasks.py


注:本文中的system.models.Configuration.get_by_name_as_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。