def create_storage_account(self, experiment_id, template_unit): """ If storage account not exist in azure subscription, then create it Else reuse storage account in azure subscription :return: """ name = template_unit.get_storage_account_name() description = template_unit.get_storage_account_description() label = template_unit.get_storage_account_label() location = template_unit.get_storage_account_location() commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.START) # avoid duplicate storage account in azure subscription if not self.service.storage_account_exists(name): # avoid name already taken by other azure subscription if not self.service.check_storage_account_name_availability(name).result: m = self.CREATE_STORAGE_ACCOUNT_ERROR[1] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 1) self.log.error(m) return False # avoid no available subscription remained if self.subscription.get_available_storage_account_count() < self.NEED_COUNT: m = self.CREATE_STORAGE_ACCOUNT_ERROR[2] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 2) self.log.error(m) return False # delete old azure storage account in database delete_azure_storage_account(name) try: result = self.service.create_storage_account(name, description, label, location) except Exception as e: m = self.CREATE_STORAGE_ACCOUNT_ERROR[0] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, e.message) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 0) self.log.error(e) return False # query async operation status run_job(MDL_CLS_FUNC[2], (self.azure_key_id, ), (result.request_id, MDL_CLS_FUNC[3], (self.azure_key_id, ), (experiment_id, template_unit), MDL_CLS_FUNC[4], (self.azure_key_id, ), (experiment_id, template_unit))) else: # check whether storage account created by azure formation before if contain_azure_storage_account(name): m = self.CREATE_STORAGE_ACCOUNT_INFO[1] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, AZURE_FORMATION) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 1) else: m = self.CREATE_STORAGE_ACCOUNT_INFO[2] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, AZURE_FORMATION) commit_azure_storage_account(name, description, label, location, ASAStatus.ONLINE, experiment_id) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 2) self.log.debug(m) # create cloud service run_job(MDL_CLS_FUNC[1], (self.azure_key_id,), (experiment_id, template_unit)) return True
def create_storage_account_async_true(self, experiment_id, template_unit): name = template_unit.get_storage_account_name() description = template_unit.get_storage_account_description() label = template_unit.get_storage_account_label() location = template_unit.get_storage_account_location() # make sure storage account exist if not self.service.storage_account_exists(name): m = self.CREATE_STORAGE_ACCOUNT_ERROR[4] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 4) self.log.error(m) else: m = self.CREATE_STORAGE_ACCOUNT_INFO[0] % (AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_storage_account(name, description, label, location, ASAStatus.ONLINE, experiment_id) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 0) self.log.debug(m) # create cloud service run_job(MDL_CLS_FUNC[1], (self.azure_key_id,), (experiment_id, template_unit))
def create_storage_account_async_true(self, experiment_id, template_unit): name = template_unit.get_storage_account_name() description = template_unit.get_storage_account_description() label = template_unit.get_storage_account_label() location = template_unit.get_storage_account_location() # make sure storage account exist if not self.service.storage_account_exists(name): m = self.CREATE_STORAGE_ACCOUNT_ERROR[4] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 4) self.log.error(m) else: m = self.CREATE_STORAGE_ACCOUNT_INFO[0] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_storage_account(name, description, label, location, ASAStatus.ONLINE, experiment_id) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 0) self.log.debug(m) # create cloud service run_job(MDL_CLS_FUNC[1], (self.azure_key_id, ), (experiment_id, template_unit))
def create_storage_account(self, experiment_id, template_unit): """ If storage account not exist in azure subscription, then create it Else reuse storage account in azure subscription :return: """ name = template_unit.get_storage_account_name() description = template_unit.get_storage_account_description() label = template_unit.get_storage_account_label() location = template_unit.get_storage_account_location() commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.START) # avoid duplicate storage account in azure subscription if not self.service.storage_account_exists(name): # avoid name already taken by other azure subscription if not self.service.check_storage_account_name_availability( name).result: m = self.CREATE_STORAGE_ACCOUNT_ERROR[1] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 1) self.log.error(m) return False # avoid no available subscription remained if self.subscription.get_available_storage_account_count( ) < self.NEED_COUNT: m = self.CREATE_STORAGE_ACCOUNT_ERROR[2] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 2) self.log.error(m) return False # delete old azure storage account in database delete_azure_storage_account(name) try: result = self.service.create_storage_account( name, description, label, location) except Exception as e: m = self.CREATE_STORAGE_ACCOUNT_ERROR[0] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, e.message) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.FAIL, m, 0) self.log.error(e) return False # query async operation status run_job(MDL_CLS_FUNC[2], (self.azure_key_id, ), (result.request_id, MDL_CLS_FUNC[3], (self.azure_key_id, ), (experiment_id, template_unit), MDL_CLS_FUNC[4], (self.azure_key_id, ), (experiment_id, template_unit))) else: # check whether storage account created by azure formation before if contain_azure_storage_account(name): m = self.CREATE_STORAGE_ACCOUNT_INFO[1] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, AZURE_FORMATION) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 1) else: m = self.CREATE_STORAGE_ACCOUNT_INFO[2] % ( AZURE_RESOURCE_TYPE.STORAGE_ACCOUNT, name, AZURE_FORMATION) commit_azure_storage_account(name, description, label, location, ASAStatus.ONLINE, experiment_id) commit_azure_log(experiment_id, ALOperation.CREATE_STORAGE_ACCOUNT, ALStatus.END, m, 2) self.log.debug(m) # create cloud service run_job(MDL_CLS_FUNC[1], (self.azure_key_id, ), (experiment_id, template_unit)) return True