Properties

new Operation(scope, name)

Example

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

//-
// Reference a global operation.
//-
const operation = compute.operation('operation-id');

//-
// Reference a region operation.
//-
const region = compute.region('us-central1');
const operation = region.operation('operation-id');

//-
// Reference a zone operation.
//-
const zone = compute.zone('us-central1-a');
const operation = zone.operation('operation-id');

//-
// All operations are event emitters. The status of each operation is polled
// continuously, starting only after you register a "complete" listener.
//-
operation.on('complete', function(metadata) {
  // The operation is complete.
});

//-
// You can register a listener to monitor when the operation begins running.
//-
operation.on('running', function(metadata) {
  // The operation is running.
});

//-
// Be sure to register an error handler as well to catch any issues which
// impeded the operation.
//-
operation.on('error', function(err) {
  // An error occurred during the operation.
});

//-
// To force the Operation object to stop polling for updates, simply remove
// any "complete" listeners you've registered.
//
// The easiest way to do this is with `removeAllListeners()`.
//-
operation.removeAllListeners();

Parameters

Name Type Optional Description

scope

 

 

The scope of the operation: a Compute, Zone, or Region object.

name

 

 

Operation name.

Properties

id  string

name  string

Methods

delete([callback])

Delete the operation.

Example

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

operation.delete(function(err, apiResponse) {});

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

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.

apiResponse

object

 

The full API response.

See also

GlobalOperations: delete API Documentation

RegionOperations: delete API Documentation

ZoneOperations: delete API Documentation

exists(callback)

Check if the operation exists.

Example

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

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

//-
// If the callback is omitted, we'll return a Promise.
//-
operation.exists().then(function(data) {
  var 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 operation exists or not.

get()

Get an operation if it exists.

Example

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

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

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

getMetadata([callback])

Get the operation's metadata. For a detailed description of metadata see Operation resource.

Example

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

operation.getMetadata(function(err, metadata, apiResponse) {
  // `metadata.error`: Contains errors if the operation failed.
  // `metadata.warnings`: Contains warnings.
});

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

GlobalOperations: get API Documentation

RegionOperations: get API Documentation

ZoneOperations: get API Documentation