Skip to content

Commit

Permalink
Merge pull request #1 from stephenplusplus/containership--subnetworks
Browse files Browse the repository at this point in the history
tests refactor
  • Loading branch information
ashleyschuett authored Jul 20, 2016
2 parents df4ac67 + 54de7d6 commit 3d6ff28
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 532 deletions.
3 changes: 3 additions & 0 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
}, {
"title": "Snapshot",
"type": "compute/snapshot"
}, {
"title": "Subnetwork",
"type": "compute/subnetwork"
}, {
"title": "VM",
"type": "compute/vm"
Expand Down
231 changes: 115 additions & 116 deletions lib/compute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,122 +1162,6 @@ Compute.prototype.getFirewalls = function(options, callback) {
});
};

/**
* Get a list of subnetworks in this project.
*
* @resource [Subnetworks Overview]{@link https://cloud.google.com/compute/docs/subnetworks}
* @resource [Subnetworks: list API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks}
*
* @param {object=} options - Subnetwork search options.
* @param {boolean} options.autoPaginate - Have pagination handled
* automatically. Default: true.
* @param {string} options.filter - Search filter in the format of
* `{name} {comparison} {filterString}`.
* - **`name`**: the name of the field to compare
* - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
* (not equal)
* - **`filterString`**: the string to filter to. For string fields, this
* can be a regular expression.
* @param {number} options.maxApiCalls - Maximum number of API calls to make.
* @param {number} options.maxResults - Maximum number of subnetworks to return.
* @param {string} options.pageToken - A previously-returned page token
* representing part of the larger set of results to view.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {module:compute/subnetwork} callback.subnetworks - Subnetwork objects
* from your project.
* @param {?object} callback.nextQuery - If present, query with this object to
* check for more results.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* gce.getSubnetworks(function(err, subnetworks) {
* // `subnetworks` is an array of `Subnetworks` objects.
* });
*
* //-
* // To control how many API requests are made and page through the results
* // manually, set `autoPaginate` to `false`.
* //-
* function callback(err, subnetworks, nextQuery, apiResponse) {
* if (nextQuery) {
* // More results exist.
* gce.getSubnetworks(nextQuery, callback);
* }
* }
*
* gce.getSubnetworks({
* autoPaginate: false
* }, callback);
*
* //-
* // Get the subnetworks from your project as a readable object stream.
* //-
* gce.getSubnetworks()
* .on('error', console.error)
* .on('data', function(subnetwork) {
* // `subnetwork` is a `Subnetwork` object.
* })
* .on('end', function() {
* // All subnetworks retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* gce.getSubnetworks()
* .on('data', function(subnetwork) {
* this.end();
* });
*/
Compute.prototype.getSubnetworks = function(options, callback) {
var self = this;

if (is.fn(options)) {
callback = options;
options = {};
}

options = options || {};

this.request({
uri: '/aggregated/subnetworks',
qs: options
}, function(err, resp) {

if (err) {
callback(err, null, null, resp);
return;
}

var nextQuery = null;

if (resp.nextPageToken) {
nextQuery = extend({}, options, {
pageToken: resp.nextPageToken
});
}

var regions = resp.items || {};

var subnetworks = Object.keys(regions).reduce(function(acc, regionName) {
var region = self.region(regionName.replace('regions/', ''));
var subnetworks = regions[regionName].subnetworks || [];

subnetworks.forEach(function(subnetwork) {
var subnetworkInstance = region.subnetwork(subnetwork.name);
subnetworkInstance.metadata = subnetwork;
acc.push(subnetworkInstance);
});

return acc;
}, []);

callback(null, subnetworks, nextQuery, resp);
});
};

