Esempio n. 1
0
    def __setup_virtual_machine_done(self, sctx):
        self.log.debug("azure virtual environment %d vm setup done" % sctx.current_job_index)
        ctx = sctx.job_ctxs[sctx.current_job_index]

        # update the status of virtual environment
        ve = self.db.find_first_object_by(VirtualEnvironment, id=ctx.virtual_environment_id)

        adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host)
        if ve:
            ve.status = VEStatus.RUNNING

            public_ip, port = adapter.get_virtual_machine_public_endpoint(
                ctx.cloud_service_name,
                ctx.deployment_name,
                ctx.virtual_machine_name,
                ctx.endpoint_name)

            if not public_ip:
                self.log.warn("unable to find public ip for vm %s, set guacamole failed" % ctx.virtual_machine_name)
            else:
                remote_para = get_remote_parameters(
                    ctx.raw_system_config,
                    ctx.remote,
                    ctx.virtual_machine_name,
                    public_ip, port)

                ve.remote_paras = json.dumps(remote_para)

            self.db.commit()
            self.expr_manager.check_expr_status(ve.experiment)

        self.log.debug("azure virtual environment %d vm success callback done, step to next" % sctx.current_job_index)
        # step to config next unit
        sctx.current_job_index += 1
        self.__schedule_setup(sctx)
    def __setup_virtual_machine_done(self, sctx):
        self.log.debug("azure virtual environment %d vm setup done" % sctx.current_job_index)
        ctx = sctx.job_ctxs[sctx.current_job_index]

        # update the status of virtual environment
        expr = Experiment.objects(id=ctx.experiment_id).first()
        ve = expr.virtual_environments[sctx.current_job_index]
        adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host)

        ve.status = VEStatus.RUNNING
        expr.save()

        azure_resource = AzureVirtualMachine(name=ctx.virtual_machine_name,
                                             label=ctx.virtual_machine_label,
                                             dns="%s.chinacloudapp.cn" % ctx.cloud_service_name,
                                             end_points=[])
        # todo record AzureDeployment, AzureCloudService and so on in db for roll back

        vm_role = adapter.get_virtual_machine_role(ctx.cloud_service_name,
                                                   ctx.deployment_name,
                                                   ctx.virtual_machine_name)

        if (not vm_role) or (not vm_role.instance_endpoints):
            self.log.warn(
                "unable to find vm %s, cannot update virtual env config like guacamole" % ctx.virtual_machine_name)
        else:
            for endpoint in vm_role.instance_endpoints:
                azure_resource.public_ip = endpoint.vip
                if endpoint.name == ctx.remote_endpoint_name:  # endpoint for remote desktop
                    ve.remote_provider = VERemoteProvider.Guacamole
                    ve.remote_paras = get_remote_parameters(
                        ctx.raw_system_config,
                        ctx.remote,
                        ctx.virtual_machine_name,
                        endpoint.vip,
                        endpoint.public_port)
                else:
                    try:
                        aep = self.__get_persistable_endpoint(endpoint, ctx.raw_network_config)
                        azure_resource.end_points.append(aep)
                    except Exception as e:
                        self.log.error(e)

        ve.azure_resource = azure_resource
        azure_resource.save()
        expr.save()
        self.expr_manager.check_expr_status(expr)

        self.log.debug("azure virtual environment %d vm success callback done, step to next" % sctx.current_job_index)
        # step to config next unit
        sctx.current_job_index += 1
        self.__schedule_setup(sctx)
Esempio n. 3
0
    def __setup_virtual_machine_done(self, sctx):
        self.log.debug("azure virtual environment %d vm setup done" %
                       sctx.current_job_index)
        ctx = sctx.job_ctxs[sctx.current_job_index]

        # update the status of virtual environment
        ve = self.db.find_first_object_by(VirtualEnvironment,
                                          id=ctx.virtual_environment_id)

        adapter = VirtualMachineAdapter(ctx.subscription_id,
                                        ctx.pem_url,
                                        host=ctx.management_host)
        if ve:
            ve.status = VEStatus.RUNNING

            public_ip, port = adapter.get_virtual_machine_public_endpoint(
                ctx.cloud_service_name, ctx.deployment_name,
                ctx.virtual_machine_name, ctx.endpoint_name)

            if not public_ip:
                self.log.warn(
                    "unable to find public ip for vm %s, set guacamole failed"
                    % ctx.virtual_machine_name)
            else:
                remote_para = get_remote_parameters(ctx.raw_system_config,
                                                    ctx.remote,
                                                    ctx.virtual_machine_name,
                                                    public_ip, port)

                ve.remote_paras = json.dumps(remote_para)

            self.db.commit()
            self.expr_manager.check_expr_status(ve.experiment)

        self.log.debug(
            "azure virtual environment %d vm success callback done, step to next"
            % sctx.current_job_index)
        # step to config next unit
        sctx.current_job_index += 1
        self.__schedule_setup(sctx)