Skip to content

Commit

Permalink
Merge pull request #792 from stephenplusplus/spp--compute
Browse files Browse the repository at this point in the history
Support Google Compute Engine
  • Loading branch information
stephenplusplus committed Aug 21, 2015
2 parents 990f196 + 3b923c9 commit f10000f
Show file tree
Hide file tree
Showing 29 changed files with 10,204 additions and 2 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This client supports the following Google Cloud Platform services:
* [Google Cloud DNS](#google-cloud-dns)
* [Google Cloud Pub/Sub](#google-cloud-pubsub)
* [Google Cloud Storage](#google-cloud-storage)
* [Google Compute Engine](#google-compute-engine)
* [Google Cloud Search](#google-cloud-search-alpha) (Alpha)

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


## Google Compute Engine

- [API Documentation][gcloud-compute-docs]
- [Official Documentation][cloud-compute-docs]

#### Preview

```js
var gcloud = require('gcloud');

// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).

var gce = gcloud.compute({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});

// Create a new VM using the latest OS image of your choice.
var zone = gce.zone('us-central1-a');
var name = 'ubuntu-http';

zone.createVM(name, { os: 'ubuntu' }, function(err, vm, operation) {
// `operation` lets you check the status of long-running tasks.

operation.onComplete(function(err, metadata) {
if (!err) {
// Virtual machine created!
}
});
});
```


## Google Cloud Search (Alpha)

> 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.
Expand Down Expand Up @@ -357,6 +392,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
[gcloud-homepage]: https://googlecloudplatform.github.io/gcloud-node/
[gcloud-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs
[gcloud-bigquery-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/bigquery
[gcloud-compute-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/compute
[gcloud-datastore-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/datastore
[gcloud-dns-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/dns
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub
Expand All @@ -376,6 +412,8 @@ Apache 2.0 - See [COPYING](COPYING) for more information.

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

[cloud-compute-docs]: https://cloud.google.com/compute/docs

[cloud-datastore-docs]: https://cloud.google.com/datastore/docs
[cloud-datastore-activation]: https://cloud.google.com/datastore/docs/activate

Expand Down
Empty file.
7 changes: 7 additions & 0 deletions docs/site/components/docs/compute-overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h3>Compute Engine Overview</h3>
<p>
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.
</p>
<p>
To learn more about Compute Engine, see <a href="https://cloud.google.com/compute/docs">What is Google Compute Engine?</a>
</p>
48 changes: 47 additions & 1 deletion docs/site/components/docs/docs-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,49 @@ angular.module('gcloud.docs')
]
},

compute: {
title: 'Compute',
_url: '{baseUrl}/compute',
pages: [
{
title: 'Address',
url: '/address'
},
{
title: 'Disk',
url: '/disk'
},
{
title: 'Firewall',
url: '/firewall'
},
{
title: 'Network',
url: '/network'
},
{
title: 'Operation',
url: '/operation'
},
{
title: 'Region',
url: '/region'
},
{
title: 'Snapshot',
url: '/snapshot'
},
{
title: 'VM',
url: '/vm'
},
{
title: 'Zone',
url: '/zone'
}
]
},

datastore: {
title: 'Datastore',
_url: '{baseUrl}/datastore',
Expand Down Expand Up @@ -180,6 +223,9 @@ angular.module('gcloud.docs')
'>=0.16.0': ['search'],

// introduce dns api.
'>=0.18.0': ['dns']
'>=0.18.0': ['dns'],

// introduce compute api.
'>=0.20.0': ['compute']
}
});
2 changes: 1 addition & 1 deletion docs/site/components/docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h3 class="sub-heading">
</article>
<hr>

<article ng-repeat="service in ['bigquery', 'datastore', 'dns', 'pubsub', 'search', 'storage']"
<article ng-repeat="service in ['bigquery', 'compute', 'datastore', 'dns', 'pubsub', 'search', 'storage']"
ng-if="isActiveDoc(service)"
ng-include="'site/components/docs/' + service + '-overview.html'">
</article>
Expand Down
145 changes: 145 additions & 0 deletions lib/compute/address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*!
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*!
* @module compute/address
*/

'use strict';

/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util.js');

/*! Developer Documentation
*
* @param {module:region} region - Region this address belongs to.
* @param {string} name - The name of the address.
*/
/**
* An Address object allows you to interact with a Google Compute Engine
* address.
*
* @resource [Instances and Networks]{@link https://cloud.google.com/compute/docs/instances-and-network}
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses} *
*
* @constructor
* @alias module:compute/address
*
* @example
* var gcloud = require('gcloud')({
* keyFilename: '/path/to/keyfile.json',
* projectId: 'grape-spaceship-123'
* });
*
* var gce = gcloud.compute();
*
* var region = gce.region('region-name');
*
* var address = region.address('address1');
*/
function Address(region, name) {
this.region = region;
this.name = name;
this.metadata = {};
}

/**
* Delete the address.
*
* @resource [Addresses: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/delete}
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {module:compute/operation} callback.operation - An operation object
* that can be used to check the status of the request.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* address.delete(function(err, operation, apiResponse) {
* // `operation` is an Operation object that can be used to check the status
* // of the request.
* });
*/
Address.prototype.delete = function(callback) {
callback = callback || util.noop;

var region = this.region;

this.makeReq_('DELETE', '', null, null, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}

var operation = region.operation(resp.name);
operation.metadata = resp;

callback(null, operation, resp);
});
};

/**
* Get the metadata of this address.
*
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses}
* @resource [Addresses: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/get}
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request
* @param {object} callback.metadata - The address's metadata.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* address.getMetadata(function(err, metadata, apiResponse) {});
*/
Address.prototype.getMetadata = function(callback) {
callback = callback || util.noop;

var self = this;

this.makeReq_('GET', '', null, null, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}

self.metadata = resp;

callback(null, self.metadata, resp);
});
};

/**
* Make a new request object from the provided arguments and wrap the callback
* to intercept non-successful responses.
*
* @private
*
* @param {string} method - Action.
* @param {string} path - Request path.
* @param {*} query - Request query object.
* @param {*} body - Request body contents.
* @param {function} callback - The callback function.
*/
Address.prototype.makeReq_ = function(method, path, query, body, callback) {
path = '/addresses/' + this.name + path;
this.region.makeReq_(method, path, query, body, callback);
};

module.exports = Address;
Loading

0 comments on commit f10000f

Please sign in to comment.