/**
* Get a list of health checks.
*
Expand Down Expand Up @@ -2024,6 +1908,121 @@ Compute.prototype.getSnapshots = function(options, callback) {
});
};

/**
* Get a list of subnetworks in this project.
*
* @resource [Subnetworks Overview]{@link https://cloud.google.com/compute/docs/subnetworks}
* @resource [Subnetworks: list API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks}
*
* @param {object=} options - Subnetwork search options.
* @param {boolean} options.autoPaginate - Have pagination handled
* automatically. Default: true.
* @param {string} options.filter - Search filter in the format of
* `{name} {comparison} {filterString}`.
* - **`name`**: the name of the field to compare
* - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
* (not equal)
* - **`filterString`**: the string to filter to. For string fields, this
* can be a regular expression.
* @param {number} options.maxApiCalls - Maximum number of API calls to make.
* @param {number} options.maxResults - Maximum number of subnetworks to return.
* @param {string} options.pageToken - A previously-returned page token
* representing part of the larger set of results to view.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {module:compute/subnetwork} callback.subnetworks - Subnetwork objects
* from your project.
* @param {?object} callback.nextQuery - If present, query with this object to
* check for more results.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* gce.getSubnetworks(function(err, subnetworks) {
* // `subnetworks` is an array of `Subnetworks` objects.
* });
*
* //-
* // To control how many API requests are made and page through the results
* // manually, set `autoPaginate` to `false`.
* //-
* function callback(err, subnetworks, nextQuery, apiResponse) {
* if (nextQuery) {
* // More results exist.
* gce.getSubnetworks(nextQuery, callback);
* }
* }
*
* gce.getSubnetworks({
* autoPaginate: false
* }, callback);
*
* //-
* // Get the subnetworks from your project as a readable object stream.
* //-
* gce.getSubnetworks()
* .on('error', console.error)
* .on('data', function(subnetwork) {
* // `subnetwork` is a `Subnetwork` object.
* })
* .on('end', function() {
* // All subnetworks retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* gce.getSubnetworks()
* .on('data', function(subnetwork) {
* this.end();
* });
*/
Compute.prototype.getSubnetworks = function(options, callback) {
var self = this;

if (is.fn(options)) {
callback = options;
options = {};
}

options = options || {};

this.request({
uri: '/aggregated/subnetworks',
qs: options
}, function(err, resp) {
if (err) {
callback(err, null, null, resp);
return;
}

var nextQuery = null;

if (resp.nextPageToken) {
nextQuery = extend({}, options, {
pageToken: resp.nextPageToken
});
}

var regions = resp.items || {};

var subnetworks = Object.keys(regions).reduce(function(acc, regionName) {
var region = self.region(regionName.replace('regions/', ''));
var subnetworks = regions[regionName].subnetworks || [];

subnetworks.forEach(function(subnetwork) {
var subnetworkInstance = region.subnetwork(subnetwork.name);
subnetworkInstance.metadata = subnetwork;
acc.push(subnetworkInstance);
});

return acc;
}, []);

callback(null, subnetworks, nextQuery, resp);
});
};

/**
* Get a list of virtual machine instances.
*
Expand Down
28 changes: 11 additions & 17 deletions lib/compute/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ var ServiceObject = require('../common/service-object.js');
*/
var util = require('../common/util.js');

/**
* @type {module:compute/region}
* @private
*/
var Region = require('./region.js');

/*! Developer Documentation
*
* @param {module:compute} compute - The Compute module this network belongs to.
Expand Down Expand Up @@ -232,7 +226,8 @@ Network.prototype.createFirewall = function(name, config, callback) {
* @param {module:compute/region|string} config.region - The region where the
* Subnetwork resides.
* @param {string} config.range - The range of internal addresses that
* are owned by this subnetwork. [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range
* are owned by this subnetwork.
* [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range
* of addresses that are legal on this network. (Alias for
* `config.ipCidrRange`)
* @param {function} callback - The callback function.
Expand All @@ -244,10 +239,10 @@ Network.prototype.createFirewall = function(name, config, callback) {
* @param {object} callback.apiResponse - The full API response.
*
* @example
* var name = 'new-subnetwork-name';
* var region = gce.region('us-east1');
*
* var config = {
* region : 'us-east1',
* region: region,
* range: '10.0.1.0/24'
* };
*
Expand All @@ -256,25 +251,24 @@ Network.prototype.createFirewall = function(name, config, callback) {
*
* // `operation` is an Operation object that can be used to check the status
* // of the request.
* });
* }
*
* network.createSubnetwork(name, config, callback);
* network.createSubnetwork('new-subnetwork-name', config, callback);
*/
Network.prototype.createSubnetwork = function(name, config, callback) {
config = extend({}, config, {
network: this.formattedName
});

var region;
var region = config.region;

if (config.region instanceof Region) {
region = config.region;
} else {
region = this.compute.region(config.region);
if (is.string(region)) {
region = this.compute.region(region);
}

delete config.region;

return region.createSubnetwork(name, config, callback);
region.createSubnetwork(name, config, callback);
};

/**
Expand Down
Loading

0 comments on commit 3d6ff28

Please sign in to comment.