本文整理汇总了Python中util.get_credentials_for函数的典型用法代码示例。如果您正苦于以下问题:Python get_credentials_for函数的具体用法?Python get_credentials_for怎么用?Python get_credentials_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_credentials_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
if 'databaseinfra' not in workflow_dict and 'hosts' not in workflow_dict:
LOG.info("We could not find a databaseinfra inside the workflow_dict")
return False
if len(workflow_dict['hosts']) == 1:
return True
databaseinfraattr = DatabaseInfraAttr.objects.filter(
databaseinfra=workflow_dict['databaseinfra'])
cs_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.CLOUDSTACK)
networkapi_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.NETWORKAPI)
cs_provider = CloudStackProvider(credentials=cs_credentials,
networkapi_credentials=networkapi_credentials)
networkapi_equipment_id = workflow_dict.get('networkapi_equipment_id')
for infra_attr in databaseinfraattr:
networkapi_equipment_id = infra_attr.networkapi_equipment_id
networkapi_ip_id = infra_attr.networkapi_ip_id
if networkapi_ip_id:
LOG.info("Removing network api IP for %s" % networkapi_ip_id)
if not cs_provider.remove_networkapi_ip(equipment_id=networkapi_equipment_id,
ip_id=networkapi_ip_id):
return False
LOG.info("Removing secondary_ip for %s" % infra_attr.cs_ip_id)
if not cs_provider.remove_secondary_ips(infra_attr.cs_ip_id):
return False
LOG.info("Secondary ip deleted!")
infra_attr.delete()
LOG.info("Databaseinfraattr deleted!")
if networkapi_equipment_id:
cs_provider.remove_networkapi_equipment(equipment_id=networkapi_equipment_id)
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0010)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例2: __init__
def __init__(self, instance):
super(FoxHA, self).__init__(instance)
self.mysql_fox_credentials = get_credentials_for(
self.environment, CredentialType.MYSQL_FOXHA
)
self.mysql_replica_credentials = get_credentials_for(
self.environment, CredentialType.MYSQL_REPLICA
)
self.foxha_credentials = get_credentials_for(
self.environment, CredentialType.FOXHA
)
self.dbaas_api = DatabaseAsAServiceApi(
self.infra, self.foxha_credentials
)
self.provider = FoxHAProvider(self.dbaas_api)
示例3: stop_vm
def stop_vm(workflow_dict):
try:
environment = workflow_dict['environment']
cs_credentials = get_credentials_for(
environment=environment, credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
instances_detail = workflow_dict['instances_detail']
for instance_detail in instances_detail:
instance = instance_detail['instance']
host = instance.hostname
host_csattr = HostAttr.objects.get(host=host)
stoped = cs_provider.stop_virtual_machine(vm_id=host_csattr.vm_id)
if not stoped:
raise Exception("Could not stop host {}".format(host))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例4: credential
def credential(self):
if not self._credential:
self._credential = get_credentials_for(
Environment.objects.get(name='prod'), CredentialType.VIP_PROVIDER
)
return self._credential
示例5: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
cs_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
instances = workflow_dict['databaseinfra'].instances.all()
if not instances:
for vm_id in workflow_dict['vms_id']:
cs_provider.destroy_virtual_machine(
project_id=cs_credentials.project,
environment=workflow_dict['environment'],
vm_id=vm_id)
for host in workflow_dict['hosts']:
host_attr = HostAttr.objects.filter(host=host)
host.delete()
LOG.info("Host deleted!")
if host_attr:
host_attr[0].delete()
LOG.info("HostAttr deleted!")
for instance in instances:
host = instance.hostname
host_attr = HostAttr.objects.get(host=host)
LOG.info("Destroying virtualmachine %s" % host_attr.vm_id)
cs_provider.destroy_virtual_machine(
project_id=cs_credentials.project,
environment=workflow_dict['environment'],
vm_id=host_attr.vm_id)
host_attr.delete()
LOG.info("HostAttr deleted!")
instance.delete()
LOG.info("Instance deleted")
host.delete()
LOG.info("Host deleted!")
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0011)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例6: 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))
示例7: do
def do(self, workflow_dict):
try:
cs_credentials = get_credentials_for(
environment=workflow_dict['source_environment'],
credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
for source_host in workflow_dict['source_hosts']:
host_attr = HostAttr.objects.get(host=source_host)
LOG.info("Destroying virtualmachine %s" % host_attr.vm_id)
cs_provider.destroy_virtual_machine(
project_id=cs_credentials.project,
environment=workflow_dict['source_environment'],
vm_id=host_attr.vm_id)
host_attr.delete()
LOG.info("HostAttr deleted!")
source_host.delete()
LOG.info("Source host deleted")
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例8: undo
def undo(self, workflow_dict):
try:
if 'databaseinfra' not in workflow_dict:
return False
database = workflow_dict['databaseinfra'].databases.get()
databaseinfra = database.databaseinfra
acl_credential = get_credentials_for(
environment=database.environment,
credential_type=CredentialType.ACLAPI)
acl_client = AclClient(
acl_credential.endpoint, acl_credential.user,
acl_credential.password, database.environment)
for database_bind in database.acl_binds.all():
infra_instances_binds = DatabaseInfraInstanceBind.objects.filter(
databaseinfra=databaseinfra,
bind_address=database_bind.bind_address)
try:
helpers.unbind_address(
database_bind, acl_client, infra_instances_binds, True)
except Exception as e:
LOG.warn(e)
continue
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0019)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例9: start_vm
def start_vm(workflow_dict):
try:
environment = workflow_dict['environment']
cs_credentials = get_credentials_for(environment = environment, credential_type = CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials = cs_credentials)
instances_detail = workflow_dict['instances_detail']
for instance_detail in instances_detail:
instance = instance_detail['instance']
host = instance.hostname
host_csattr = HostAttr.objects.get(host=host)
started = cs_provider.start_virtual_machine(vm_id = host_csattr.vm_id)
if not started:
raise Exception, "Could not start host {}".format(host)
for instance_detail in instances_detail:
instance = instance_detail['instance']
host = instance.hostname
host_csattr = HostAttr.objects.get(host=host)
host_ready = check_ssh(server=host.address, username=host_csattr.vm_user, password=host_csattr.vm_password, wait=5, interval=10)
if not host_ready:
error = "Host %s is not ready..." % host
LOG.warn(error)
raise Exception, error
return True
except Exception, e:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例10: vm_credential
def vm_credential(self):
if not self._vm_credential:
self._vm_credential = get_credentials_for(
self.environment, CredentialType.VM,
)
return self._vm_credential
示例11: undo
def undo(self, workflow_dict):
try:
original_cloudstackpack = workflow_dict['original_cloudstackpack']
environment = workflow_dict['environment']
cs_credentials = get_credentials_for(
environment=environment, credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
original_serviceofferingid = original_cloudstackpack.offering.serviceofferingid
if workflow_dict['offering_changed']:
host = workflow_dict['host']
host_csattr = HostAttr.objects.get(host=host)
offering_changed = cs_provider.change_service_for_vm(
vm_id=host_csattr.vm_id, serviceofferingid=original_serviceofferingid)
if not offering_changed:
raise Exception("Could not change offering for Host {}".format(host))
else:
LOG.info('No resize to instance {}'.format(workflow_dict['instance']))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例12: get_network_from_ip
def get_network_from_ip(ip, database_environment):
net_api_credentials = get_credentials_for(
environment=database_environment,
credential_type=CredentialType.NETWORKAPI
)
ip_client = Ip.Ip(
net_api_credentials.endpoint, net_api_credentials.user,
net_api_credentials.password
)
ips = ip_client.get_ipv4_or_ipv6(ip)
ips = ips['ips']
if type(ips) != list:
ips = [ips]
net_ip = ips[0]
network_client = Network.Network(
net_api_credentials.endpoint, net_api_credentials.user,
net_api_credentials.password
)
network = network_client.get_network_ipv4(net_ip['networkipv4'])
network = network['network']
return network['oct1'] + '.' + network['oct2'] + '.' + network['oct3'] + '.' + network['oct4'] + '/' + network['block']
示例13: do
def do(self, workflow_dict):
try:
database = workflow_dict['database']
cloudstackpack = workflow_dict['cloudstackpack']
instances_detail = workflow_dict['instances_detail']
environment = workflow_dict['environment']
cs_credentials = get_credentials_for(environment = environment, credential_type = CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials = cs_credentials)
serviceofferingid = cloudstackpack.offering.serviceofferingid
for instance_detail in instances_detail:
instance = instance_detail['instance']
host = instance.hostname
host_csattr = HostAttr.objects.get(host=host)
offering_changed = cs_provider.change_service_for_vm(vm_id = host_csattr.vm_id, serviceofferingid = serviceofferingid)
if not offering_changed:
raise Exception, "Could not change offering for Host {}".format(host)
instance_detail['offering_changed'] = True
LOG.info('Updating offering DatabaseInfra.')
databaseinfraoffering = DatabaseInfraOffering.objects.get(databaseinfra = database.databaseinfra)
databaseinfraoffering.offering = cloudstackpack.offering
databaseinfraoffering.save()
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例14: credential
def credential(self):
if not self._credential:
self._credential = get_credentials_for(
self.environment, CredentialType.VIP_PROVIDER
)
return self._credential
示例15: undo
def undo(self, workflow_dict):
try:
if 'databaseinfra' not in workflow_dict:
return False
action = 'deny'
database = workflow_dict['databaseinfra'].databases.get()
for database_bind in database.acl_binds.all():
acl_environment, acl_vlan = database_bind.bind_address.split(
'/')
data = {"kind": "object#acl", "rules": []}
default_options = {
"protocol": "tcp",
"source": "",
"destination": "",
"description": "{} access for database {} in {}".format(database_bind.bind_address,
database.name,
database.environment.name),
"action": action,
"l4-options": {"dest-port-start": "",
"dest-port-op": "eq"}
}
LOG.info("Default options: {}".format(default_options))
databaseinfra = database.infra
infra_instances_binds = DatabaseInfraInstanceBind.objects.filter(
databaseinfra=databaseinfra,
bind_address=database_bind.bind_address)
for infra_instance_bind in infra_instances_binds:
custom_options = copy.deepcopy(default_options)
custom_options['source'] = database_bind.bind_address
custom_options[
'destination'] = infra_instance_bind.instance + '/32'
custom_options[
'l4-options']['dest-port-start'] = infra_instance_bind.instance_port
data['rules'].append(custom_options)
acl_credential = get_credentials_for(environment=database.environment,
credential_type=CredentialType.ACLAPI)
acl_client = AclClient(acl_credential.endpoint,
acl_credential.user,
acl_credential.password)
LOG.info("Data used on payload: {}".format(data))
acl_client.revoke_acl_for(environment=acl_environment,
vlan=acl_vlan, payload=data)
infra_instances_binds.delete()
database_bind.delete()
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0019)
workflow_dict['exceptions']['traceback'].append(traceback)
return False