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


Python models.Configuration类代码示例

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


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

示例1: __mongo_client__

    def __mongo_client__(self, instance):
        connection_address = self.__get_admin_connection(instance)
        if not self.databaseinfra and instance:
            self.databaseinfra = instance.databaseinfra
        try:
            # mongo uses timeout in mili seconds
            connection_timeout_in_miliseconds = Configuration.get_by_name_as_int(
                'mongo_connect_timeout', default=MONGO_CONNECTION_DEFAULT_TIMEOUT) * 1000
            
            server_selection_timeout_in_seconds = Configuration.get_by_name_as_int(
                'mongo_server_selection_timeout', default=MONGO_SERVER_SELECTION_DEFAULT_TIMEOUT) * 1000

            socket_timeout_in_miliseconds = Configuration.get_by_name_as_int(
                'mongo_socket_timeout', default=MONGO_SOCKET_TIMEOUT) * 1000

            client = pymongo.MongoClient(
                connection_address, connectTimeoutMS=connection_timeout_in_miliseconds, serverSelectionTimeoutMS=server_selection_timeout_in_seconds,
                 socketTimeoutMS=socket_timeout_in_miliseconds)
            if (not instance) or (instance and instance.instance_type != instance.MONGODB_ARBITER):
                if self.databaseinfra.user and self.databaseinfra.password:
                    LOG.debug('Authenticating databaseinfra %s',
                              self.databaseinfra)
                    client.admin.authenticate(self.databaseinfra.user,
                                              self.databaseinfra.password)
            return client
        except TypeError:
            raise AuthenticationError(
                message='Invalid address: ' % connection_address)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:28,代码来源:mongodb.py

示例2: databaseinfra_ending

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,代码行数:11,代码来源:email_notifications.py

示例3: notify_new_user_creation

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,代码行数:14,代码来源:email_notifications.py

示例4: MakeDatabaseBackup

class MakeDatabaseBackup(TestCase):

    def setUp(self):
        cache.clear()

        self.admin = SnapshotAdmin(Snapshot, admin.sites.AdminSite())
        self.param_backup_available = Configuration(
            name='backup_available', value=1
        )
        self.param_backup_available.save()

    def tearDown(self):
        if self.param_backup_available.id:
            self.param_backup_available.delete()

    def test_is_backup_available(self):
        self.assertTrue(self.admin.is_backup_available)

    def test_is_backup_disable(self):
        self.param_backup_available.value = 0
        self.param_backup_available.save()
        self.assertFalse(self.admin.is_backup_available)

    def test_is_backup_disable_not_configured(self):
        self.param_backup_available.delete()
        self.assertFalse(self.admin.is_backup_available)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:26,代码来源:tests.py

示例5: databaseinfra_ending

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,代码行数:14,代码来源:email_notifications.py

示例6: revoke_detail

    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,代码行数:34,代码来源:databaseregionmigrationdetail.py

示例7: do

    def do(self, workflow_dict):
        try:

            if 'databaseinfra' not in workflow_dict \
                or 'clone' not in workflow_dict :
                return False

            args = get_clone_args(workflow_dict['clone'], workflow_dict['database'])
            script_name = factory_for(workflow_dict['clone'].databaseinfra).clone()

            python_bin= Configuration.get_by_name('python_venv_bin')

            return_code, output = call_script(script_name, working_dir=settings.SCRIPTS_PATH
                , args=args, split_lines=False, python_bin=python_bin)

            LOG.info("Script Output: {}".format(output))
            LOG.info("Return code: {}".format(return_code))

            if return_code != 0:
                workflow_dict['exceptions']['traceback'].append(output)
                return False

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0017)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:30,代码来源:clone_database.py

示例8: user_m2m_changed

def user_m2m_changed(sender, **kwargs):
    team = kwargs.get('instance')
    action = kwargs.get('action')
    if action == 'post_add':
        from util.laas import register_team_laas
        if Configuration.get_by_name_as_int('laas_integration') == 1:
            register_team_laas(team)
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:7,代码来源:models.py

示例9: __redis_client__

    def __redis_client__(self, instance):

        try:
            LOG.debug(
                'Connecting to redis databaseinfra %s', self.databaseinfra)
            # redis uses timeout in seconds
            connection_timeout_in_seconds = Configuration.get_by_name_as_int(
                'redis_connect_timeout', default=REDIS_CONNECTION_DEFAULT_TIMEOUT)

            if (instance and instance.instance_type == Instance.REDIS) or (not self.databaseinfra.plan.is_ha and not instance):
                connection_address, connection_port = self.__get_admin_single_connection(
                    instance)
                client = redis.Redis(host=connection_address,
                                     port=int(connection_port),
                                     password=self.databaseinfra.password,
                                     socket_connect_timeout=connection_timeout_in_seconds)

            else:
                sentinel = self.get_sentinel_client(instance)
                client = sentinel.master_for(self.databaseinfra.name,
                                             socket_timeout=connection_timeout_in_seconds,
                                             password=self.databaseinfra.password)

            LOG.debug(
                'Successfully connected to redis databaseinfra %s' % (self.databaseinfra))
            return client
        except Exception, e:
            raise e
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:28,代码来源:redis.py

示例10: get_clone_args

