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


Python provider.CloudStackProvider类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: update_bundle

    def update_bundle(self):
        from dbaas_cloudstack.provider import CloudStackProvider
        from dbaas_cloudstack.util import get_cs_credential

        databaseinfra = self.host.instances.all()[0].databaseinfra
        environment = databaseinfra.environment
        engine = databaseinfra.engine

        cs_credentials = get_cs_credential(environment)
        cs_provider = CloudStackProvider(credentials=cs_credentials)

        networkid = cs_provider.get_vm_network_id(
            vm_id=self.vm_id,
            project_id=cs_credentials.project)

        zoneid = cs_provider.get_vm_zone_id(
            vm_id=self.vm_id,
            project_id=cs_credentials.project)

        bunbdles = CloudStackBundle.objects.filter(
            networkid=networkid,
            zoneid=zoneid,
            engine=engine,
            region__environment=environment)
        if len(bunbdles) > 0:
            self.bundle = bunbdles[0]
            self.save()
开发者ID:globocom,项目名称:dbaas-cloudstack,代码行数:27,代码来源:models.py

示例6: 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

示例7: 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

示例8: 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

示例9: undo

    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:
            cs_credentials = get_credentials_for(
                environment=workflow_dict['target_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            cs_provider = CloudStackProvider(credentials=cs_credentials)

            for source_instance in workflow_dict['source_instances']:
                source_instance.future_instance = None
                source_instance.save()
                LOG.info("Source instance updated")

            for target_instance in workflow_dict['target_instances']:
                target_instance.delete()
                LOG.info("Target instance deleted")

            for source_host in workflow_dict['source_hosts']:
                source_host.future_host = None
                source_host.save()
                LOG.info("Source host updated")

            for target_host in workflow_dict['target_hosts']:
                host_attr = HostAttr.objects.get(host=target_host)
                LOG.info("Destroying virtualmachine %s" % host_attr.vm_id)

                cs_provider.destroy_virtual_machine(
                    project_id=cs_credentials.project,
                    environment=workflow_dict['target_environment'],
                    vm_id=host_attr.vm_id)

                host_attr.delete()
                LOG.info("HostAttr deleted!")

                target_host.delete()
                LOG.info("Target 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:tsunli,项目名称:database-as-a-service,代码行数:46,代码来源:create_virtualmachines.py

示例10: 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

示例11: undo

	def undo(self, workflow_dict):
		LOG.info("Running undo...")
		try:
			if not 'databaseinfra' in workflow_dict and not 'hosts' 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)

			cs_provider = CloudStackProvider(credentials=cs_credentials)

			for infra_attr in databaseinfraattr:
				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 as e:
			traceback = full_stack()

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

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

示例12: do

    def do(self, workflow_dict):
        try:
            if 'hosts' not in workflow_dict:
                return False

            if len(workflow_dict['hosts']) == 1:
                return True

            cs_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.CLOUDSTACK)

            LOG.info("Get credential fot network api...")
            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.NETWORKAPI)

            cs_provider = CloudStackProvider(credentials=cs_credentials,
                                             networkapi_credentials=networkapi_credentials)
            if not cs_provider:
                raise Exception("Could not create CloudStackProvider object")
                return False

            workflow_dict['databaseinfraattr'] = []

            networkapi_equipment_id = cs_provider.register_networkapi_equipment(
                equipment_name=workflow_dict['names']['infra'])
            if not networkapi_equipment_id:
                raise Exception("Could not register networkapi equipment")
                return False

            workflow_dict['networkapi_equipment_id'] = networkapi_equipment_id

            for host in workflow_dict['hosts']:
                LOG.info("Creating Secondary ips...")

                host_attr = HostAttr.objects.get(host=host)

                reserved_ip = cs_provider.reserve_ip(
                    project_id=cs_credentials.project,
                    vm_id=host_attr.vm_id)

                if not reserved_ip:
                    return False

                total = DatabaseInfraAttr.objects.filter(
                    databaseinfra=workflow_dict['databaseinfra']).count()

                databaseinfraattr = DatabaseInfraAttr()

                databaseinfraattr.ip = reserved_ip['secondary_ip']

                if total == 0:
                    databaseinfraattr.is_write = True

                    LOG.info("Updating databaseinfra endpoint...")

                    databaseinfra = workflow_dict['databaseinfra']
                    databaseinfra.endpoint = databaseinfraattr.ip + \
                        ":%i" % 3306
                    databaseinfra.save()

                    workflow_dict['databaseinfra'] = databaseinfra

                    ip_desc = 'Write IP'

                else:
                    databaseinfraattr.is_write = False
                    ip_desc = 'Read IP'

                networkapi_ip_id = cs_provider.register_networkapi_ip(equipment_id=networkapi_equipment_id,
                                                                      ip=reserved_ip[
                                                                          'secondary_ip'],
                                                                      ip_desc=ip_desc)

                databaseinfraattr.cs_ip_id = reserved_ip['cs_ip_id']
                databaseinfraattr.networkapi_equipment_id = networkapi_equipment_id
                databaseinfraattr.networkapi_ip_id = networkapi_ip_id
                databaseinfraattr.databaseinfra = workflow_dict[
                    'databaseinfra']
                databaseinfraattr.save()

                workflow_dict['databaseinfraattr'].append(databaseinfraattr)

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

