Example #1
0
    def __config_virtual_machine(self, sctx):
        ctx = sctx.job_ctxs[sctx.current_job_index]
        ctx.vm_need_config = False
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        try:
            network_config = get_network_config(
                ctx.raw_network_config,
                adapter.get_assigned_endpoints(ctx.cloud_service_name))

            if len(network_config.input_endpoints.input_endpoints) == 0:
                # don't need to config, skip
                self.__setup_virtual_machine_done(sctx)
                return

            req = adapter.update_virtual_machine_network_config(
                ctx.cloud_service_name, ctx.deployment_name,
                ctx.virtual_machine_name, network_config)

            ctx.request_id = req.request_id
            self.__wait_for_config_virtual_machine(sctx)
        except Exception as e:
            self.log.error(
                "azure virtual environment %d error while config network: %r" %
                (sctx.current_job_index, e.message))
            self._on_virtual_environment_failed(sctx)
Example #2
0
    def __setup_virtual_machine_without_deployment_existed(self, sctx):
        ctx = sctx.job_ctxs[sctx.current_job_index]
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        try:
            if not ctx.is_vm_image:
                network_config = get_network_config(
                    ctx.raw_network_config,
                    adapter.get_assigned_endpoints(ctx.cloud_service_name))
            else:
                network_config = None

            req = adapter.create_virtual_machine_deployment(
                ctx.cloud_service_name,
                ctx.deployment_name,
                ctx.deployment_slot,
                ctx.virtual_machine_label,
                ctx.virtual_machine_name,
                ctx.system_config,
                ctx.os_virtual_hard_disk,
                network_config,
                provision_guest_agent=True,
                resource_extension_references=ctx.
                resource_extension_references,
                role_size=ctx.virtual_machine_size,
                vm_image_name=ctx.image_name if ctx.is_vm_image else None)
            # wait for add virtual machine to finish
            ctx.request_id = req.request_id
            ctx.vm_need_config = True if ctx.is_vm_image else False
            self.__wait_for_create_virtual_machine_deployment(sctx)
        except Exception as e:
            self.log.error(
                "azure virtual environment %d create virtual machine %r failed: %r"
                % (sctx.current_job_index, ctx.virtual_machine_name, str(e)))
            self._on_virtual_environment_failed(sctx)
    def __config_virtual_machine(self, sctx):
        ctx = sctx.job_ctxs[sctx.current_job_index]
        ctx.vm_need_config = False
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        try:
            network_config = get_network_config(
                ctx.raw_network_config,
                adapter.get_assigned_endpoints(ctx.cloud_service_name))

            if len(network_config.input_endpoints.input_endpoints) == 0:
                # don't need to config, skip
                self.__setup_virtual_machine_done(sctx)
                return

            req = adapter.update_virtual_machine_network_config(
                ctx.cloud_service_name,
                ctx.deployment_name,
                ctx.virtual_machine_name,
                network_config)

            ctx.request_id = req.request_id
            self.__wait_for_config_virtual_machine(sctx)
        except Exception as e:
            self.log.error(
                "azure virtual environment %d error while config network: %r" %
                (sctx.current_job_index, e.message))
            self._on_virtual_environment_failed(sctx)
    def __setup_virtual_machine_without_deployment_existed(self, sctx):
        ctx = sctx.job_ctxs[sctx.current_job_index]
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        try:
            if not ctx.is_vm_image:
                network_config = get_network_config(
                    ctx.raw_network_config,
                    adapter.get_assigned_endpoints(ctx.cloud_service_name))
            else:
                network_config = None

            req = adapter.create_virtual_machine_deployment(
                ctx.cloud_service_name,
                ctx.deployment_name,
                ctx.deployment_slot,
                ctx.virtual_machine_label,
                ctx.virtual_machine_name,
                ctx.system_config,
                ctx.os_virtual_hard_disk,
                network_config,
                provision_guest_agent=True,
                resource_extension_references=ctx.resource_extension_references,
                role_size=ctx.virtual_machine_size,
                vm_image_name=ctx.image_name if ctx.is_vm_image else None)
            # wait for add virtual machine to finish
            ctx.request_id = req.request_id
            ctx.vm_need_config = True if ctx.is_vm_image else False
            self.__wait_for_create_virtual_machine_deployment(sctx)
        except Exception as e:
            self.log.error(
                "azure virtual environment %d create virtual machine %r failed: %r"
                % (sctx.current_job_index, ctx.virtual_machine_name, str(e)))
            self._on_virtual_environment_failed(sctx)
