def setup_cloud_service(self, sctx): # get context from super context ctx = sctx.job_ctxs[sctx.current_job_index] adapter = CloudServiceAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) try: if not adapter.cloud_service_exists(ctx.cloud_service_name): if not adapter.create_cloud_service( name=ctx.cloud_service_name, label=ctx.cloud_service_label, location=ctx.cloud_service_host): self.log.error("azure virtual environment %d create remote cloud service failed via creation" % sctx.current_job_index) self.__on_setup_failed(sctx) return # create the cloud service remote successfully, record sctx.remote_created.append(Context( type=REMOTE_CREATED_RECORD.TYPE_CLOUD_SERVICE, name=ctx.cloud_service_name)) except Exception as e: self.log.error( "azure virtual environment %d create remote cloud service failed: %r" % (sctx.current_job_index, str(e))) self.__on_setup_failed(sctx) return self.log.debug("azure virtual environment %d cloud service setup done" % sctx.current_job_index) # next step: setup storage self.scheduler.add_once("azure_formation", "setup_storage", context=sctx, seconds=0) return
def setup_cloud_service(self, sctx): # get context from super context ctx = sctx.job_ctxs[sctx.current_job_index] adapter = CloudServiceAdapter(ctx.subscription_id, ctx.pem_url, host=ctx.management_host) try: if not adapter.cloud_service_exists(ctx.cloud_service_name): if not adapter.create_cloud_service( name=ctx.cloud_service_name, label=ctx.cloud_service_label, location=ctx.cloud_service_host): self.log.error( "azure virtual environment %d create remote cloud service failed via creation" % sctx.current_job_index) self.__on_setup_failed(sctx) return # create the cloud service remote successfully, record sctx.remote_created.append( Context(type=REMOTE_CREATED_RECORD.TYPE_CLOUD_SERVICE, name=ctx.cloud_service_name)) except Exception as e: self.log.error( "azure virtual environment %d create remote cloud service failed: %r" % (sctx.current_job_index, str(e))) self.__on_setup_failed(sctx) return self.log.debug( "azure virtual environment %d cloud service setup done" % sctx.current_job_index) # next step: setup storage self.scheduler.add_once("azure_formation", "setup_storage", context=sctx, seconds=0) return
def __setup_rollback(self, record, sctx): # TODO: the rollback process should use a async way same # as previous setup process, but for convinence, # we do it in a sync way for rec in record: if rec.type == REMOTE_CREATED_RECORD.TYPE_CLOUD_SERVICE: adapter = CloudServiceAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) adapter.delete_cloud_service(rec.name, complete=True) elif rec.type == REMOTE_CREATED_RECORD.TYPE_STORAGE_ACCOUNT: adapter = StorageAccountAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) adapter.delete_storage_account(rec.name) elif (rec.type == REMOTE_CREATED_RECORD.TYPE_ADD_VIRTUAL_MACHINE or rec.type == REMOTE_CREATED_RECORD.TYPE_CREATE_VIRTUAL_MACHINE_DEPLOYMENT): adapter = VirtualMachineAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) if rec.type == REMOTE_CREATED_RECORD.TYPE_ADD_VIRTUAL_MACHINE: adapter.delete_virtual_machine( rec.cloud_service_name, rec.deployment_name, rec.virtual_machine_name, True) else: adapter.delete_deployment( rec.cloud_service_name, rec.deployment_name, True) else: self.log.warn("unknown record type: %s" % rec.type)
def __setup_rollback(self, record, sctx): # TODO: the rollback process should use a async way same # as previous setup process, but for convinence, # we do it in a sync way for rec in record: if rec.type == REMOTE_CREATED_RECORD.TYPE_CLOUD_SERVICE: adapter = CloudServiceAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) adapter.delete_cloud_service(rec.name, complete=True) elif rec.type == REMOTE_CREATED_RECORD.TYPE_STORAGE_ACCOUNT: adapter = StorageAccountAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) adapter.delete_storage_account(rec.name) elif (rec.type == REMOTE_CREATED_RECORD.TYPE_ADD_VIRTUAL_MACHINE or rec.type == REMOTE_CREATED_RECORD. TYPE_CREATE_VIRTUAL_MACHINE_DEPLOYMENT): adapter = VirtualMachineAdapter(sctx.subscription_id, sctx.pem_url, host=sctx.management_host) if rec.type == REMOTE_CREATED_RECORD.TYPE_ADD_VIRTUAL_MACHINE: adapter.delete_virtual_machine(rec.cloud_service_name, rec.deployment_name, rec.virtual_machine_name, True) else: adapter.delete_deployment(rec.cloud_service_name, rec.deployment_name, True) else: self.log.warn("unknown record type: %s" % rec.type)