Skip to content

Commit 3b923c9

Browse files
Refactor and test Compute Engine
1 parent d1addf1 commit 3b923c9

30 files changed

Lines changed: 8513 additions & 1976 deletions

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This client supports the following Google Cloud Platform services:
1515
* [Google Cloud DNS](#google-cloud-dns)
1616
* [Google Cloud Pub/Sub](#google-cloud-pubsub)
1717
* [Google Cloud Storage](#google-cloud-storage)
18+
* [Google Compute Engine](#google-compute-engine)
1819
* [Google Cloud Search](#google-cloud-search-alpha) (Alpha)
1920

2021
If you need support for other Google APIs, check out the [Google Node.js API Client library][googleapis].
@@ -300,6 +301,40 @@ localReadStream.pipe(remoteWriteStream);
300301
```
301302

302303

304+
## Google Compute Engine
305+
306+
- [API Documentation][gcloud-compute-docs]
307+
- [Official Documentation][cloud-compute-docs]
308+
309+
#### Preview
310+
311+
```js
312+
var gcloud = require('gcloud');
313+
314+
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
315+
// global basis (see Authorization section above).
316+
317+
var gce = gcloud.compute({
318+
projectId: 'my-project',
319+
keyFilename: '/path/to/keyfile.json'
320+
});
321+
322+
// Create a new VM using the latest OS image of your choice.
323+
var zone = gce.zone('us-central1-a');
324+
var name = 'ubuntu-http';
325+
326+
zone.createVM(name, { os: 'ubuntu' }, function(err, vm, operation) {
327+
// `operation` lets you check the status of long-running tasks.
328+
329+
operation.onComplete(function(err, metadata) {
330+
if (!err) {
331+
// Virtual machine created!
332+
}
333+
});
334+
});
335+
```
336+
337+
303338
## Google Cloud Search (Alpha)
304339

305340
> This is an *Alpha* release of Google Cloud Search. This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
@@ -357,6 +392,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
357392
[gcloud-homepage]: https://googlecloudplatform.github.io/gcloud-node/
358393
[gcloud-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs
359394
[gcloud-bigquery-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/bigquery
395+
[gcloud-compute-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/compute
360396
[gcloud-datastore-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/datastore
361397
[gcloud-dns-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/dns
362398
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub
@@ -376,6 +412,8 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
376412

377413
[cloud-bigquery-docs]: https://cloud.google.com/bigquery/what-is-bigquery
378414

415+
[cloud-compute-docs]: https://cloud.google.com/compute/docs
416+
379417
[cloud-datastore-docs]: https://cloud.google.com/datastore/docs
380418
[cloud-datastore-activation]: https://cloud.google.com/datastore/docs/activate
381419

docs/json/master/compute/.gitkeep

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h3>Compute Engine Overview</h3>
2+
<p>
3+
The object returned from <code>gcloud.compute</code> gives you complete control of your Compute Engine virtual machines, disks, networks, snapshots, addresses, firewalls, and more.
4+
</p>
5+
<p>
6+
To learn more about Compute Engine, see <a href="https://cloud.google.com/compute/docs">What is Google Compute Engine?</a>
7+
</p>

docs/site/components/docs/docs-values.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,49 @@ angular.module('gcloud.docs')
3939
]
4040
},
4141

42+
compute: {
43+
title: 'Compute',
44+
_url: '{baseUrl}/compute',
45+
pages: [
46+
{
47+
title: 'Address',
48+
url: '/address'
49+
},
50+
{
51+
title: 'Disk',
52+
url: '/disk'
53+
},
54+
{
55+
title: 'Firewall',
56+
url: '/firewall'
57+
},
58+
{
59+
title: 'Network',
60+
url: '/network'
61+
},
62+
{
63+
title: 'Operation',
64+
url: '/operation'
65+
},
66+
{
67+
title: 'Region',
68+
url: '/region'
69+
},
70+
{
71+
title: 'Snapshot',
72+
url: '/snapshot'
73+
},
74+
{
75+
title: 'VM',
76+
url: '/vm'
77+
},
78+
{
79+
title: 'Zone',
80+
url: '/zone'
81+
}
82+
]
83+
},
84+
4285
datastore: {
4386
title: 'Datastore',
4487
_url: '{baseUrl}/datastore',
@@ -180,6 +223,9 @@ angular.module('gcloud.docs')
180223
'>=0.16.0': ['search'],
181224

182225
// introduce dns api.
183-
'>=0.18.0': ['dns']
226+
'>=0.18.0': ['dns'],
227+
228+
// introduce compute api.
229+
'>=0.20.0': ['compute']
184230
}
185231
});

docs/site/components/docs/docs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h3 class="sub-heading">
4444
</article>
4545
<hr>
4646

47-
<article ng-repeat="service in ['bigquery', 'datastore', 'dns', 'pubsub', 'search', 'storage']"
47+
<article ng-repeat="service in ['bigquery', 'compute', 'datastore', 'dns', 'pubsub', 'search', 'storage']"
4848
ng-if="isActiveDoc(service)"
4949
ng-include="'site/components/docs/' + service + '-overview.html'">
5050
</article>

lib/compute/address.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright 2014 Google Inc. All Rights Reserved.
2+
* Copyright 2015 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,85 +26,101 @@
2626
*/
2727
var util = require('../common/util.js');
2828

29-
/**
30-
* Create an Address object to interact with a Google Compute Engine address.
29+
/*! Developer Documentation
3130
*
32-
* @constructor
33-
* @alias module:region/address
31+
* @param {module:region} region - Region this address belongs to.
32+
* @param {string} name - The name of the address.
33+
*/
34+
/**
35+
* An Address object allows you to interact with a Google Compute Engine
36+
* address.
3437
*
35-
* @throws {Error} if an address name or a region are not provided.
38+
* @resource [Instances and Networks]{@link https://cloud.google.com/compute/docs/instances-and-network}
39+
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses} *
3640
*
37-
* @param {module:region} region - The Google Compute Engine region this
38-
* address belongs to.
39-
* @param {string} name - The name of the address.
40-
* @param {object=} metadata - Address metadata.
41+
* @constructor
42+
* @alias module:compute/address
4143
*
4244
* @example
4345
* var gcloud = require('gcloud')({
44-
* keyFilename: '/path/to/keyfile.json'
46+
* keyFilename: '/path/to/keyfile.json',
47+
* projectId: 'grape-spaceship-123'
4548
* });
4649
*
47-
* var compute = gcloud.compute();
50+
* var gce = gcloud.compute();
4851
*
49-
* var myRegion = compute.region('region-name');
52+
* var region = gce.region('region-name');
5053
*
51-
* var address = myRegion.address('address1');
54+
* var address = region.address('address1');
5255
*/
53-
function Address(region, name, metadata) {
56+
function Address(region, name) {
5457
this.region = region;
5558
this.name = name;
56-
this.metadata = metadata;
57-
58-
if (!util.is(this.name, 'string')) {
59-
throw new Error('A name is needed to use a Compute Engine Address.');
60-
}
61-
if (!this.region) {
62-
throw new Error('A region is needed to use a Compute Engine Address.');
63-
}
59+
this.metadata = {};
6460
}
6561

6662
/**
6763
* Delete the address.
6864
*
69-
* @param {function} callback - The callback function.
65+
* @resource [Addresses: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/delete}
66+
*
67+
* @param {function=} callback - The callback function.
68+
* @param {?error} callback.err - An error returned while making this request.
69+
* @param {module:compute/operation} callback.operation - An operation object
70+
* that can be used to check the status of the request.
71+
* @param {object} callback.apiResponse - The full API response.
7072
*
7173
* @example
72-
* address.delete(function(err, operation) {
73-
* // `operation` is an Operation object and can be used to check the status
74-
* // of address deletion.
74+
* address.delete(function(err, operation, apiResponse) {
75+
* // `operation` is an Operation object that can be used to check the status
76+
* // of the request.
7577
* });
7678
*/
7779
Address.prototype.delete = function(callback) {
7880
callback = callback || util.noop;
81+
7982
var region = this.region;
80-
this.makeReq_('DELETE', '', null, true, function(err, resp) {
83+
84+
this.makeReq_('DELETE', '', null, null, function(err, resp) {
8185
if (err) {
82-
callback(err);
86+
callback(err, null, resp);
8387
return;
8488
}
89+
8590
var operation = region.operation(resp.name);
8691
operation.metadata = resp;
87-
callback(null, operation);
92+
93+
callback(null, operation, resp);
8894
});
8995
};
9096

9197
/**
92-
* Get the address' metadata.
98+
* Get the metadata of this address.
99+
*
100+
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses}
101+
* @resource [Addresses: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/get}
93102
*
94103
* @param {function=} callback - The callback function.
104+
* @param {?error} callback.err - An error returned while making this request
105+
* @param {object} callback.metadata - The address's metadata.
106+
* @param {object} callback.apiResponse - The full API response.
95107
*
96108
* @example
97109
* address.getMetadata(function(err, metadata, apiResponse) {});
98110
*/
99111
Address.prototype.getMetadata = function(callback) {
100112
callback = callback || util.noop;
113+
101114
var self = this;
115+
102116
this.makeReq_('GET', '', null, null, function(err, resp) {
103117
if (err) {
104-
callback(err);
118+
callback(err, null, resp);
105119
return;
106120
}
121+
107122
self.metadata = resp;
123+
108124
callback(null, self.metadata, resp);
109125
});
110126
};
@@ -126,4 +142,4 @@ Address.prototype.makeReq_ = function(method, path, query, body, callback) {
126142
this.region.makeReq_(method, path, query, body, callback);
127143
};
128144

129-
module.exports = Address;
145+
module.exports = Address;

0 commit comments

Comments
 (0)