0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OCI CLIメモ

Last updated at Posted at 2024-06-26

インストール

ociコマンドをインストールする

bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

インストール先は~/binと~/lib/oracle-cli (デフォルト)

参照
Quickstart

そこそこ重い ~/lib/oracle-cli/lib/python3.x/site-packagesだけでも664MB以上ある

Dockerで使う際はオプションとして--no-tty --accept-all-defaultsを付けること

用意するもの

  1. MyProfile > ocid (ocid1.user.xxx)
  2. Tenancy > ocid (ocid1.tenancy.xxx)
  3. MyProfile > API keys > API Keys

最後のは~/prikey.pemに保存しておく

参照
必要なキーとOCID

適当なコマンドを実行するとWizardが開始する

ERROR: Could not find config file at /home/ubuntu/.oci/config
Do you want to create a new config file? [Y/n]: y
Do you want to create your config file by logging in through a browser? [Y/n]: n
    This command provides a walkthrough of creating a valid CLI config file.

    The following links explain where to find the information required by this
    script:

    User API Signing Key, OCID and Tenancy OCID:

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other

    Region:

        https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm

    General config documentation:

        https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm


Enter a location for your config [/home/ubuntu/.oci/config]: 
Enter a user OCID: ocid1.user.oc1..xxx
Enter a tenancy OCID: ocid1.tenancy.oc1..yyy
Enter a region by index or name(e.g.
1: af-johannesburg-1, 2: ap-chiyoda-1, 3: ap-chuncheon-1, 4: ap-dcc-canberra-1, 5: ap-dcc-gazipur-1,
6: ap-hyderabad-1, 7: ap-ibaraki-1, 8: ap-melbourne-1, 9: ap-mumbai-1, 10: ap-osaka-1,
11: ap-seoul-1, 12: ap-singapore-1, 13: ap-sydney-1, 14: ap-tokyo-1, 15: ca-montreal-1,
16: ca-toronto-1, 17: eu-amsterdam-1, 18: eu-dcc-dublin-1, 19: eu-dcc-dublin-2, 20: eu-dcc-milan-1,
21: eu-dcc-milan-2, 22: eu-dcc-rating-1, 23: eu-dcc-rating-2, 24: eu-dcc-zurich-1, 25: eu-frankfurt-1,
26: eu-frankfurt-2, 27: eu-jovanovac-1, 28: eu-madrid-1, 29: eu-madrid-2, 30: eu-marseille-1,
31: eu-milan-1, 32: eu-paris-1, 33: eu-stockholm-1, 34: eu-zurich-1, 35: il-jerusalem-1,
36: me-abudhabi-1, 37: me-abudhabi-3, 38: me-dcc-doha-1, 39: me-dcc-muscat-1, 40: me-dubai-1,
41: me-jeddah-1, 42: mx-monterrey-1, 43: mx-queretaro-1, 44: sa-bogota-1, 45: sa-santiago-1,
46: sa-saopaulo-1, 47: sa-valparaiso-1, 48: sa-vinhedo-1, 49: uk-cardiff-1, 50: uk-gov-cardiff-1,
51: uk-gov-london-1, 52: uk-london-1, 53: us-ashburn-1, 54: us-chicago-1, 55: us-gov-ashburn-1,
56: us-gov-chicago-1, 57: us-gov-phoenix-1, 58: us-langley-1, 59: us-luke-1, 60: us-phoenix-1,
61: us-saltlake-2, 62: us-sanjose-1): 
Do you want to generate a new API Signing RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: n
Enter the location of your API Signing private key file: /home/ubuntu/prikey.pem 
Warning: To increase security of your API key located at /home/ubuntu/prikey.pem, append an extra line with 'OCI_API_KEY' at the end. For more information, refer to https://docs.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm
Fingerprint: xx:yy:zz
Config written to /home/ubuntu/.oci/config


    If you haven't already uploaded your API Signing public key through the
    console, follow the instructions on the page linked below in the section
    'How to upload the public key':

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2


Successfully created config file with your new CLI user profile
Once your public key is uploaded in the console, you can re-run your command to use your new config file and user profile

パーミッションが違うと怒られるので事前に直しておく

oci setup repair-file-permissions --file /home/ubuntu/prikey.pem

オブジェクトストレージへのアップロード

クラウドコンソールからbucketを作成する
namespaceもここから確認できる

ファイルのアップロード
content-typeでファイルフォーマットを、cache-controlでHTTPのキャッシュをコントロールすることができる

oci os object put -ns mynamespace -bn mybucket --name myimage.png --file /Users/me/myimage.png --metadata '{"key1":"value1","key2":"value2"}' --content-type "image/png" --cache-control "public, max-age=604800, immutable"
               
Uploading object  [####################################]  100%
{
  "etag": "xxx",
  "last-modified": "yyy",
  "opc-content-md5": "zzz"
}

参照
Using the CLI
put — OCI CLI Command Reference 3.44.1 documentation
オブジェクト・ストレージ・オブジェクト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?