Tag Archives: JVM Languages

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

How to Create an Instance Snapshot 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/snapshot/").request("application/oracle-compute-v3+json").header("cookie", ...).post(Entity.entity("{ \"instance\": \"sampleInstance" }", "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: '/snapshot/' }, (res) => {

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

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

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

  }

});

req.write('{ "instance": "sampleInstance" }');

req.end();

API w/ Python

import requests

res = requests.post('https://host/snapshot/', headers={'accept':'application/oracle-compute-v3+json','content-type':'application/oracle-compute-v3+json','cookie':...},json={'instance':'sampleInstance'})

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

CLI

1) Run the following command:

opc compute snapshots add sampleInstance

How to Resize 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/instance/sampleInstance").request("application/oracle-compute-v3+json").header("cookie", ...).put(Entity.entity("{ \"shape\": \"sampleShape\" }", "application/oracle-compute-v3+json"));

    if (res.getStatus() == 200)
      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: 'PUT', path: '/instance/sampleInstance' }, (res) => {

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

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

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

  }

});

req.write('{ "shape": "shapeName" }');

req.end();

API w/ Python

import requests

res = requests.put('https://host/instance/sampleInstance',headers={'accept':'application/oracle-compute-v3+json','content-type':'application/oracle-compute-v3+json','cookie':...},json={'shape':'shapeName'})

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

CLI

Not supported.

How to Restart 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/rebootinstancerequest/").request("application/oracle-compute-v3+json").header("cookie", ...).post(Entity.entity("{ \"instance\": \"sampleInstance" }", "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: '/rebootinstancerequest/' }, (res) => {

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

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

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

  }

});

res.write('{ "instance": "sampleInstance" }');

req.end();

API w/ Python

import requests

res = requests.post('https://host/rebootinstancerequest/',headers={'accept':'application/oracle-compute-v3+json','content-type':'application/oracle-compute-v3+json','cookie':...},json={'instance','sampleInstance'})

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

CLI

1) Run the following command:

opc compute reboot-instance-requests add sampleInstance

How to Start 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/instance/sampleInstance").request("application/oracle-compute-v3+json").header("cookie", ...).put(Entity.entity("{ \"desired_state\": \"running\" }", "application/oracle-compute-v3+json"));

    if (res.getStatus() == 200)
      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: 'PUT', path: '/instance/sampleInstance' }, (res) => {

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

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

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

  }

});

req.write('{ "desired_state": "running" }');

req.end();

API w/ Python

import requests

res = requests.get('https://host/instance/sampleInstance',headers={'accept':'application/oracle-compute-v3+json','content-type','application/oracle-compute-v3+json','cookie':cookie},json={'desired_state':'running'})
 
if res.status_code == 200:
  print(res.text)

CLI

Not supported.

How to Stop 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/instance/sampleInstance").request("application/oracle-compute-v3+json").header("cookie", ...).put(Entity.entity("{ \"desired_state\": \"shutdown\" }", "application/oracle-compute-v3+json"));

    if (res.getStatus() == 200)
      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: 'PUT', path: '/instance/sampleInstance' }, (res) => {

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

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

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

  }

});

req.write('{ "desired_state": "shutdown" }');

req.end();

API w/ Python

import requests

res = requests.get('https://host/instance/sampleInstance',headers={'accept':'application/oracle-compute-v3+json','content-type','application/oracle-compute-v3+json','cookie':cookie},json={'desired_state':'shutdown'})

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

CLI

Not supported.

How to Get 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.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/instance/sampleInstance").request("application/oracle-cloud-v3+json").header("cookie", ...).get();

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

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.get({ headers: { accept: 'application/oracle-compute-v3+json', cookie: ... }, hostname: 'host', path: '/instance/sampleInstance' }, (res) => {

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

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

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

  }

});

req.end();

API w/ Python

import requests

res = requests.get('https://host/instance/sampleInstance',headers={'accept':'application/oracle-compute-v3+json','cookie':...)

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

CLI

1) Run the following command:

opc compute instances get sampleInstance

How to List Instances in the Oracle Compute Cloud Service

API w/ Java

All Information

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
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/instance/sampleUser/").request("application/oracle-compute-v3+json").header("cookie", ...).get();

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

    client.close();
  }

}

Only Names

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
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/instance/sampleUser/").request("application/oracle-compute-v3+directory+json").header("cookie", ...).get();

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

    client.close();
  }

}

API w/ Node.js

All Information

const https = require('https');

const req = https.get({ headers: { accept: 'application/oracle-compute-v3+json', cookie: ... }, hostname: 'host', path: '/instance/sampleUser/' }, (res) => {

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

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

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

  }

});

req.end();

Only Names

const https = require('https');

const req = https.get({ headers: { accept: 'application/oracle-compute-v3+directory+json', cookie: ... }, hostname: 'host', path: '/instance/sampleUser/' }, (res) => {

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

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

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

  }

});

req.end();

API w/ Python

All Information

import requests

res = requests.get('https://host/instance/sampleUser/',headers={'accept':'application/oracle-compute-v3+json','cookie':...})

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

Only Names

import requests

res = requests.get('https://host/instance/sampleUser/',headers={'accept':'application/oracle-compute-v3+directory+json','cookie':...})

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

CLI

1) Run the following command:

opc compute instances list sampleUser

How to Get a Shape 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.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/shape/sampleShape").request("application/oracle-cloud-v3+json").header("cookie", ...).get();

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

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.get({ headers: { accept: 'application/oracle-compute-v3+json', cookie: ... }, hostname: 'host', path: '/shape/shapeName' }, (res) => {

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

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

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

  }

});

req.end();

API w/ Python

import requests

res = requests.get('https://host/shape/sampleShape',headers={'accept':'application/oracle-compute-v3+json','cookie':cookie})

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

CLI

1) Run the following command:

opc compute shapes get shapeName

How to List Shapes 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.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/shape/").request("application/oracle-cloud-v3+json").header("cookie", ...).get();

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

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.get({ headers: { accept: 'application/oracle-compute-v3+json', cookie: ... }, hostname: 'host', path: '/shape/' }, (res) => {

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

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

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

  }

});

req.end();

API w/ Python

import requests

res = requests.get('https://host/shape/',headers={'accept':'application/oracle-compute-v3+json','cookie':...})

if res.status_code == 200
  print(res.text)

CLI

1) Run the following command:

opc compute shapes list