Example #5
0
    def __setup_virtual_machine_with_deployment_existed(self, sctx):
        # get context from super context
        ctx = sctx.job_ctxs[sctx.current_job_index]
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        # add virtual machine to deployment
        try:
            deployment_name = adapter.get_deployment_name(
                ctx.cloud_service_name, ctx.deployment_slot)
            if not ctx.is_vm_image:
                network_config = get_network_config(
                    ctx.raw_network_config,
                    adapter.get_assigned_endpoints(ctx.cloud_service_name))
            else:
                network_config = None

            # create if vm is not created
            if not adapter.virtual_machine_exists(ctx.cloud_service_name,
                                                  deployment_name,
                                                  ctx.virtual_machine_name):
                req = adapter.add_virtual_machine(
                    ctx.cloud_service_name,
                    deployment_name,
                    ctx.virtual_machine_name,
                    ctx.system_config,
                    ctx.os_virtual_hard_disk,
                    network_config=network_config,
                    provision_guest_agent=True,
                    resource_extension_references=ctx.
                    resource_extension_references,
                    role_size=ctx.virtual_machine_size,
                    vm_image_name=ctx.image_name if ctx.is_vm_image else None)

                # wait for add virtual machine to finish
                ctx.request_id = req.request_id
                ctx.vm_need_config = True if ctx.is_vm_image else False
                self.__wait_for_add_virtual_machine(sctx)
            # NOTE: if the vm is created, we think is well configured
            # else:  # if vm is created, then we need to config the vm
            #    ctx.vm_need_config = True
            #    self.__wait_for_virtual_machine_ready(sctx)
            #    return
            else:
                self.__setup_virtual_machine_done(sctx)
                return
        except Exception as e:
            self.log.error(
                "azure virtual environment %d create virtual machine %r failed: %r"
                % (sctx.current_job_index, ctx.virtual_machine_name, str(e)))
            self._on_virtual_environment_failed(sctx)
    def __setup_virtual_machine_with_deployment_existed(self, sctx):
        # get context from super context
        ctx = sctx.job_ctxs[sctx.current_job_index]
        adapter = self.__get_adapter_from_sctx(sctx, VirtualMachineAdapter)

        # add virtual machine to deployment
        try:
            deployment_name = adapter.get_deployment_name(ctx.cloud_service_name, ctx.deployment_slot)
            if not ctx.is_vm_image:
                network_config = get_network_config(
                    ctx.raw_network_config,
                    adapter.get_assigned_endpoints(ctx.cloud_service_name))
            else:
                network_config = None

            # create if vm is not created
            if not adapter.virtual_machine_exists(ctx.cloud_service_name, deployment_name, ctx.virtual_machine_name):
                req = adapter.add_virtual_machine(
                    ctx.cloud_service_name,
                    deployment_name,
                    ctx.virtual_machine_name,
                    ctx.system_config,
                    ctx.os_virtual_hard_disk,
                    network_config=network_config,
                    provision_guest_agent=True,
                    resource_extension_references=ctx.resource_extension_references,
                    role_size=ctx.virtual_machine_size,
                    vm_image_name=ctx.image_name if ctx.is_vm_image else None)

                # wait for add virtual machine to finish
                ctx.request_id = req.request_id
                ctx.vm_need_config = True if ctx.is_vm_image else False
                self.__wait_for_add_virtual_machine(sctx)
            # NOTE: if the vm is created, we think is well configured
            # else:  # if vm is created, then we need to config the vm
            #    ctx.vm_need_config = True
            #    self.__wait_for_virtual_machine_ready(sctx)
            #    return
            else:
                self.__setup_virtual_machine_done(sctx)
                return
        except Exception as e:
            self.log.error(
                "azure virtual environment %d create virtual machine %r failed: %r"
                % (sctx.current_job_index, ctx.virtual_machine_name, str(e)))
            self._on_virtual_environment_failed(sctx)