How to Create an Instance in the Oracle Compute Cloud Service

API w/ Java

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

public final class ComputeSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("https://host/launchplan/").request("application/oracle-compute-v3+json").header("cookie", ...).post(Entity.entity("{ \"instances\": [ { \"shape\": \"sampleShape\", \"imagelist\": \"sampleImageList\" } ] }", "application/oracle-compute-v3+json"));

    if (res.getStatus() == 201)
      out.println(res.readEntity(String.class));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { accept: 'application/oracle-compute-v3+json', 'content-type', 'application/oracle-compute-v3+json', cookie: ... }, hostname: 'host', method: 'POST', path: '/launchplan/' }, (res) => {

  if (res.statusCode === 201) {
    var body = '';

    res.on('data', (chunk) => {
      body += chunk.toString();
    });

    res.on('end', () => {
      console.log(body);
    });

  }

});

req.write('{ "instances": [ { "shape": "sampleShape", "imagelist": "sampleImageList" } ] }');

req.end();

API w/ Python

import requests

res = requests.post('https://host/launchplan/',headers{'accept':'application/oracle-compute-v3+json','content-type':'application/oracle-compute-v3+json','cookie':...},json='{'instances':{'shape':'sampleShape','imagelist':'sampleImageList'}})

if res.status_code = 201:
  print(res.text)

CLI

1) Create the launch-plan.json file:

{
  "instances": [
    {
      "shape": "sampleShape",
      "imagelist": "sampleImageList"
    }
  ]
}

2) Run the following command:

opc compute launch-plans add --request-body=launch-plan.json

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s