Exemple #1
0
    def create_host(self, infra, offering, name, team_name, zone=None, database_name=''):
        url = "{}/{}/{}/host/new".format(
            self.credential.endpoint, self.provider, self.environment
        )
        data = {
            "engine": self.engine,
            "name": name,
            "cpu": offering.cpus,
            "memory": offering.memory_size_mb,
            "group": infra.name,
            "team_name": team_name,
            "database_name": database_name
        }
        if zone:
            data['zone'] = zone

        response = self._request(post, url, json=data, timeout=600)
        if response.status_code != 201:
            raise HostProviderCreateVMException(response.content, response)

        content = response.json()

        host = Host()
        host.address = content["address"]
        host.hostname = host.address
        host.user = self.vm_credential.user
        host.password = self.vm_credential.password
        host.provider = self.provider
        host.identifier = content["id"]
        host.offering = offering
        host.save()

        return host
Exemple #2
0
    def create_host(self, infra, offering, name):
        url = "{}/{}/{}/host/new".format(self.credential.endpoint,
                                         self.provider, self.environment)
        data = {
            "engine": self.engine,
            "name": name,
            "cpu": offering.cpus,
            "memory": offering.memory_size_mb,
            "group": infra.name
        }

        response = post(url, json=data)
        if response.status_code != 201:
            raise IndexError(response.content, response)

        content = response.json()

        host = Host()
        host.address = content["address"]
        host.hostname = host.address
        host.user = self.vm_credential.user
        host.password = self.vm_credential.password
        host.provider = self.provider
        host.identifier = content["id"]
        host.offering = offering
        host.save()

        return host
    def create_host(self, infra, offering, name, team_name, zone=None, database_name=''):
        url = "{}/{}/{}/host/new".format(
            self.credential.endpoint, self.provider, self.environment
        )
        data = {
            "engine": self.engine,
            "name": name,
            "cpu": offering.cpus,
            "memory": offering.memory_size_mb,
            "group": infra.name,
            "team_name": team_name,
            "database_name": database_name
        }
        if zone:
            data['zone'] = zone

        response = self._request(post, url, json=data, timeout=600)
        if response.status_code != 201:
            raise HostProviderCreateVMException(response.content, response)

        content = response.json()

        host = Host()
        host.address = content["address"]
        host.hostname = host.address
        host.user = self.vm_credential.user
        host.password = self.vm_credential.password
        host.provider = self.provider
        host.identifier = content["id"]
        host.offering = offering
        host.save()

        return host
 def do(self):
     host = Host()
     host.address = self.instance.vm_name
     host.hostname = self.instance.vm_name
     host.user = '******'
     host.password = '******'
     host.provider = 'k8s'
     host.save()
     self.instance.hostname = host
     self.instance.save()
Exemple #5
0
    def create_host(self,
                    infra,
                    offering,
                    name,
                    team_name,
                    zone=None,
                    database_name='',
                    host_obj=None,
                    port=None,
                    volume_name=None,
                    init_user=None,
                    init_password=None,
                    static_ip=None):
        url = "{}/{}/{}/host/new".format(self.credential.endpoint,
                                         self.provider, self.environment)
        data = {
            "engine": self.engine,
            "name": name,
            "cpu": offering.cpus,
            "memory": offering.memory_size_mb,
            "group": infra.name,
            "team_name": team_name,
            "database_name": database_name,
            "static_ip_id": static_ip and static_ip.identifier
        }
        if zone:
            data['zone'] = zone
        if port:
            data['port'] = port
        if volume_name:
            data['volume_name'] = volume_name
        if init_user:
            data['init_user'] = init_user
        if init_password:
            data['init_password'] = init_password

        response = self._request(post, url, json=data, timeout=600)
        if response.status_code != 201:
            raise HostProviderCreateVMException(response.content, response)

        content = response.json()
        if host_obj is None:
            host = Host()
            host.hostname = content["address"]
        else:
            host = host_obj
        host.address = content["address"]
        host.user = self.vm_credential.user
        host.password = self.vm_credential.password
        host.private_key = self.vm_credential.private_key
        host.provider = self.provider
        host.identifier = content["id"]
        host.offering = offering
        host.save()
        return host
    def create_host(self, address):
        from physical.models import Host

        host = Host()
        host.address = address
        host.hostname = host.address
        host.user = self.vm_credentials.user
        host.password = self.vm_credentials.password
        host.offering = self.cs_offering
        host.save()
        return host
