Properties

new Snapshot(scope, name)

Example

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

//-
// Or, access through a disk.
//-
const disk = compute.zone('us-central1-a').disk('disk-name');
const snapshot = disk.snapshot('disk-snapshot-name');

Parameters

Name Type Optional Description

scope

 

 

The parent scope this snapshot belongs to. If it's a Disk, we expose the create methods.

name

 

 

Snapshot name.

See also

Snapshots Overview

Snapshot Resource

Properties

compute  Compute

id  string

name  string

Methods

create(config)

Create a snapshot.

This is only available if you accessed this object through Disk#snapshot.

Example

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

snapshot.create(function(err, snapshot, operation, apiResponse) {
  // `snapshot` is a Snapshot 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.
//-
snapshot.create().then(function(data) {
  const snapshot = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

Parameter

Name Type Optional Description

config

object

 

See Disk#createSnapshot.

delete([callback])

Delete the snapshot.

Example

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

snapshot.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.
//-
snapshot.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

Snapshots: delete API Documentation

exists(callback)

Check if the snapshot exists.

Example

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

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

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 snapshot exists or not.

get([options])

Get a snapshot if it exists.

If you access this snapshot through a Disk object, this can be used as a "get or create" method. Pass an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Example

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

snapshot.get(function(err, snapshot, apiResponse) {
  // `snapshot` is a Snapshot object.
});

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

Parameters

Name Type Optional Description

options

options

Yes

Configuration object.

Values in options have the following properties:

Name Type Optional Description

autoCreate

boolean

 

Automatically create the object if it does not exist. Default: false

getMetadata([callback])

Get the snapshot's metadata.

Example

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

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

//-
// If the callback is omitted, we'll return a Promise.
//-
snapshot.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 snapshot's metadata.

apiResponse

object

 

The full API response.

See also

Snapshot Resource

Snapshots: get API Documentation