Question & Answer
Question
We had this situation during the migration upgrade to the newer version of CP4D. To consolidate the project assets with numerous notebooks on each project, we exported those notebooks as ipynb files and put them into specific directories. And then we create new projects and add those notebooks to the specific projects. Could you tell me how to automate the process to import those notebooks to the new project by using CPDCTL command tool?
Cause
Since there are a huge number of notebooks we need to add to the new project, importing notebook files one by one in CP4D UI is not a choice. We need to use CPDCTL command tool to automate the process.
Answer
According to the CPDCTL documentation, importing notebooks to the existing project requires 2 steps:
1. Uploading notebook content in ipynb format.
cpdctl assets files upload --path <your remote path to the notebook content> --file <your local path to the notebook content> --project-id <your project id>
2. Create a notebook by referencing the notebook content with the attribute file-reference.
cpdctl notebooks create --name <your notebook name> --project-id <your project id> --file-reference <your remote path to the notebook content> --runtime '{"environment": "<your environment id>"}'
To automate the process to import number of notebook files in the bash shell, we can run the cpdctl command within a loop.
cd <notebook-folder>
for f in *; do
cpdctl asset file upload --path notebook/$f --file $f --project-id <project_id> --file-content-type notebook
cpdctl notebook create --file-reference notebook/$f --name ${f%_*} --project-id <project_id>
done
[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSGU851","label":"IBM Watson Studio for IBM Cloud Pak for Data"},"ARM Category":[{"code":"a8m3p000000UoRHAA0","label":"Administration-\u003EProjects"}],"ARM Case Number":"TS014454794","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]
Was this topic helpful?
Document Information
Modified date:
27 October 2023
UID
ibm17060753