Category Archives: Software

How to Create an Instance in OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/lauchplan/', '{ "instances": [ { "shape": "sampleShape", "imagelist": "sampleImageList" } ] }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 201
 puts res.body
end

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 OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/snapshot/', '{ "instance": "instanceName" }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 201
 puts res.body
end

CLI

1) Run the following command:

opc compute snapshots add sampleInstance

How to Rescale an Instance in OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleInstance', '{ "shape": "shapeName" }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 200
 puts res.body
end

CLI

Not supported.

How to Restart an Instance in OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/rebootinstancerequest/', '{ "instance": "sampleInstance" }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 201
 puts res.body
end

CLI

1) Run the following command:

opc compute reboot-instance-requests add sampleInstance

How to Start an Instance in OCI Compute Classic

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': ...}, json = { 'desired_state': 'running' })

if res.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleInstance', '{ "desired_state": "running" }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 200
 puts res.body
end

CLI

Not supported.

How to Stop an Instance in OCI Compute Classic

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': ...}, json = { 'desired_state': 'shutdown' })

if res.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleInstance', '{ "desired_state": "shutdown" }', { :accept => 'application/oracle-compute-v3+json', :content_type => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 200
 puts res.body
end

CLI

Not supported.

How to Get an Instance in OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleInstance', { :accept => 'application/oracle-compute-v3+json', :cookies => cookie }

if res.code == 200
 puts res.body
end

CLI

1) Run the following command:

opc compute instances get sampleInstance

How to List Instances in OCI Compute Classic

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.ok:
  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.ok:
  print(res.text)

API w/ Ruby

All Information

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleUser/', { :accept => 'application/oracle-compute-v3+json', :cookies => cookie }

if res.code == 200
 puts res.body
end

Only Names

require 'rest-client'

res = RestClient.get 'https://host/instance/sampleUser/', { :accept => 'application/oracle-compute-v3+directory+json', :cookies => cookie }

if res.code == 200
 puts res.body
end

CLI

1) Run the following command:

opc compute instances list sampleUser

How to Get a Shape in OCI Compute Classic

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': ...})

if res.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/shape/sampleShape', { :accept => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 200
 puts res.body
end

CLI

1) Run the following command:

opc compute shapes get shapeName

How to List Shapes in OCI Compute Classic

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.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/shape/', { :accept => 'application/oracle-compute-v3+json', :cookies => ... }

if res.code == 200
  puts res.body
end

CLI

1) Run the following command:

opc compute shapes list