Skip to content

Commit be9ce31

Browse files
committed
Add zone and region entities to provide a more hierarchical structure
1 parent 785d146 commit be9ce31

5 files changed

Lines changed: 785 additions & 399 deletions

File tree

lib/compute/disk.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,38 @@ var COMPUTE_BASE_URL = 'https://www.googleapis.com/compute/v1/projects/';
3636
* Create a Disk object to interact with a Google Compute Engine disk.
3737
*
3838
* @constructor
39-
* @alias module:compute/disk
39+
* @alias module:zone/disk
4040
*
4141
* @throws {Error} if a disk name or a zone are not provided.
4242
*
43-
* @param {module:compute} compute - The Google Compute Engine instance this
43+
* @param {module:zone} zone - The Google Compute Engine zone this
4444
* disk belongs to.
45-
* @param {string} name - Name of the disk.
46-
* @param {string} zone - Zone to which the disk belongs.
4745
* @param {number=} sizeGb - Size of the disk in GB.
4846
* @param {object=} metadata - Disk metadata.
4947
*
5048
* @example
51-
* var gcloud = require('gcloud');
52-
*
53-
* var compute = gcloud.compute({
54-
* projectId: 'grape-spaceship-123'
49+
* var gcloud = require('gcloud')({
50+
* keyFilename: '/path/to/keyfile.json'
5551
* });
5652
*
57-
* var disk = compute.disk('disk-1', 'europe-west1-b');
53+
* var compute = gcloud.compute();
54+
*
55+
* var myZone = compute.zone('zone-name');
56+
*
57+
* var disk = myZone.disk('disk1');
5858
*/
59-
function Disk(compute, name, zone, sizeGb, metadata) {
59+
function Disk(zone, name, sizeGb, metadata) {
6060
this.name = name;
6161
this.zone = zone;
6262

63-
if (!this.name) {
63+
if (!util.is(this.name, 'string')) {
6464
throw new Error('A name is needed to use Google Cloud Compute Disk.');
6565
}
6666
if (!this.zone) {
6767
throw new Error('A zone is needed to use Google Cloud Compute Disk.');
6868
}
6969

7070
this.sizeGb = sizeGb;
71-
this.compute = compute;
7271
this.metadata = metadata;
7372
}
7473

@@ -132,16 +131,16 @@ Disk.prototype.makeReq_ = function(method, path, query, body, callback) {
132131
var reqOpts = {
133132
method: method,
134133
qs: query,
135-
uri: COMPUTE_BASE_URL + this.compute.projectId +
136-
'/zones/' + this.zone +
134+
uri: COMPUTE_BASE_URL + this.zone.compute.projectId +
135+
'/zones/' + this.zone.name +
137136
'/disks/' + this.name + path
138137
};
139138

140139
if (body) {
141140
reqOpts.json = body;
142141
}
143142

144-
this.compute.makeAuthorizedRequest_(reqOpts, callback);
143+
this.zone.compute.makeAuthorizedRequest_(reqOpts, callback);
145144
};
146145

147146
module.exports = Disk;

0 commit comments

Comments
 (0)