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
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