Properties

new Disk(zone, name)

Example

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

Parameters

Name Type Optional Description

zone

 

 

name

 

 

See also

Disks Overview

Disk Resource

Properties

formattedName  string

id  string

name  string

zone  Zone

The parent Zone instance of this Disk instance.

Methods

create(config)

Create a persistent disk.

Example

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

const config = {
  // ...
};

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

Parameter

Name Type Optional Description

config

object

 

See {Zone#createDisk}.

createSnapshot(name[, options], callback)

Create a snapshot of a disk.

Example

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

function callback(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.
}

disk.createSnapshot('new-snapshot-name', callback);

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

Parameters

Name Type Optional Description

name

string

 

Name of the snapshot.

options

object

Yes

See the Disks: createSnapshot request body.

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.

snapshot

Snapshot

 

The created Snapshot object.

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 Overview

Disks: createSnapshot API Documentation

delete([callback])

Delete the disk.

Example

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

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

Disks: delete API Documentation

exists(callback)

Check if the disk exists.

Example

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

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

//-
// If the callback is omitted, we'll return a Promise.
//-
disk.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 disk exists or not.

get([options])

Get a disk if it exists.

You may optionally use this to "get or create" an object by providing 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 zone = compute.zone('us-central1-a');
const disk = zone.disk('disk1');

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

//-
// If the callback is omitted, we'll return a Promise.
//-
disk.get().then(function(data) {
  const disk = 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 disk's metadata.

Example

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

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

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

apiResponse

object

 

The full API response.

See also

Disk Resource

Disks: get API Documentation

snapshot(name) → Snapshot

Get a reference to a snapshot from this disk.

Example

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

Parameter

Name Type Optional Description

name

string

 

Name of the snapshot.

See also

Snapshots Overview

Returns

Snapshot