--- title: TWCC CLI tags: TWCCTutorial, Guide, CLI, TW --- # TWCC CLI [TOC] ## 1. 部署操作環境 ### Step 1. 安裝相關套件 :::info :bulb: 注意:若以 TWCC 「開發型容器」安裝此工具,需先在容器內執行以下作業,再部署 TWCC CLI 環境: <br> - 輸入以下指令以修改名稱伺服器 (Name server) <br> ```bash= sudo vi /etc/resolv.conf ``` - 再輸入`i`,進入編輯模式 :arrow_right: 將 nameserver `10.96.0.10` 改為 `8.8.8.8` :arrow_right: 按 `esc` 鍵進入命令模式 :arrow_right: 輸入 `:wq!` :arrow_right: 按`enter` 鍵存檔離開 :arrow_right: 再按`enter` 回到容器命令列 <br>  ::: - 若本機尚未安裝 Python,以下以 TWCC 虛擬運算服務建立的環境 (OS:Ubuntu 16.04) 為例,請依序執行以下指令安裝套件 :::danger ```bash= whereis pip ``` > 若結果出得來,跳過 >  ::: ```bash= ~~sudo sed -i 's/nova\.clouds\./tw./g' /etc/apt/sources.list~~(刪除) sudo apt update sudo apt -y install build-essential python2.7 python2.7-dev curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python2.7 get-pip.py sudo pip install pipenv git clone https://github.com/TW-NCHC/TWCC-CLI ``` 亦可以直接執行以下指令 ```bash= git clone https://github.com/TW-NCHC/TWCC-CLI cd TWCC-CLI/ ~~ bash tools/twcc_env.sh ~~(刪除) ``` - 若本機已安裝 Python,直接執行以下指令即可 :::danger container 環境底下 ```bash= pip install pipenv --user ``` >  ::: ```bash= ~~sudo pip install pipenv~~(刪除) git clone https://github.com/TW-NCHC/TWCC-CLI ```  ### Step 2. 進入 TWCC_CLI 環境並開始使用服務 ```bash= cd TWCC-CLI/ ``` :::danger 檢查: ```bash= whereis pipenv ``` pipenv: (找不到) ---- 沒有 .local ```bash= export PATH=$HOME/.local/bin:$PATH #gpfs # whereis pipenv which pipenv ``` export 之後就找得到 ---- tag:regex https://github.com/scrapinghub/dateparser/issues/566#issuecomment-531191804 ```bash= sudo apt update #確定有安裝python-dev sudo apt -y install build-essential python-dev pipenv install ``` :::  ```bash= cd TWCC-CLI/ pipenv install pipenv run python src/test/gpu_cntr.py ```  ```python= !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py list-cntr !export PATH=$HOME/.local/bin:$PATH; cd $HOME/TWCC-CLI/src/test; pipenv run python gpu_cntr.py del-cntr 628864 ```  - 輸入您的 TWCC API 金鑰 (金鑰會依計畫、使用者、使用者身份會有不同),便可成功登入 - 選擇使用的計畫 (使用滑鼠點擊計畫或在 Answer 輸入計畫編號)  :::info :bulb:查詢金鑰的方法: - 登入 TWCC 後,點選右上角的使用者名稱,再點選「API 金鑰管理」  <br> - 便可檢視您的金鑰  ::: :::info :bulb: 更換使用計畫的方法: - 執行以下指令刪除金鑰,並再次進入 TWCC CLI 環境,便可輸入其他計畫之金鑰 ```bash= rm -rf ~/.twcc_data ```  ::: :::info :bulb: 注意: - 輸入 API 金鑰後,若遇以下語言設定問題: " UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-6: ordinal not in range(128)"  <br/> - 請先依序執行以下指令,設定語言檔案,再次輸入 API 金鑰即可登入 ```bash= sudo apt-get update sudo apt-get install -y locales sudo locale-gen "en_US.UTF-8" sudo update-locale LC_ALL="en_US.UTF-8" sudo export LC_ALL=en_US.UTF-8 ``` ::: ## 2. 開發型容器 :::info :bulb: 注意:以 TWCC CLI 使用開發型容器服務,須先部署 TWCC CLI 的操作環境。參見本文件上方:1. 部署操作環境 ::: ### 2-1. 建立開發型容器 ```bash= # [-cntr 容器名稱] [- gpu GPU 數量] [-sol 映像檔類型名稱] [-img 映像檔名稱] [-wait T/True 或 F/False,是否顯示"Waiting for container to be Ready"] pipenv run python src/test/gpu_cntr.py create-cntr [-cntr Container name] [-gpu Number of GPU] [-sol Solution Name] [-img Image Name] [-wait T/True or F/False <Wait for CNTR to ready or not>] ``` - 或直接以預設資訊建立容器 ```bash= pipenv run python src/test/gpu_cntr.py create-cntr ```  - 在 TWCC 開發型容器管理頁面,可看到已建立的容器  :::info :bulb: 預設建立資訊 | 映像檔類型、映像檔 | 容器名稱 |硬體設定| | -------- | -------- | -------- | | TensorFlow (latest environment) | twcc-cli | 1 GPU + 4 cores + 90 GB memory | ::: ### 2-2. 檢視所有映像檔類型 ```bash= pipenv run python src/test/gpu_cntr.py list-sol ``` ### 2-3. 檢視所有映像檔 ```bash= pipenv run python src/test/gpu_cntr.py list-all-img ``` ### 2-4. 檢視容器資訊 ```bash= # [-site 容器ID] # [-table T/True or F/False <True 顯示容器 ID、名稱、建立時間、狀態;False 顯示容器連線資訊>] # [-all <顯示計畫的全部容器,僅限租戶管理員使用>] pipenv run python src/test/gpu_cntr.py list-cntr [-site Site Id] [-table <Show info on table>] [-all <Show all containers>] ``` - 列表顯示所有容器 ```bash= pipenv run python src/test/gpu_cntr.py list-cntr ```  - 檢視 site_id 為 `93072` 的容器資訊 ```bash= pipenv run python src/test/gpu_cntr.py list-cntr -site 93072 ```  - 檢視 site_id 為 `93072` 的容器連線資訊 (將會顯示您的 SSH 連線資訊:主機帳號、SSH 連接埠) ```bash= pipenv run python src/test/gpu_cntr.py list-cntr -site 93072 -table False ``` - 檢視計劃下的所有容器 (僅限租戶管理員限使用) ```bash= pipenv run python src/test/gpu_cntr.py list-cntr -all ```  ### 2-5. 刪除容器 ```bash= pipenv run python src/test/gpu_cntr.py del-cntr Site Id ```  - 刪除 site_id 為 `93072` 的容器 ```bash= pipenv run python src/test/gpu_cntr.py del-cntr 93072 ``` ### 2-6. 容器複本 - TWCC CLI 提供使用者客製化容器,在 TWCC 完成環境部署後,可保存容器複本,再次建立容器便能快速進入熟悉的工作環境。 #### 2-6-1. 提出容器複本的申請 ```bash= # 輸入以下指令後,需再輸入欲保留環境的容器 ID、自訂的 image tag 與 image name pipenv run python src/test/gpu_cntr.py create-commit ``` - 提出申請保留容器 ID 為 `283375` 的容器,image tag 自訂為 latest,image name 自訂為 `copyofimg`:  :::info :bulb: 使用者需先在 TWCC 建立容器,並自行將環境部署完成,才能提出此申請。提出申請後,系統管理員將會審核您的申請,將會另行以 e-mail 通知審核結果 ::: #### 2-6-2. 列出已提出的申請 ```bash= pipenv run python src/test/gpu_cntr.py list-commit ``` #### 2-6-3. 以複本建立容器 - 申請審核通過後,便可使用以下方法,以複本直接建立容器 ```bash= # 可使用 list-all-img 查詢所有「映像檔類型」與「映像檔」名稱 pipenv run python gpu_cntr.py create-cntr -img <Custom Image Name> -sol <Image Type Name> ``` - 複本的映像檔類型名稱皆為 「Custom Image」、映像檔名稱為使用者自訂的「image name:image tag」 ```bash= pipenv run python gpu_cntr.py create-cntr -img copyofimg:latest -sol Custom Image ``` ## 3. 雲端物件儲存 :::info :bulb: 注意: - 若在開發型容器內使用雲端物件儲存、存取資料,需先在容器環境內部署 TWCC CLI 工具。參見本文件上方:1. 部署操作環境 - 一般檔案管理 (上傳/刪除/搜尋Metadata/設定通知),亦可於 TWCC 入口網站內操作,參見:[雲端物件儲存](https://www.twcc.ai/doc?page=object&euqinu=true) ::: ### 3-1. 建立儲存體 ```bash= # [-n/--name 儲存體名稱] pipenv run python src/test/s3.py create-bucket [-n/--name <Bucket name>] ``` - 建立名為 `testbucket` 的儲存體 ```bash= pipenv run python src/test/s3.py create-bucket -n testbucket ``` ### 3-2. 檢視所有儲存體 ```bash= pipenv run python src/test/s3.py list-buckets ``` ### 3-3. 檢視儲存體的所有檔案 ```bash= pipenv run python src/test/s3.py list-files [-n/--name <Bucket name> [-df] ``` - 檢視儲存體`wtestbucket` 的檔案資訊 ```bash= pipenv run python src/test/s3.py list-files -n wtestbucket ``` ### 3-4. 刪除儲存體的某一檔案 ```bash= # [-n/--name 儲存體名稱] [-f/--file_name 檔案名稱] pipenv run python src/test/s3.py del-file [-n/--name <Bucket name>] [-f/--file_name <Name of the file>] ``` - 刪除儲存體 `wtestbucket` 的 `a.txt` 檔案內容 ```bash= pipenv run python src/test/s3.py del-file -n wtestbucket -f a.txt ``` ### 3-5. 上傳檔案 或 資料夾至儲存體 ```bash= # [-s/--source 來源檔案路徑] [-d/--directory 儲存體名稱] [-k/--key 上傳後的檔案名稱] pipenv run python src/test/s3.py upload [-s/--source <Local source path>] [-d/--directory <Bucket name>] [-k/--key <file name>] [-r] ``` - 上傳一檔案至儲存體 ```bash= # 若沒有另外定義 key (上傳後的檔案名),則檔案名會同來源檔案的名稱 pipenv run python src/test/s3.py upload -s ~/uploadme.txt -d wtestbucket -k downloadme.txt ``` - 上傳一資料夾的所有檔案至儲存體 ```bash= # 加上 -r 以上傳資料夾內的所有檔案 pipenv run python src/test/s3.py upload -s ~/UploadFolder/ -d wtestbucket -r ``` ### 3-6. 下載儲存體檔案 或 整個儲存體 ```bash= # [-s/--source 儲存體名稱] [-d/--directory 下載至本機的路徑位置] [-k/--key 欲下載的檔案名稱] pipenv run python src/test/s3.py download [-s/--source <Bucket name>] [-k/--key <file name>] [-d/--directory <Local path>] [-r] ``` - 自儲存體下載一檔案 ```bash= # 若無在 -d 路徑之後指定下載後的檔案名稱,會直接以來源檔案名稱命名 pipenv run python src/test/s3.py download -s wtestbucket -k downloadme.txt -d ~/ ``` - 下載儲存體至指定位置 ```bash= # 加上 -r 以上傳資料夾內的所有檔案 pipenv run python s3.py download -s wtestbucket -d ~/DowntoHere/ -r ``` ### 3-7. 刪除儲存體 ```bash= # [-n/--name 欲刪除的儲存體名稱] pipenv run python src/test/s3.py del-bucket [-n/--name Bucket name] [-df] ``` - 刪除儲存體 `thisiswrong` ```bash= pipenv run python src/test/s3.py del-bucket -n thisiswrong ``` - 若儲存體仍有檔案,刪除時將會顯示錯誤訊息。請加上 "-df",將會先刪除檔案,再刪除儲存體 ```bash= pipenv run python src/test/s3.py del-bucket -n thisiswrong -df ``` 2019-11-07 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up