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