def __config_virtual_machine(self, sctx): ctx = sctx.job_ctxs[sctx.current_job_index] ctx.vm_need_config = False adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) 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 try: req = adapter.update_virtual_machine_network_config( ctx.cloud_service_name, ctx.deployment_name, ctx.virtual_machine_name, network_config) except Exception as e: self.log.error( "azure virtual environment %d error while config network: %r" % (sctx.current_job_index, e.message)) self.__on_setup_failed(sctx) return ctx.request_id = req.request_id self.__wait_for_config_virtual_machine(sctx)
def __setup_virtual_machine_without_deployment_existed(self, sctx): ctx = sctx.job_ctxs[sctx.current_job_index] adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) 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 try: 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, role_size=ctx.virtual_machine_size, vm_image_name=ctx.image_name if ctx.is_vm_image else None) 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_setup_failed(sctx) return # 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)
def __setup_virtual_machine_with_deployment_existed(self, sctx): # get context from super context ctx = sctx.job_ctxs[sctx.current_job_index] adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) 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 # add virtual machine to deployment try: # 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, role_size=ctx.virtual_machine_size, vm_image_name=ctx.image_name if ctx.is_vm_image else None) # 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_setup_failed(sctx) return # 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)
def __setup_virtual_machine_with_deployment_existed(self, sctx): # get context from super context ctx = sctx.job_ctxs[sctx.current_job_index] adapter = VirtualMachineAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) 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 # add virtual machine to deployment try: # 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) # 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_setup_failed(sctx) return # 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)