Image
Source: image.
An Image object allows you to interact with a Google Compute Engine image.
Property
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
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 |
|
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
|
- See also
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
|
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
|