Property

id

new Image(compute, name)

Example

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

Parameters

Name Type Optional Description

compute

 

 

The parent Compute instance this Image belongs to.

name

 

 

Image name.

See also

Images Overview

Image Resource

Property

id  string

Methods

create(disk[, options])

Create an image.

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

Parameters

Name Type Optional Description

disk

Disk

 

See Compute#createImage.

options

object

Yes

See Compute#createImage.

delete([callback])

Delete the image.

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

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

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

exists(callback)

Check if the image exists.

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

Parameters

Name Type Optional Description

callback

function()

 

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

exists

boolean

 

Whether the image exists or not.

get([options])

Get an image if it exists.

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

Parameter

Name Type Optional Description

options

options

Yes

Configuration object.

getMetadata([callback])

Get the image's metadata.

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

Parameters

Name Type Optional Description

callback

function()

Yes

The callback function.

Values in callback have the following properties:

Name Type Optional Description

err

error

 

An error returned while making this request.

Value can be null.

metadata

object

 

The image's metadata.

apiResponse

object

 

The full API response.

See also

Images: get API Documentation

Image Resource