Constructor

Image

new Image(compute, name)

Parameter

compute

Compute

The parent Compute instance this Image belongs to.

name

string

Image name.

See also

Images Overview

Image Resource

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const image = compute.image('image-name');

Property

id

string

Methods

create

create(disk, options)

Create an image.

Parameter

disk

Disk

See Compute#createImage.

options

Optional

object

See Compute#createImage.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const zone = compute.zone('us-central1-a');
const disk = zone.disk('disk1');
const image = compute.image('image-name');

image.create(disk, function(err, image, operation, apiResponse) {
  // `image` is an Image object.

  // `operation` is an Operation object that can be used to check the
  // status of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
image.create(disk).then(function(data) {
  const image = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

delete

delete(callback)

Delete the image.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

operation

Operation

An operation object that can be used to check the status of the request.

apiResponse

object

The full API response.

See also

Images: delete API Documentation

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const image = compute.image('image-name');

image.delete(function(err, operation, apiResponse) {
  // `operation` is an Operation object that can be used to check the status
  // of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
image.delete().then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

exists

exists(callback)

Check if the image exists.

Parameter

callback

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

exists

boolean

Whether the image exists or not.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const image = compute.image('image-name');

image.exists(function(err, exists) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
image.exists().then(function(data) {
  const exists = data[0];
});

get

get(options)

Get an image if it exists.

Parameter

options

Optional

options

Configuration object.

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const image = compute.image('image-name');

image.get(function(err, image, apiResponse) {
  // `image` is an Image object.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
image.get().then(function(data) {
  const image = data[0];
  const apiResponse = data[1];
});

getMetadata

getMetadata(callback)

Get the image's metadata.

Parameter

callback

Optional

function()

The callback function.

Values in callback have the following properties:

Parameter

err

error

An error returned while making this request.

Value may be null.

metadata

object

The image's metadata.

apiResponse

object

The full API response.

See also

Images: get API Documentation

Image Resource

Example

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const image = compute.image('image-name');

image.getMetadata(function(err, metadata, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
image.getMetadata().then(function(data) {
  const metadata = data[0];
  const apiResponse = data[1];
});