本文整理汇总了Python中system.models.Configuration.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_by_name方法的具体用法?Python Configuration.get_by_name怎么用?Python Configuration.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类system.models.Configuration
的用法示例。
在下文中一共展示了Configuration.get_by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: database_usage
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
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)
示例2: get_clone_args
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
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
示例3: do
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
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
示例4: database_analyzing
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def database_analyzing(context={}):
LOG.info("Notifying Database alayzing with context %s" % context)
subject = _("[DBAAS] Database overestimated")
template = "analyzing_notification"
addr_from = Configuration.get_by_name("email_addr_from")
send_email = Configuration.get_by_name("send_analysis_email")
team = context.get("team")
if team and team.email and send_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)
示例5: databaseinfra_ending
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [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)
示例6: external_links
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def external_links(request):
iaas_status = Configuration.get_by_name('iaas_status')
iaas_quota = Configuration.get_by_name('iaas_quota')
try:
credential = get_credentials_for(
environment=Environment.objects.first(),
credential_type=CredentialType.GRAFANA
)
sofia_dashboard = "{}/{}?var-datasource={}".format(
credential.endpoint,
credential.get_parameter_by_name('sofia_dbaas_dashboard'),
credential.get_parameter_by_name('datasource')
)
except IndexError:
sofia_dashboard = ""
return {'iaas_status': iaas_status,
'iaas_quota': iaas_quota,
'sofia_main_dashboard': sofia_dashboard}
示例7: get_configuration
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def get_configuration(context, configuration_name, context_var_name):
"""
Usage: {% get_configuration config_name context_var %}
Search config name on system configuration and set context_var on
page context
"""
config_val = Configuration.get_by_name(configuration_name) or ''
context[context_var_name] = config_val
return ''
示例8: notify_new_user_creation
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [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")
示例9: __mysql_client__
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def __mysql_client__(self, instance, database='mysql'):
connection_address, connection_port = self.__get_admin_connection(instance)
try:
LOG.debug('Connecting to mysql databaseinfra %s', self.databaseinfra)
# mysql uses timeout in seconds
connection_timeout_in_seconds = int(Configuration.get_by_name('mysql_connect_timeout') or 5)
client = mysqldb.connect(host=connection_address, port=int(connection_port),
user=self.databaseinfra.user, passwd=self.databaseinfra.password,
db=database, connect_timeout=connection_timeout_in_seconds)
LOG.debug('Successfully connected to mysql databaseinfra %s' % (self.databaseinfra))
return client
except Exception, e:
raise e
示例10: databaseinfra_ending
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [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)
示例11: notify_team_change_for
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def notify_team_change_for(user=None):
LOG.info("Notifying team change for user %s" % user)
subject=_("[DBAAS] your team has been updated!")
template="team_change_notification"
addr_from=Configuration.get_by_name("email_addr_from")
if user.email:
#addr_to=Configuration.get_by_name_as_list("new_user_notify_email") + [user.email]
addr_to=[user.email]
context={}
context['user'] = user
domain = get_domain()
context['url'] = domain
context['teams'] = [team.name for team in user.team_set.all()]
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 team change")
else:
LOG.warning("user %s has no email set and therefore cannot be notified!")
示例12: cluster_command
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def cluster_command(self):
return Configuration.get_by_name('redis_trib_path')
示例13: do
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def do(self, workflow_dict):
try:
region_migration_dir = Configuration.get_by_name('region_migration_dir')
if not region_migration_dir:
region_migration_dir = '/tmp'
workflow_dict['region_migration_dir_infra_name'] = "{}/{}".format(region_migration_dir, workflow_dict['databaseinfra'].name)
for index, source_instance in enumerate(workflow_dict['source_instances']):
source_host = source_instance.hostname
source_cs_host_attr = CS_HostAttr.objects.get(host=source_host)
hostname = source_host.hostname.split('.')[0]
localpath = "{}/{}".format(workflow_dict['region_migration_dir_infra_name'], hostname)
os.makedirs(localpath)
LOG.info('Get source host files to {}'.format(localpath))
if not scp_get_file(server=source_host.address,
username=source_cs_host_attr.vm_user,
password=source_cs_host_attr.vm_password,
localpath="{}/mongodb.key".format(localpath),
remotepath="/data/mongodb.key"):
raise Exception("FTP Error")
if not scp_get_file(server=source_host.address,
username=source_cs_host_attr.vm_user,
password=source_cs_host_attr.vm_password,
localpath="{}/mongodb.conf".format(localpath),
remotepath="/data/mongodb.conf"):
raise Exception("FTP Error")
if not scp_get_file(server=source_host.address,
username=source_cs_host_attr.vm_user,
password=source_cs_host_attr.vm_password,
localpath="{}/td-agent.conf".format(localpath),
remotepath="/etc/td-agent/td-agent.conf"):
raise Exception("FTP Error")
target_host = source_host.future_host
LOG.info(target_host)
target_cs_host_attr = CS_HostAttr.objects.get(host=target_host)
target_instance = source_instance.future_instance
if target_instance.instance_type == target_instance.MONGODB_ARBITER:
LOG.info("Cheking host ssh...")
host_ready = check_ssh(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
wait=5, interval=10)
if not host_ready:
raise Exception(str("Host %s is not ready..." % target_host))
if not scp_put_file(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
localpath="{}/mongodb.key".format(localpath),
remotepath="/data/mongodb.key"):
raise Exception("FTP Error")
if not scp_put_file(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
localpath="{}/mongodb.conf".format(localpath),
remotepath="/data/mongodb.conf"):
raise Exception("FTP Error")
if not scp_put_file(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
localpath="{}/td-agent.conf".format(localpath),
remotepath="/etc/td-agent/td-agent.conf"):
raise Exception("FTP Error")
script = test_bash_script_error()
script += build_permission_script()
script += build_start_database_script()
script = build_context_script({}, script)
output = {}
LOG.info(script)
return_code = exec_remote_command(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
raise Exception(str(output))
shutil.rmtree(workflow_dict['region_migration_dir_infra_name'])
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
#.........这里部分代码省略.........
示例14: do
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
def do(self, workflow_dict):
try:
initial_script = '#!/bin/bash\n\ndie_if_error()\n{\n local err=$?\n if [ "$err" != "0" ]; then\n echo "$*"\n exit $err\n fi\n}'
region_migration_dir = Configuration.get_by_name('region_migration_dir')
if not region_migration_dir:
region_migration_dir = '/tmp'
workflow_dict['region_migration_dir_infra_name'] = "{}/{}".format(region_migration_dir, workflow_dict['databaseinfra'].name)
for index, source_instance in enumerate(workflow_dict['source_instances']):
source_host = source_instance.hostname
source_cs_host_attr = CS_HostAttr.objects.get(host = source_host)
hostname = source_host.hostname.split('.')[0]
localpath = "{}/{}".format(workflow_dict['region_migration_dir_infra_name'], hostname)
os.makedirs(localpath)
LOG.info('Get source host files to {}'.format(localpath))
if not scp_get_file(server = source_host.address,
username = source_cs_host_attr.vm_user,
password = source_cs_host_attr.vm_password,
localpath = "{}/mongodb.key".format(localpath),
remotepath = "/data/mongodb.key"):
raise Exception("FTP Error")
if not scp_get_file(server = source_host.address,
username = source_cs_host_attr.vm_user,
password = source_cs_host_attr.vm_password,
localpath = "{}/mongodb.conf".format(localpath),
remotepath = "/data/mongodb.conf"):
raise Exception("FTP Error")
if not scp_get_file(server = source_host.address,
username = source_cs_host_attr.vm_user,
password = source_cs_host_attr.vm_password,
localpath = "{}/td-agent.conf".format(localpath),
remotepath = "/etc/td-agent/td-agent.conf"):
raise Exception("FTP Error")
target_host = source_host.future_host
LOG.info(target_host)
target_cs_host_attr = CS_HostAttr.objects.get(host = target_host)
if not scp_put_file(server = target_host.address,
username = target_cs_host_attr.vm_user,
password = target_cs_host_attr.vm_password,
localpath = "{}/mongodb.key".format(localpath),
remotepath = "/data/mongodb.key"):
raise Exception("FTP Error")
if not scp_put_file(server = target_host.address,
username = target_cs_host_attr.vm_user,
password = target_cs_host_attr.vm_password,
localpath = "{}/mongodb.conf".format(localpath),
remotepath = "/data/mongodb.conf"):
raise Exception("FTP Error")
if not scp_put_file(server = target_host.address,
username = target_cs_host_attr.vm_user,
password = target_cs_host_attr.vm_password,
localpath = "{}/td-agent.conf".format(localpath),
remotepath = "/etc/td-agent/td-agent.conf"):
raise Exception("FTP Error")
script = initial_script
script += '\nmkdir /data/data'
script += '\ndie_if_error "Error creating data dir"'
script += '\nchown mongodb:mongodb /data'
script += '\ndie_if_error "Error changing datadir permission"'
script += '\nchown -R mongodb:mongodb /data/*'
script += '\ndie_if_error "Error changing datadir permission"'
script += '\nchmod 600 /data/mongodb.key'
script += '\ndie_if_error "Error changing mongodb key file permission"'
script += '\necho ""; echo $(date "+%Y-%m-%d %T") "- Starting the database"'
script += '\n/etc/init.d/mongodb start > /dev/null'
script += '\ndie_if_error "Error starting database"'
script = build_context_script({}, script)
output = {}
LOG.info(script)
return_code = exec_remote_command(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
raise Exception, str(output)
shutil.rmtree(workflow_dict['region_migration_dir_infra_name'])
return True
except Exception:
traceback = full_stack()
#.........这里部分代码省略.........
示例15: generate_random_string
# 需要导入模块: from system.models import Configuration [as 别名]
# 或者: from system.models.Configuration import get_by_name [as 别名]
parsed_logs = ''
database_logs = provider.get_logs_for_group(environment, lognit_environment, uri)
try:
database_logs = json.loads(database_logs)
except Exception, e:
pass
else:
for database_log in database_logs:
try:
items = database_log['items']
except KeyError, e:
pass
else:
parsed_logs = "\n".join((item['message'] for item in items))
arq_path = Configuration.get_by_name('database_clone_dir') + '/' + database.name + generate_random_string(20) + '.txt'
arq = open(arq_path,'w')
arq.write(parsed_logs)
arq.close()
uri = 'mongodb://{}:{}@{}:{}/admin'.format(database.databaseinfra.user,
database.databaseinfra.password,
database.databaseinfra.instances.all()[
0].address,
database.databaseinfra.instances.all()[0].port)
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
md = dex.Dex(db_uri=uri, verbose=False, namespaces_list=[],