All posts by Fernando Ribeiro

About Fernando Ribeiro

Professional with 17 years of experience in enterprise solution development. Already worked as sales consultant, solution architect and full stack developer in companies like Oracle, Red Hat and IBM. Currently works as Principal Digital & Cloud Architect at Oracle and contributes to open source projects.

How to Receive a Message from an Apache ActiveMQ Topic with Red

Red [
  msg: read http://localhost:8161/api/message/SampleTopic

  print msg
]
Advertisements

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

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.