Exemple #7
0
    def do(self, workflow_dict):
        try:
            if 'environment' not in workflow_dict or 'plan' not in workflow_dict:
                return False

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

            vm_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.VM)

            cs_provider = CloudStackProvider(credentials=cs_credentials)

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

            workflow_dict['hosts'] = []
            workflow_dict['instances'] = []
            workflow_dict['databaseinfraattr'] = []
            workflow_dict['vms_id'] = []

            workflow_dict['plan'].validate_min_environment_bundles(
                workflow_dict['environment']
            )
            bundles = list(cs_plan_attrs.bundles_actives)

            offering = cs_plan_attrs.get_stronger_offering()

            for index, vm_name in enumerate(workflow_dict['names']['vms']):

                if len(bundles) == 1:
                    bundle = bundles[0]
                else:
                    if index == 0:
                        bundle = LastUsedBundle.get_next_infra_bundle(
                            plan=workflow_dict['plan'], bundles=bundles)
                    else:
                        bundle = LastUsedBundle.get_next_bundle(
                            current_bundle=bundle, bundles=bundles)

                try:
                    DatabaseInfraOffering.objects.get(
                        databaseinfra=workflow_dict['databaseinfra'])
                except ObjectDoesNotExist:
                    LOG.info("Creating databaseInfra Offering...")
                    dbinfra_offering = DatabaseInfraOffering()
                    dbinfra_offering.offering = offering
                    dbinfra_offering.databaseinfra = workflow_dict[
                        'databaseinfra']
                    dbinfra_offering.save()

                LOG.debug(
                    "Deploying new vm on cs with bundle %s and offering %s" % (bundle, offering))

                error, vm = cs_provider.deploy_virtual_machine(
                    offering=offering.serviceofferingid,
                    bundle=bundle,
                    project_id=cs_credentials.project,
                    vmname=vm_name,
                    affinity_group_id=cs_credentials.get_parameter_by_name(
                        'affinity_group_id'),
                )

                if error:
                    raise Exception(error)

                LOG.debug("New virtualmachine: %s" % vm)

                workflow_dict['vms_id'].append(vm['virtualmachine'][0]['id'])

                host = Host()
                host.address = vm['virtualmachine'][0]['nic'][0]['ipaddress']
                host.hostname = host.address
                host.cloud_portal_host = True
                host.offering = offering
                host.user = vm_credentials.user
                host.password = vm_credentials.password
                host.save()
                LOG.info("Host created!")

                workflow_dict['hosts'].append(host)

                host_attr = HostAttr()
                host_attr.vm_id = vm['virtualmachine'][0]['id']
                host_attr.vm_user = vm_credentials.user
                host_attr.vm_password = vm_credentials.password
                host_attr.host = host
                host_attr.bundle = bundle
                host_attr.save()
                LOG.info("Host attrs custom attributes created!")

                instance = Instance()
                instance.address = host.address
                instance.port = 3306
                instance.hostname = host
                instance.databaseinfra = workflow_dict['databaseinfra']
                instance.instance_type = Instance.MYSQL
                instance.save()
                LOG.info("Instance created!")

                workflow_dict['instances'].append(instance)

                databaseinfra = workflow_dict['databaseinfra']
                databaseinfra.last_vm_created += 1
                databaseinfra.save()
                workflow_dict['databaseinfra'] = databaseinfra

                LastUsedBundleDatabaseInfra.set_last_infra_bundle(
                    databaseinfra=databaseinfra, bundle=host_attr.bundle)

                if workflow_dict['qt'] == 1:

                    LOG.info("Updating databaseinfra endpoint...")
                    databaseinfra = workflow_dict['databaseinfra']
                    databaseinfra.endpoint = instance.address + \
                        ":%i" % (instance.port)
                    databaseinfra.save()
                    workflow_dict['databaseinfra'] = databaseinfra

                    return True

            return True
        except Exception:
            traceback = full_stack()

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

            return False