Exemple #1
0
    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
    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
	def do(self, workflow_dict):
		try:
			if not 'hosts' 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)

			cs_provider = CloudStackProvider(credentials=cs_credentials)

			workflow_dict['databaseinfraattr'] = []

			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

				else:
					databaseinfraattr.is_write = False

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

				workflow_dict['databaseinfraattr'].append(databaseinfraattr)

			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
    def do(self, workflow_dict):
        try:
            if not 'hosts' 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

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

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

            return False
    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