• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.get_credentials_for函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了get_credentials_for函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:tsunli,项目名称:database-as-a-service,代码行数:57,代码来源:create_secondary_ip.py


示例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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:15,代码来源:fox.py


示例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
开发者ID:openarmy,项目名称:database-as-a-service,代码行数:25,代码来源:__init__.py


示例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
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:migrate_networkapi_vip.py


示例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
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:60,代码来源:create_virtualmachines.py


示例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))
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:31,代码来源:database.py


示例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
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:32,代码来源:remove_vms.py


示例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
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:34,代码来源:check_database_binds.py


示例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
开发者ID:Milstein,项目名称:database-as-a-service,代码行数:33,代码来源:mongodb_share.py


示例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
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:vip_provider.py


示例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
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:30,代码来源:resize_vm.py


示例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']
开发者ID:hunterfu,项目名称:database-as-a-service,代码行数:26,代码来源:views.py


示例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
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:35,代码来源:resize_vm.py


示例14: credential

    def credential(self):
        if not self._credential:
            self._credential = get_credentials_for(
                self.environment, CredentialType.VIP_PROVIDER
            )

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


示例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
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:60,代码来源:check_database_binds.py


示例16: __init__

 def __init__(self, instance):
     super(MetricsCollector, self).__init__(instance)
     self.credential = get_credentials_for(
         self.environment, CredentialType.TELEGRAF)
     self.collector_allowed = self.credential.get_parameter_by_name(
         'collector_allowed')
     self.kafka_topic = self.credential.get_parameter_by_name(
         'kafka_topic')
开发者ID:globocom,项目名称:database-as-a-service,代码行数:8,代码来源:metric_collector.py


示例17: _get_fox_provider

    def _get_fox_provider(self, driver):
        databaseinfra = driver.databaseinfra

        foxha_credentials = get_credentials_for(
            environment=databaseinfra.environment,
            credential_type=CredentialType.FOXHA
        )
        dbaas_api = DatabaseAsAServiceApi(databaseinfra, foxha_credentials)
        return FoxHAProvider(dbaas_api)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:9,代码来源:mysql.py


示例18: get_log_url

    def get_log_url(self):
        from util import get_credentials_for
        from util.laas import get_group_name
        from dbaas_credentials.models import CredentialType

        credential = get_credentials_for(environment=self.environment, credential_type=CredentialType.LOGNIT)
        #print credential.endpoint, get_group_name(self)
        url = "%s%s" % (credential.endpoint, get_group_name(self))
        return "<a href='%s' target='_blank'>%s</a>" % (url, url)
开发者ID:andrewsmedina,项目名称:database-as-a-service,代码行数:9,代码来源:models.py


示例19: database_dex_analyze_view

    def database_dex_analyze_view(self, request, database_id):
        import json
        import random
        from dbaas_laas.provider import LaaSProvider
        from util import get_credentials_for
        from util.laas import get_group_name
        from dbaas_credentials.models import CredentialType
        import os
        import string
        from datetime import datetime, timedelta


        def generate_random_string(length, stringset=string.ascii_letters+string.digits):
            return ''.join([stringset[i%len(stringset)] \
            for i in [ord(x) for x in os.urandom(length)]])


        database = Database.objects.get(id=database_id)

        if database.status != Database.ALIVE or not database.database_status.is_alive:
            self.message_user(
                request, "Database is not alive cannot be analyzed", 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 analyzed because it is in use by another task.", level=messages.ERROR)
            url = reverse('admin:logical_database_changelist')
            return HttpResponseRedirect(url)


        credential =get_credentials_for(environment=database.environment,
                                        credential_type=CredentialType.LAAS)

        db_name = database.name
        environment = database.environment
        endpoint = credential.endpoint
        username = credential.user
        password = credential.password
        lognit_environment = credential.get_parameter_by_name('lognit_environment')

        provider = LaaSProvider()

        group_name = get_group_name(database)
        today = (datetime.now()).strftime('%Y%m%d')
        yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y%m%d')
        uri = "group:{} text:query date:[{} TO {}] time:[000000 TO 235959]".format(group_name,yesterday,today)


        parsed_logs = ''
        database_logs = provider.get_logs_for_group(environment, lognit_environment, uri)
        try:
            database_logs = json.loads(database_logs)
        except Exception, e:
            pass
开发者ID:openarmy,项目名称:database-as-a-service,代码行数:56,代码来源:database.py


示例20: do

    def do(self, workflow_dict):
        try:
            cs_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.NETWORKAPI)

            cs_provider = CloudStackProvider(credentials=cs_credentials,
                                             networkapi_credentials=networkapi_credentials)

            for infra_attr in workflow_dict['source_secondary_ips']:

                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)
                    ip_removed = cs_provider.remove_networkapi_ip(equipment_id=networkapi_equipment_id,
                                                                  ip_id=networkapi_ip_id)
                    if not ip_removed:
                        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!")

            return True

        except Exception:
            traceback = full_stack()

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

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.get_current_user函数代码示例发布时间:2022-05-27
下一篇:
Python util.get_code函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap