本文整理汇总了Python中system.models.Configuration.get_by_name_as_int方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_by_name_as_int方法的具体用法?Python Configuration.get_by_name_as_int怎么用?Python Configuration.get_by_name_as_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类system.models.Configuration
的用法示例。
在下文中一共展示了Configuration.get_by_name_as_int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __mongo_client__
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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)
示例2: __redis_client__
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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
示例3: metricdetail_view
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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))
示例4: remove_database_old_backups
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def remove_database_old_backups(self):
task_history = TaskHistory.register(request=self.request, user=None)
backup_retention_days = Configuration.get_by_name_as_int('backup_retention_days')
LOG.info("Removing backups older than %s days" % (backup_retention_days))
backup_time_dt = date.today() - timedelta(days=backup_retention_days)
snapshots = Snapshot.objects.filter(start_at__lte=backup_time_dt, purge_at__isnull = True, instance__isnull = False, snapshopt_id__isnull = False)
msgs = []
status = TaskHistory.STATUS_SUCCESS
if len(snapshots) == 0:
msgs.append("There is no snapshot to purge")
for snapshot in snapshots:
try:
remove_snapshot_backup(snapshot=snapshot)
msg = "Backup %s removed" % (snapshot)
LOG.info(msg)
except:
msg = "Error removing backup %s" % (snapshot)
status = TaskHistory.STATUS_ERROR
LOG.error(msg)
msgs.append(msg)
task_history.update_status_for(status, details="\n".join(msgs))
return
示例5: delete_view
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def delete_view(self, request, object_id, extra_context=None):
database = Database.objects.get(id=object_id)
extra_context = extra_context or {}
if database.status != Database.ALIVE or not database.database_status.is_alive:
self.message_user(
request, "Database {} is not alive and cannot be deleted".format(database.name), level=messages.ERROR)
url = reverse('admin:logical_database_changelist')
return HttpResponseRedirect(url)
if database.is_beeing_used_elsewhere():
self.message_user(
request, "Database {} cannot be deleted because it is in use by another task.".format(database.name), level=messages.ERROR)
url = reverse('admin:logical_database_changelist')
return HttpResponseRedirect(url)
if database.has_migration_started():
self.message_user(
request, "Database {} cannot be deleted because it is beeing migrated.".format(database.name), level=messages.ERROR)
url = reverse('admin:logical_database_changelist')
return HttpResponseRedirect(url)
if not database.is_in_quarantine:
extra_context['quarantine_days'] = Configuration.get_by_name_as_int(
'quarantine_retention_days')
return super(DatabaseAdmin, self).delete_view(request, object_id, extra_context=extra_context)
示例6: purge_task_history
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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)
示例7: get_sentinel_client
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def get_sentinel_client(self, instance=None):
connection_timeout_in_seconds = Configuration.get_by_name_as_int(
'redis_connect_timeout', default=REDIS_CONNECTION_DEFAULT_TIMEOUT)
sentinels = self.__get_admin_sentinel_connection(instance)
sentinel = Sentinel(
sentinels, socket_timeout=connection_timeout_in_seconds)
return sentinel
示例8: databaseinfra_notification
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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
示例9: user_m2m_changed
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
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)
示例10: purge_quarantine
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def purge_quarantine(self):
quarantine_time = Configuration.get_by_name_as_int('quarantine_retention_days')
quarantine_time_dt = date.today() - timedelta(days=quarantine_time)
databases = Database.objects.filter(is_in_quarantine=True, quarantine_dt__lte=quarantine_time_dt)
for database in databases:
database.delete()
LOG.info("The database %s was deleted, because it was set to quarentine %d days ago" % (
database.name, quarantine_time))
示例11: changelist_view
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def changelist_view(self, request, extra_context=None):
extra_context = extra_context or {}
backup_avaliable = Configuration.get_by_name_as_int(
'backup_avaliable')
extra_context['backup_avaliable'] = False
if backup_avaliable:
extra_context['backup_avaliable'] = True
return super(SnapshotAdmin, self).changelist_view(request, extra_context=extra_context)
示例12: get_dex_url
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def get_dex_url(self):
if Configuration.get_by_name_as_int('dex_analyze') != 1:
return ""
if self.databaseinfra.plan.provider == Plan.PREPROVISIONED:
return ""
if self.engine_type != 'mongodb':
return ""
return 1
示例13: get_dex_url
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def get_dex_url(self):
if Configuration.get_by_name_as_int('dex_analyze') != 1:
return ""
if self.databaseinfra.plan.is_pre_provisioned:
return ""
if self.engine_type != 'mongodb':
return ""
return 1
示例14: __mongo_client__
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def __mongo_client__(self, instance):
connection_address = self.__get_admin_connection(instance)
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
client = pymongo.MongoClient(connection_address, connectTimeoutMS=connection_timeout_in_miliseconds)
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)
示例15: databaseinfra_notification
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name_as_int [as 别名]
def databaseinfra_notification():
# Sum capacity per databseinfra with parameter plan, environment and engine
infras = DatabaseInfra.objects.values('plan__name', 'environment__name', 'engine__engine_type__name').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 >= Configuration.get_by_name_as_int("threshold_infra_notification", default=50):
LOG.info('Plan %s in environment %s with %s%% occupied' % (infra['plan__name'], infra['environment__name'],percent))
LOG.info("Sending notification...")
email_notifications.databaseinfra_ending(infra['plan__name'], infra['environment__name'], used['used'],infra['capacity'],percent)
return