Image

Image

An Image object allows you to interact with a Google Compute Engine image.

Constructor

new Image(compute, name)

Parameters:
Name Type Description
compute Compute

The parent Compute instance this Image belongs to.

name string

Image name.

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

Members

id :string

Source:

Methods

create(disk, optionsopt)

Create an image.

Parameters:
Name Type Attributes Description
disk Disk

See Compute#createImage.

options object <optional>

See Compute#createImage.

Source:
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(callbackopt)

Delete the image.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

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

apiResponse object

The full API response.

Source:
See:
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(callback)

Check if the image exists.

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the image exists or not.

Source:
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(optionsopt)

Get an image if it exists.

Parameters:
Name Type Attributes Description
options options <optional>

Configuration object.

Source:
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(callbackopt)

Get the image's metadata.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The image's metadata.

apiResponse object

The full API response.

Source:
See:
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];
});