{"id":1412,"date":"2019-11-01T18:25:44","date_gmt":"2019-11-01T23:25:44","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1412"},"modified":"2019-11-01T18:29:31","modified_gmt":"2019-11-01T23:29:31","slug":"oracle-oci-cli-query","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/oracle-oci-cli-query\/","title":{"rendered":"Oracle OCI CLI Query"},"content":{"rendered":"\n
Some bash snippets of using --query, jq and interacting with Bash to manipulate into variables. <\/p>\n\n\n\n
Collect boot volume's id<\/p>\n\n\n
\nSRCBOOTVOLID=$(oci --profile $profile bv boot-volume list --compartment-id "$source_compartment" --availability-domain "$source_ad" --query "data [?\\"display-name\\" == '$instance_name (Boot Volume)'].{id:id}" | jq -r '.[] | .id')\n<\/pre><\/div>\n\n\nCollect instance ocid<\/p>\n\n\n
\nINSTANCEID=$(oci --profile $profile compute instance launch --availability-domain $target_ad --compartment-id $sandbox_compartment --shape VM.Standard1.1 --display-name "burner-$instance_name-instance-for-custom-image" --source-boot-volume-id $BOOTVOLID --wait-for-state RUNNING --subnet-id $sandbox_subnetid --query "data .{id:id}" | jq -r '. | .id')\n<\/pre><\/div>\n\n\nStop instance and collect the id (or whatever you need from the json)<\/p>\n\n\n
\nSTOPPEDID=$(oci --profile $profile compute instance action --action STOP --instance-id $INSTANCEID --wait-for-state STOPPED --query "data .{id:id}" | jq -r '. | .id')\n\n<\/pre><\/div>\n\n\nCollect the work-request-id to monitor in a loop after I export a custom image to object storage. Note in the query the field I need is NOT in the data section.<\/p>\n\n\n
\nWORKREQUESTID=$(oci --profile $profile compute image export to-object --image-id $IMAGEID --namespace faketenancy --bucket-name DR-Images --name $today-$instance_name-custom-image-object --query '"opc-work-request-id"' --raw-output)\n\nwhile [ "$RESULT" != "SUCCEEDED" ]\ndo\n RESULT=$(oci --profile myprofile work-requests work-request get --work-request-id $WORKREQUESTID --query "data .{status:status}" | jq -r '. | .status')\n echo "running export job and $RESULT checking every 2 mins"\n sleep 2m\ndone\n<\/pre><\/div>\n\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"
Some bash snippets of using –query, jq and interacting with Bash to manipulate into variables. Collect boot volume’s id Collect<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107,87],"tags":[],"class_list":["post-1412","post","type-post","status-publish","format-standard","hentry","category-jq","category-oci"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1412"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1412\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}