示例13: do

    def do(self, workflow_dict):
        try:
            if 'target_hosts' not in workflow_dict:
                return False

            if len(workflow_dict['target_hosts']) == 1:
                return True

            cs_credentials = get_credentials_for(
                environment=workflow_dict['target_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            LOG.info("Get credential fot network api...")
            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['target_environment'],
                credential_type=CredentialType.NETWORKAPI)

            cs_provider = CloudStackProvider(credentials=cs_credentials,
                                             networkapi_credentials=networkapi_credentials)
            if not cs_provider:
                raise Exception("Could not create CloudStackProvider object")
                return False

            workflow_dict['target_secondary_ips'] = []

            networkapi_equipment_id = workflow_dict['source_secondary_ips'][0].networkapi_equipment_id

            if not networkapi_equipment_id:
                raise Exception("Could not register networkapi equipment")
                return False

            for index, host in enumerate(workflow_dict['target_hosts']):
                LOG.info("Creating Secondary ips...")
                host_attr = HostAttr.objects.get(host=host)

                reserved_ip = cs_provider.reserve_ip(
                    project_id=cs_credentials.project,
                    vm_id=host_attr.vm_id)
                if not reserved_ip:
                    return False

                databaseinfraattr = DatabaseInfraAttr()
                databaseinfraattr.ip = reserved_ip['secondary_ip']
                if index == 0:
                    databaseinfraattr.is_write = True
                    ip_desc = 'Write IP'
                else:
                    databaseinfraattr.is_write = False
                    ip_desc = 'Read IP'

                networkapi_ip_id = cs_provider.register_networkapi_ip(equipment_id=networkapi_equipment_id,
                                                                      ip=reserved_ip['secondary_ip'],
                                                                      ip_desc=ip_desc)

                databaseinfraattr.cs_ip_id = reserved_ip['cs_ip_id']
                databaseinfraattr.networkapi_equipment_id = networkapi_equipment_id
                databaseinfraattr.networkapi_ip_id = networkapi_ip_id
                databaseinfraattr.databaseinfra = workflow_dict[
                    'databaseinfra']
                databaseinfraattr.save()

                old_ip = workflow_dict['source_secondary_ips'][index]
                old_ip.equivalent_dbinfraattr = databaseinfraattr
                old_ip.save()

                workflow_dict['target_secondary_ips'].append(databaseinfraattr)

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

示例14: do

	def do(self, workflow_dict):
		try:

			LOG.info("Getting cloudstack credentials...")
			cs_credentials = get_credentials_for(
				environment=workflow_dict['environment'],
				credential_type=CredentialType.CLOUDSTACK)

			cs_provider = CloudStackProvider(credentials=cs_credentials)

			statsd_credentials = get_credentials_for(
				environment=workflow_dict['environment'],
				credential_type=CredentialType.STATSD)

			statsd_host, statsd_port = statsd_credentials.endpoint.split(':')

			for index, hosts in enumerate(permutations(workflow_dict['hosts'])):

				LOG.info("Getting vm credentials...")
				host_csattr = CsHostAttr.objects.get(host=hosts[0])

				LOG.info("Cheking host ssh...")
				host_ready = check_ssh(
					server=hosts[0].address, username=host_csattr.vm_user, password=host_csattr.vm_password, wait=5,
					interval=10)

				if not host_ready:
					LOG.warn("Host %s is not ready..." % hosts[0])
					return False

				host_nfsattr = HostAttr.objects.get(host=hosts[0])

				planattr = PlanAttr.objects.get(plan=workflow_dict['plan'])

				contextdict = {
					'EXPORTPATH': host_nfsattr.nfsaas_path,
					'DATABASENAME': workflow_dict['name'],
					'DBPASSWORD': get_credentials_for(environment=workflow_dict['environment'],
					                                  credential_type=CredentialType.MYSQL).password,
					'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
					'ENGINE': 'mysql',
					'STATSD_HOST': statsd_host,
					'STATSD_PORT': statsd_port,
				}

				if len(workflow_dict['hosts']) > 1:
					LOG.info("Updating contexdict for %s" % hosts[0])

					contextdict.update({
						'SERVERID': index + 1,
						'IPMASTER': hosts[1].address,
						'IPWRITE': workflow_dict['databaseinfraattr'][0].ip,
						'IPREAD': workflow_dict['databaseinfraattr'][1].ip,
						'MASTERPAIRNAME': workflow_dict['databaseinfra'].name,
						'HOST01': workflow_dict['hosts'][0],
						'HOST02': workflow_dict['hosts'][1],
						'INSTANCE01': workflow_dict['instances'][0],
						'INSTANCE02': workflow_dict['instances'][1],
						'SECOND_SCRIPT_FILE': '/opt/dbaas/scripts/dbaas_second_script.sh'
					})

				LOG.info("Updating userdata for %s" % hosts[0])

				cs_provider.update_userdata(
					vm_id=host_csattr.vm_id, contextdict=contextdict, userdata=planattr.userdata)

				LOG.info("Executing script on %s" % hosts[0])

				return_code = exec_remote_command(server=hosts[0].address,
				                                  username=host_csattr.vm_user,
				                                  password=host_csattr.vm_password,
				                                  command='/opt/dbaas/scripts/dbaas_userdata_script.sh')

				if return_code != 0:
					return False

			if len(workflow_dict['hosts']) > 1:
				for host in workflow_dict['hosts']:

					LOG.info("Executing script on %s" % hosts[0])

					return_code = exec_remote_command(server=host.address,
					                                  username=host_csattr.vm_user,
					                                  password=host_csattr.vm_password,
					                                  command=contextdict['SECOND_SCRIPT_FILE'])

					if return_code != 0:
						return False

			return True
		except Exception, e:
			traceback = full_stack()

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

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

示例15: do

    def do(self, workflow_dict):
        try:

            LOG.info("Getting cloudstack credentials...")
            cs_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.CLOUDSTACK)

            cs_provider = CloudStackProvider(credentials=cs_credentials)

            mongodbkey = ''.join(random.choice(string.hexdigits) for i in range(50))

            workflow_dict['replicasetname'] = 'RepicaSet_' + workflow_dict['databaseinfra'].name
            
            statsd_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.STATSD)
            
            statsd_host, statsd_port = statsd_credentials.endpoint.split(':')

            for index, instance in enumerate(workflow_dict['instances']):
                host = instance.hostname

                LOG.info("Getting vm credentials...")
                host_csattr = CsHostAttr.objects.get(host=host)

                LOG.info("Cheking host ssh...")
                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:
                    LOG.warn("Host %s is not ready..." % host)
                    return False

                if instance.is_arbiter:
                    contextdict = {
                        'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
                        'DATABASENAME': workflow_dict['name'],
                        'ENGINE': 'mongodb',
                        'STATSD_HOST': statsd_host,
                        'STATSD_PORT': statsd_port,
                    }
                    databaserule = 'ARBITER'
                else:
                    host_nfsattr = HostAttr.objects.get(host=host)
                    contextdict = {
                        'EXPORTPATH': host_nfsattr.nfsaas_path,
                        'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
                        'DATABASENAME': workflow_dict['name'],
                        'ENGINE': 'mongodb',
                        'DBPASSWORD': get_credentials_for(environment=workflow_dict['environment'],
                                                          credential_type=CredentialType.MONGODB).password,
                        'STATSD_HOST': statsd_host,
                        'STATSD_PORT': statsd_port,
                    }

                    if index == 0:
                        databaserule = 'PRIMARY'
                    else:
                        databaserule = 'SECONDARY'

                if len(workflow_dict['hosts']) > 1:
                    LOG.info("Updating contexdict for %s" % host)

                    contextdict.update({
                        'REPLICASETNAME': workflow_dict['replicasetname'],
                        'HOST01': workflow_dict['hosts'][0],
                        'HOST02': workflow_dict['hosts'][1],
                        'HOST03': workflow_dict['hosts'][2],
                        'MONGODBKEY': mongodbkey,
                        'DATABASERULE': databaserule,
                        'SECOND_SCRIPT_FILE': '/opt/dbaas/scripts/dbaas_second_script.sh',
                        'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
                    })

                LOG.info("Updating userdata for %s" % host)

                planattr = PlanAttr.objects.get(plan=workflow_dict['plan'])
                cs_provider.update_userdata(
                    vm_id=host_csattr.vm_id, contextdict=contextdict, userdata=planattr.userdata)

                LOG.info("Executing script on %s" % host)

                return_code = exec_remote_command(server=host.address,
                                                  username=host_csattr.vm_user,
                                                  password=host_csattr.vm_password,
                                                  command='/opt/dbaas/scripts/dbaas_userdata_script.sh')

                if return_code != 0:
                    return False

            if len(workflow_dict['hosts']) > 1:
                for host in workflow_dict['hosts']:

                    LOG.info("Executing script on %s" % host)

                    return_code = exec_remote_command(server=host.address,
                                                      username=host_csattr.vm_user,
                                                      password=host_csattr.vm_password,
#.........这里部分代码省略.........
开发者ID:Milstein,项目名称:database-as-a-service,代码行数:101,代码来源:init_database_mongodb.py


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