Skip to content

Commit

Permalink
Add zone and region entities to provide a more hierarchical structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jul 16, 2015
1 parent 785d146 commit be9ce31
Show file tree
Hide file tree
Showing 5 changed files with 785 additions and 399 deletions.
29 changes: 14 additions & 15 deletions lib/compute/disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,38 @@ var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';
* Create a Disk object to interact with a Google Compute Engine disk.
*
* @constructor
* @alias module:compute/disk
* @alias module:zone/disk
*
* @throws {Error} if a disk name or a zone are not provided.
*
* @param {module:compute} compute - The Google Compute Engine instance this
* @param {module:zone} zone - The Google Compute Engine zone this
* disk belongs to.
* @param {string} name - Name of the disk.
* @param {string} zone - Zone to which the disk belongs.
* @param {number=} sizeGb - Size of the disk in GB.
* @param {object=} metadata - Disk metadata.
*
* @example
* var gcloud = require('gcloud');
*
* var compute = gcloud.compute({
* projectId: 'grape-spaceship-123'
* var gcloud = require('gcloud')({
* keyFilename: '/path/to/keyfile.json'
* });
*
* var disk = compute.disk('disk-1', 'europe-west1-b');
* var compute = gcloud.compute();
*
* var myZone = compute.zone('zone-name');
*
* var disk = myZone.disk('disk1');
*/
function Disk(compute, name, zone, sizeGb, metadata) {
function Disk(zone, name, sizeGb, metadata) {
this.name = name;
this.zone = zone;

if (!this.name) {
if (!util.is(this.name, 'string')) {
throw new Error('A name is needed to use Google Cloud Compute Disk.');
}
if (!this.zone) {
throw new Error('A zone is needed to use Google Cloud Compute Disk.');
}

this.sizeGb = sizeGb;
this.compute = compute;
this.metadata = metadata;
}

Expand Down Expand Up @@ -132,16 +131,16 @@ Disk.prototype.makeReq_ = function(method, path, query, body, callback) {
var reqOpts = {
method: method,
qs: query,
uri: COMPUTE_BASE_URL + this.compute.projectId +
'/zones/' + this.zone +
uri: COMPUTE_BASE_URL + this.zone.compute.projectId +
'/zones/' + this.zone.name +
'/disks/' + this.name + path
};

if (body) {
reqOpts.json = body;
}

this.compute.makeAuthorizedRequest_(reqOpts, callback);
this.zone.compute.makeAuthorizedRequest_(reqOpts, callback);
};

module.exports = Disk;
Loading

0 comments on commit be9ce31

Please sign in to comment.