def upload_model()

in decisionai_plugin/common/util/model.py [0:0]


def upload_model(config, subscription, model_id, model_dir):
    try:
        zip_dir = os.path.join(config.model_temp_dir, subscription + '_' + model_id + '_' + str(time.time()))
        os.makedirs(zip_dir, exist_ok=True)

        zip_file = os.path.join(zip_dir, "model.zip")
        with zipfile.ZipFile(zip_file, "w") as zf:
            src_files = os.listdir(model_dir)
            for file_name in src_files:
                full_file = os.path.join(model_dir, file_name)
                if os.path.isfile(full_file):
                    zf.write(full_file, basename(full_file))
                else: 
                    full_subdir = os.path.join(model_dir, file_name)
                    for root, dirs, files in os.walk(full_subdir):
                        for fn in files:
                            absfn = os.path.join(root, fn)
                            print(absfn)
                            zfn = absfn[len(model_dir)+len(os.sep):]
                            zf.write(absfn, zfn)
            zf.close()

        container_name = config.tsana_app_name

        azure_blob = AzureBlob(AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_ACCOUNT_KEY, AZURE_STORAGE_ACCOUNT_DOMAIN)
        azure_blob.create_container(container_name)

        with open(zip_file, "rb") as data:
            azure_blob.upload_blob(container_name, subscription + '_' + model_id, data)
        return STATUS_SUCCESS, ''
    except Exception as e:
        return STATUS_FAIL, str(e)
    finally:
        shutil.rmtree(zip_dir, ignore_errors=True)