{
  "date": "2016-11-07T21:11:03",
  "slug": "oracle-public-cloud-create-a-database-from-command-line",
  "link": "https://www.dbi-services.com/blog/oracle-public-cloud-create-a-database-from-command-line/",
  "title": {
    "rendered": "Oracle Public Cloud: create a database from command line"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nYou love the Oracle Public Cloud with its simple Web interface? Great. But what if you want to automate a database creation from command line?<br />\nEasy with the CURL and REST API.<br />\n<!--more--></p>\n<h3>JSON</h3>\n<p>First, you need to create a JSON file with all the information for your service.<br />\nEverything is documented: <a href=\"https://apicatalog.oraclecloud.com/ui/views/apicollection/oracle-public/database/1.1/serviceinstances\" target=\"_blank\" rel=\"noopener noreferrer\">https://apicatalog.oraclecloud.com/ui/views/apicollection/oracle-public/database/1.1/serviceinstances</a></p>\n<pre><code>\n$ cat createrequestbody.json\n&nbsp;\n{\n  \"description\": \"Mon Nov  7 21:03:39 CET 2016\",\n  \"edition\": \"EE_HP\",\n  \"level\": \"PAAS\",\n  \"serviceName\": \"CDB122\",\n  \"shape\": \"oc3\",\n  \"subscriptionType\": \"MONTHLY\",\n  \"version\": \"12.2.0.1\",\n  \"vmPublicKeyText\": \"ssh-dss AAAAB3NzaC1kc3MAAACBAMrw5Au0hHP1BT/W3gcSg+Fwq36LdfzroubjS6g8RSvcaeltk1O/uQwJV73MCsBDgs4PaAuDekZTW5w6kN8ESd6r6BGLm/sETHNiRzOWWap3ds18iiaLJWcMbKRlZUWLdfhGemryWZaQIFrSNkfE5YkFz4V4m5d4EwKpLzIthKh3AAAAFQDtjTsaF7nydePPJPDqYERu8QlcMQAAAIBjl8NxEmE7nud7b4xuLkuJKnwlf2urHrOZGcQapNUZAjuehe6/8VhPB4GebZb52GlyYOuELDP6e9PXyFRxTfTPff22JE5tPM8vTjCmFEKhBspl43YurJxwvDtvgTNKk5Zp5MBXMDjQ8KNHXlpnRrfh45acHI8gs0KlH51+e7j+6AAAAIA/Q8rVC4g+MBepJGKed2ar0JzralZo7Q8vsZfQ889Y3wkaBJl2/SRaaW1JNmkB20eZIEbRkh9e/ex07ryKg65dgUzU4/2dE2CSxplG0vSf/xp7hYr/bJzR1SZXMKbAdZ2wg+SGaTlKWAAS9xhvKGw1jVWdVgacYJOPl343bMKkuw==\",\n  \"parameters\": [\n    {\n      \"type\": \"db\",\n      \"usableStorage\": \"15\",\n      \"adminPassword\": \"P4ss#ord\",\n      \"sid\": \"CDB122\",\n      \"pdbName\": \"PDB1\",\n      \"failoverDatabase\": \"no\",\n      \"backupDestination\": \"NONE\"\n    }\n  ]\n}\n</code></pre>\n<p>You can see that you have exactly the same information as from the GUI.</p>\n<h3>Create Instance</h3>\n<p>Then, you run the following CURL command (having the cacert.pem certificate in the current directory:</p>\n<pre><code>\n$ curl --include --request POST --cacert ./cacert.pem --user myuser@oracle.com:P4ss#ord --header \"X-ID-TENANT-NAME:opcoct\" --header \"Content-Type:application/json\" --data @createrequestbody.json https://dbcs.emea.oraclecloud.com/paas/service/dbcs/api/v1.1/instances/opcoct\n&nbsp;\nHTTP/2 202\nserver: Oracle-Application-Server-11g\nlocation: https://dbcs.emea.oraclecloud.com:443/paas/service/dbcs/api/v1.1/instances/opcoct/status/create/job/2738110\ncontent-language: en\naccess-control-allow-origin: *\naccess-control-allow-headers: Content-Type, api_key, Authorization\nretry-after: 60\naccess-control-allow-methods: GET, POST, DELETE, PUT, OPTIONS, HEAD\nx-oracle-dms-ecid: 005GBi63mCP3n315RvWByd0003Ri0004Zg\nx-oracle-dms-ecid: 005GBi63mCP3n315RvWByd0003Ri0004Zg\nservice-uri: https://dbcs.emea.oraclecloud.com:443/paas/service/dbcs/api/v1.1/instances/opcoct/CDB122\nx-frame-options: DENY\ncontent-type: application/json\nvary: user-agent\ndate: Mon, 07 Nov 2016 20:03:59 GMT\n</code></pre>\n<p>Here &#8220;opcoct&#8221; is my identity domain id. You find it in the header X-ID-TENANT-NAME and the URL.<br />\nThe myuser@oracle.com:P4ss#ord is the user and password in the domain.</p>\n<p>From the GUI you can see that the creation has started:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureDBAASREST01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureDBAASREST01.png\" alt=\"CaptureDBAASREST01\" width=\"1034\" height=\"199\" class=\"alignnone size-full wp-image-12518\" /></a></p>\n<h3>DBaaS instance information</h3>\n<p>Here is the information for the database service</p>\n<pre><code>\n$ curl --include --request GET --cacert ./cacert.pem --user myuser@oracle.com:P4ss#ord --header \"X-ID-TENANT-NAME:opcoct\" https://dbcs.emea.oraclecloud.com/paas/service/dbcs/api/v1.1/instances/opcoct/CDB122\n&nbsp;\nHTTP/2 200\nserver: Oracle-Application-Server-11g\ncontent-language: en\nservice-uri: https://dbcs.emea.oraclecloud.com:443/paas/service/dbcs/api/v1.1/instances/opcoct/CDB122\naccess-control-allow-headers: Content-Type, api_key, Authorization\naccess-control-allow-methods: GET, POST, DELETE, PUT, OPTIONS, HEAD\nx-oracle-dms-ecid: 005GBiK7U4I3z015Rvl3id00071a0000yo\nx-oracle-dms-ecid: 005GBiK7U4I3z015Rvl3id00071a0000yo\naccess-control-allow-origin: *\nx-frame-options: DENY\ncontent-type: application/json\nvary: user-agent\ndate: Mon, 07 Nov 2016 20:07:52 GMT\ncontent-length: 1244\n&nbsp;\n{\n  \"service_name\": \"CDB122\",\n  \"version\": \"12.2.0.1\",\n  \"status\": \"In Progress\",\n  \"description\": \"Mon Nov  7 21:03:39 CET 2016\",\n  \"identity_domain\": \"opcoct\",\n  \"creation_time\": \"2016-11-07T20:03:59.524+0000\",\n  \"last_modified_time\": \"2016-11-07T20:03:59.505+0000\",\n  \"created_by\": \"myuser@oracle.com\",\n  \"sm_plugin_version\": \"16.4.3-541\",\n  \"service_uri\": \"https:\\/\\/dbcs.emea.oraclecloud.com:443\\/paas\\/service\\/dbcs\\/api\\/v1.1\\/instances\\/opcoct\\/CDB122\",\n  \"num_nodes\": 1,\n  \"level\": \"PAAS\",\n  \"edition\": \"EE_HP\",\n  \"shape\": \"oc3\",\n  \"subscriptionType\": \"MONTHLY\",\n  \"creation_job_id\": \"2738110\",\n  \"num_ip_reservations\": 1,\n  \"backup_destination\": \"NONE\",\n  \"failover_database\": false,\n  \"rac_database\": false,\n  \"sid\": \"CDB122\",\n  \"pdbName\": \"PDB1\",\n  \"demoPdb\": \"\",\n  \"listenerPort\": 1521,\n  \"timezone\": \"UTC\",\n  \"is_clone\": false,\n  \"clone_supported_version\": \"16.3.1\",\n  \"active_jobs\": [\n    {\n      \"active_job_operation\": \"start-db-compute-resources\",\n      \"active_job_id\": 2738113,\n      \"active_job_messages\": []\n    },\n    {\n      \"active_job_operation\": \"create-dbaas-service\",\n      \"active_job_id\": 2738110,\n      \"active_job_messages\": []\n    }\n  ],\n  \"compute_site_name\": \"EM003_Z19\",\n  \"jaas_instances_using_service\": \"\"\n}\n</code></pre>\n<p>The status is &#8216;in progress&#8217;. Let&#8217;s look at the compute service.</p>\n<h3>Compute instance information</h3>\n<p>From the compute service, you can see if there is already an IP address assigned here</p>\n<pre><code>\n$ curl --include --request GET --cacert ./cacert.pem --user myuser@oracle.com:P4ss#ord --header \"X-ID-TENANT-NAME:opcoct\" https://dbcs.emea.oraclecloud.com/paas/service/dbcs/api/v1.1/instances/opcoct/CDB122/servers\n&nbsp;\nHTTP/2 200\nserver: Oracle-Application-Server-11g\ncontent-language: en\naccess-control-allow-headers: Content-Type, api_key, Authorization\naccess-control-allow-methods: GET, POST, DELETE, PUT, OPTIONS, HEAD\nx-oracle-dms-ecid: 005GBiMizXo3z015Rvl3id00071a0004p_\nx-oracle-dms-ecid: 005GBiMizXo3z015Rvl3id00071a0004p_\naccess-control-allow-origin: *\nx-frame-options: DENY\ncontent-type: application/json\nvary: user-agent\ndate: Mon, 07 Nov 2016 20:08:35 GMT\ncontent-length: 430\n&nbsp;\n[{\n  \"status\": \"Running\",\n  \"creation_job_id\": \"2738110\",\n  \"creation_time\": \"2016-11-07T20:03:59.524+0000\",\n  \"created_by\": \"myuser@oracle.com\",\n  \"shape\": \"oc3\",\n  \"sid\": \"CDB122\",\n  \"pdbName\": \"PDB1\",\n  \"listenerPort\": 1521,\n  \"connect_descriptor\": \"CDB122:1521\\/PDB1\",\n  \"connect_descriptor_with_public_ip\": \"null:1521\\/PDB1\",\n  \"initialPrimary\": true,\n  \"storageAllocated\": 142336,\n  \"reservedIP\": \"\",\n  \"hostname\": \"CDB122\"\n}]\n</code></pre>\n<p>No IP address yet. I have the job id (2738110) so that I can check it later.</p>\n<h3>Job information</h3>\n<pre><code>\n$ curl --include --request GET --cacert ./cacert.pem --user myuser@oracle.com:P4ss#ord --header \"X-ID-TENANT-NAME:opcoct\" https://dbcs.emea.oraclecloud.com/paas/service/dbcs/api/v1.1/instances/opcoct/status/create/job/2738110\n&nbsp;\nHTTP/2 202\nserver: Oracle-Application-Server-11g\nlocation: https://dbcs.emea.oraclecloud.com:443/paas/service/dbcs/api/v1.1/instances/opcoct/status/create/job/2738110\ncontent-language: en\naccess-control-allow-origin: *\naccess-control-allow-headers: Content-Type, api_key, Authorization\nretry-after: 60\naccess-control-allow-methods: GET, POST, DELETE, PUT, OPTIONS, HEAD\nx-oracle-dms-ecid: 005GBiOeMbz3n315RvWByd0003Ri00048d\nx-oracle-dms-ecid: 005GBiOeMbz3n315RvWByd0003Ri00048d\nservice-uri: https://dbcs.emea.oraclecloud.com:443/paas/service/dbcs/api/v1.1/instances/opcoct/CDB122\nx-frame-options: DENY\ncontent-type: application/json\nvary: user-agent\ndate: Mon, 07 Nov 2016 20:09:08 GMT\n&nbsp;\n{\n  \"service_name\": \"CDB122\",\n  \"version\": \"12.2.0.1\",\n  \"status\": \"In Progress\",\n  \"description\": \"Mon Nov  7 21:03:39 CET 2016\",\n  \"identity_domain\": \"opcoct\",\n  \"creation_time\": \"2016-11-07T20:03:59.524+0000\",\n  \"last_modified_time\": \"2016-11-07T20:03:59.505+0000\",\n  \"created_by\": \"myuser@oracle.com\",\n  \"sm_plugin_version\": \"16.4.3-541\",\n  \"service_uri\": \"https:\\/\\/dbcs.emea.oraclecloud.com:443\\/paas\\/service\\/dbcs\\/api\\/v1.1\\/instances\\/opcoct\\/CDB122\",\n  \"message\": [\"Starting Compute resources...\"],\n  \"job_start_date\": \"Mon Nov 07 20:04:01 GMT 2016\",\n  \"job_status\": \"InProgress\",\n  \"job_operation\": \"create-dbaas-service\",\n  \"job_request_params\": {\n    \"edition\": \"EE_HP\",\n    \"vmPublicKeyText\": \"ssh-dss AAAAB3NzaC1kc3MAAACBAMrw5Au0hHP1BT/W3gcSg+Fwq36LdfzroubjS6g8RSvcaeltk1O/uQwJV73MCsBDgs4PaAuDekZTW5w6kN8ESd6r6BGLm/sETHNiRzOWWap3ds18iiaLJWcMbKRlZUWLdfhGemryWZaQIFrSNkfE5YkFz4V4m5d4EwKpLzIthKh3AAAAFQDtjTsaF7nydePPJPDqYERu8QlcMQAAAIBjl8NxEmE7nud7b4xuLkuJKnwlf2urHrOZGcQapNUZAjuehe6/8VhPB4GebZb52GlyYOuELDP6e9PXyFRxTfTPff22JE5tPM8vTjCmFEKhBspl43YurJxwvDtvgTNKk5Zp5MBXMDjQ8KNHXlpnRrfh45acHI8gs0KlH51+e7j+6AAAAIA/Q8rVC4g+MBepJGKed2ar0JzralZo7Q8vsZfQ889Y3wkaBJl2/SRaaW1JNmkB20eZIEbRkh9e/ex07ryKg65dgUzU4/2dE2CSxplG0vSf/xp7hYr/bJzR1SZXMKbAdZ2wg+SGaTlKWAAS9xhvKGw1jVWdVgacYJOPl343bMKkuw==\",\n    \"count\": \"2\",\n    \"provisioningTimeout\": \"180\",\n    \"subscriptionType\": \"MONTHLY\",\n    \"createStorageContainerIfMissing\": \"false\",\n    \"dbConsolePort\": \"1158\",\n    \"listenerPort\": \"1521\",\n    \"serviceName\": \"CDB122\",\n    \"namespace\": \"dbaas\",\n    \"version\": \"12.2.0.1\",\n    \"timezone\": \"UTC\",\n    \"pdbName\": \"PDB1\",\n    \"level\": \"PAAS\",\n    \"tenant\": \"opcoct\",\n    \"serviceInstance\": \"CDB122\",\n    \"description\": \"Mon Nov  7 21:03:39 CET 2016\",\n    \"failoverDatabase\": \"false\",\n    \"emExpressPort\": \"5500\",\n    \"ncharset\": \"AL16UTF16\",\n    \"trial\": \"false\",\n    \"sid\": \"CDB122\",\n    \"noRollback\": \"false\",\n    \"operationName\": \"create-dbaas-service\",\n    \"goldenGate\": \"false\",\n    \"backupDestination\": \"NONE\",\n    \"ibkup\": \"false\",\n    \"charset\": \"AL32UTF8\",\n    \"serviceVersion\": \"12.2.0.1\",\n    \"shape\": \"oc3\",\n    \"identity_domain_id\": \"opcoct\",\n    \"serviceType\": \"dbaas\",\n    \"usableStorage\": \"15\",\n    \"disasterRecovery\": \"false\",\n    \"server_base_uri\": \"https:\\/\\/dbcs.emea.oraclecloud.com:443\\/paas\\/service\\/dbcs\\/\",\n    \"computeSiteName\": \"EM003_Z19\",\n    \"isRac\": \"false\"\n  }\n}\n</code></pre>\n<h3>REST Endpoint</h3>\n<p>Here, my test is on the EMEA datacenter and this is why the URL starts with https://dbcs.emea.oraclecloud.com<br />\nIf you don&#8217;t know, you can check on My Cloud Services where you have all information:<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureDBAASREST02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureDBAASREST02.png\" alt=\"CaptureDBAASREST02\" width=\"1092\" height=\"385\" class=\"alignnone size-full wp-image-12522\" /></a></p>\n",
    "protected": false
  }
}