def get_clone_args(origin_database, dest_database):
    
    #origin
    origin_instance=origin_database.databaseinfra.instances.all()[0]
    
    db_orig=origin_database.name
    user_orig=origin_database.databaseinfra.user
    #pass_orig="PASSWORD_ORIGIN=%s" % origin_database.databaseinfra.password
    pass_orig=origin_database.databaseinfra.password
    host_orig=origin_instance.address
    port_orig=origin_instance.port
    
    #destination
    dest_instance=dest_database.databaseinfra.instances.all()[0]
    
    db_dest=dest_database.name
    user_dest=dest_database.databaseinfra.user
    #pass_dest="PASSWORD_DEST=%s" % dest_database.databaseinfra.password
    pass_dest=dest_database.databaseinfra.password
    host_dest=dest_instance.address
    port_dest=dest_instance.port
    
    path_of_dump=Configuration.get_by_name('database_clone_dir')
    
    args=[db_orig, user_orig, pass_orig, host_orig, str(int(port_orig)), 
            db_dest, user_dest, pass_dest, host_dest, str(int(port_dest)), 
            path_of_dump
    ]
    
    return args
开发者ID:Milstein,项目名称:database-as-a-service,代码行数:30,代码来源:util.py

示例11: purge_task_history

def purge_task_history(self):
    try:
        worker_name = get_worker_name()
        task_history = TaskHistory.register(request=self.request, user=None, worker_name=worker_name)

        now = datetime.datetime.now()
        retention_days = Configuration.get_by_name_as_int('task_history_retention_days')

        n_days_before = now - datetime.timedelta(days=retention_days)

        tasks_to_purge = TaskHistory.objects.filter(task_name__in=['notification.tasks.database_notification',
                'notification.tasks.database_notification_for_team',
                'notification.tasks.update_database_status',
                'notification.tasks.update_database_used_size',
                'notification.tasks.update_instances_status',
                'system.tasks.set_celery_healthcheck_last_update']
        , ended_at__lt=n_days_before
        , task_status__in=["SUCCESS", "ERROR"])

        tasks_to_purge.delete()

        task_history.update_status_for(TaskHistory.STATUS_SUCCESS,
            details='Purge succesfully done!')
    except Exception, e:
        task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:25,代码来源:tasks.py

示例12: databaseinfra_notification

def databaseinfra_notification(self, user=None):
	task_history = TaskHistory.register(request=self.request, user=user)
	threshold_infra_notification = Configuration.get_by_name_as_int("threshold_infra_notification", default=0)
	if threshold_infra_notification <= 0:
		LOG.warning("database infra notification is disabled")
		return

	# Sum capacity per databseinfra with parameter plan, environment and engine
	infras = DatabaseInfra.objects.values('plan__name', 'environment__name', 'engine__engine_type__name',
	                                      'plan__provider').annotate(capacity=Sum('capacity'))
	for infra in infras:
		# total database created in databaseinfra per plan, environment and engine
		used = DatabaseInfra.objects.filter(plan__name=infra['plan__name'],
		                                    environment__name=infra['environment__name'],
		                                    engine__engine_type__name=infra['engine__engine_type__name']).aggregate(
			used=Count('databases'))
		# calculate the percentage
		percent = int(used['used'] * 100 / infra['capacity'])
		if percent >= threshold_infra_notification and infra['plan__provider'] != Plan.CLOUDSTACK:
			LOG.info('Plan %s in environment %s with %s%% occupied' % (
				infra['plan__name'], infra['environment__name'], percent))
			LOG.info("Sending database infra notification...")
			context = {}
			context['plan'] = infra['plan__name']
			context['environment'] = infra['environment__name']
			context['used'] = used['used']
			context['capacity'] = infra['capacity']
			context['percent'] = percent
			email_notifications.databaseinfra_ending(context=context)

		task_history.update_status_for(TaskHistory.STATUS_SUCCESS,
		                               details='Databaseinfra Notification successfully sent to dbaas admins!')
	return
开发者ID:whoishu,项目名称:database-as-a-service,代码行数:33,代码来源:tasks.py

示例13: database_name_evironment_constraint

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,代码行数:16,代码来源:validators.py

示例14: metricdetail_view

    def metricdetail_view(self, request, database_id):
        from util.metrics.metrics import get_metric_datapoints_for

        hostname = request.GET.get('hostname')
        metricname = request.GET.get('metricname')

        database = Database.objects.get(id=database_id)
        engine = database.infra.engine_name
        db_name = database.name
        URL = get_credentials_for(
            environment=database.environment, credential_type=CredentialType.GRAPHITE).endpoint

        from_option = request.POST.get('change_from') or '2hours'
        granurality = self.get_granurality(from_option) or '20minutes'

        from_options = self.build_select_options(
            from_option, self.get_from_options())

        graph_data = get_metric_datapoints_for(engine, db_name, hostname,
                                               url=URL, metric_name=metricname,
                                               granurality=granurality,
                                               from_option=from_option)

        title = "{} {} Metric".format(
            database.name, graph_data[0]["graph_name"])

        show_filters = Configuration.get_by_name_as_int('metric_filters')
        if graph_data[0]['normalize_series'] == True:
            show_filters = False

        return render_to_response("logical/database/metrics/metricdetail.html", locals(), context_instance=RequestContext(request))
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:31,代码来源:database.py

示例15: database_usage

def database_usage(context={}):
    LOG.info("Notifying Database usage with context %s" % context)
    subject = _("[DBAAS] Database is almost full")
    template = "database_notification"
    addr_from = Configuration.get_by_name("email_addr_from")
    team = context.get("team")
    if team and team.email:
        addr_to = [
            team.email, Configuration.get_by_name("new_user_notify_email")]
    else:
        addr_to = Configuration.get_by_name("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:flaviohenriqu,项目名称:database-as-a-service,代码行数:16,代码来源:email_notifications.py


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