Skip to content

Commit 3d6ff28

Browse files
Merge pull request #1 from stephenplusplus/containership--subnetworks
tests refactor
2 parents df4ac67 + 54de7d6 commit 3d6ff28

11 files changed

Lines changed: 532 additions & 532 deletions

File tree

docs/toc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
}, {
102102
"title": "Snapshot",
103103
"type": "compute/snapshot"
104+
}, {
105+
"title": "Subnetwork",
106+
"type": "compute/subnetwork"
104107
}, {
105108
"title": "VM",
106109
"type": "compute/vm"

lib/compute/index.js

Lines changed: 115 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,122 +1162,6 @@ Compute.prototype.getFirewalls = function(options, callback) {
11621162
});
11631163
};
11641164

1165-
/**
1166-
* Get a list of subnetworks in this project.
1167-
*
1168-
* @resource [Subnetworks Overview]{@link https://cloud.google.com/compute/docs/subnetworks}
1169-
* @resource [Subnetworks: list API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks}
1170-
*
1171-
* @param {object=} options - Subnetwork search options.
1172-
* @param {boolean} options.autoPaginate - Have pagination handled
1173-
* automatically. Default: true.
1174-
* @param {string} options.filter - Search filter in the format of
1175-
* `{name} {comparison} {filterString}`.
1176-
* - **`name`**: the name of the field to compare
1177-
* - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
1178-
* (not equal)
1179-
* - **`filterString`**: the string to filter to. For string fields, this
1180-
* can be a regular expression.
1181-
* @param {number} options.maxApiCalls - Maximum number of API calls to make.
1182-
* @param {number} options.maxResults - Maximum number of subnetworks to return.
1183-
* @param {string} options.pageToken - A previously-returned page token
1184-
* representing part of the larger set of results to view.
1185-
* @param {function} callback - The callback function.
1186-
* @param {?error} callback.err - An error returned while making this request.
1187-
* @param {module:compute/subnetwork} callback.subnetworks - Subnetwork objects
1188-
* from your project.
1189-
* @param {?object} callback.nextQuery - If present, query with this object to
1190-
* check for more results.
1191-
* @param {object} callback.apiResponse - The full API response.
1192-
*
1193-
* @example
1194-
* gce.getSubnetworks(function(err, subnetworks) {
1195-
* // `subnetworks` is an array of `Subnetworks` objects.
1196-
* });
1197-
*
1198-
* //-
1199-
* // To control how many API requests are made and page through the results
1200-
* // manually, set `autoPaginate` to `false`.
1201-
* //-
1202-
* function callback(err, subnetworks, nextQuery, apiResponse) {
1203-
* if (nextQuery) {
1204-
* // More results exist.
1205-
* gce.getSubnetworks(nextQuery, callback);
1206-
* }
1207-
* }
1208-
*
1209-
* gce.getSubnetworks({
1210-
* autoPaginate: false
1211-
* }, callback);
1212-
*
1213-
* //-
1214-
* // Get the subnetworks from your project as a readable object stream.
1215-
* //-
1216-
* gce.getSubnetworks()
1217-
* .on('error', console.error)
1218-
* .on('data', function(subnetwork) {
1219-
* // `subnetwork` is a `Subnetwork` object.
1220-
* })
1221-
* .on('end', function() {
1222-
* // All subnetworks retrieved.
1223-
* });
1224-
*
1225-
* //-
1226-
* // If you anticipate many results, you can end a stream early to prevent
1227-
* // unnecessary processing and API requests.
1228-
* //-
1229-
* gce.getSubnetworks()
1230-
* .on('data', function(subnetwork) {
1231-
* this.end();
1232-
* });
1233-
*/
1234-
Compute.prototype.getSubnetworks = function(options, callback) {
1235-
var self = this;
1236-
1237-
if (is.fn(options)) {
1238-
callback = options;
1239-
options = {};
1240-
}
1241-
1242-
options = options || {};
1243-
1244-
this.request({
1245-
uri: '/aggregated/subnetworks',
1246-
qs: options
1247-
}, function(err, resp) {
1248-
1249-
if (err) {
1250-
callback(err, null, null, resp);
1251-
return;
1252-
}
1253-
1254-
var nextQuery = null;
1255-
1256-
if (resp.nextPageToken) {
1257-
nextQuery = extend({}, options, {
1258-
pageToken: resp.nextPageToken
1259-
});
1260-
}
1261-
1262-
var regions = resp.items || {};
1263-
1264-
var subnetworks = Object.keys(regions).reduce(function(acc, regionName) {
1265-
var region = self.region(regionName.replace('regions/', ''));
1266-
var subnetworks = regions[regionName].subnetworks || [];
1267-
1268-
subnetworks.forEach(function(subnetwork) {
1269-
var subnetworkInstance = region.subnetwork(subnetwork.name);
1270-
subnetworkInstance.metadata = subnetwork;
1271-
acc.push(subnetworkInstance);
1272-
});
1273-
1274-
return acc;
1275-
}, []);
1276-
1277-
callback(null, subnetworks, nextQuery, resp);
1278-
});
1279-
};
1280-
12811165
/**
12821166
* Get a list of health checks.
12831167
*
@@ -2024,6 +1908,121 @@ Compute.prototype.getSnapshots = function(options, callback) {
20241908
});
20251909
};
20261910

1911+
/**
1912+
* Get a list of subnetworks in this project.
1913+
*
1914+
* @resource [Subnetworks Overview]{@link https://cloud.google.com/compute/docs/subnetworks}
1915+
* @resource [Subnetworks: list API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks}
1916+
*
1917+
* @param {object=} options - Subnetwork search options.
1918+
* @param {boolean} options.autoPaginate - Have pagination handled
1919+
* automatically. Default: true.
1920+
* @param {string} options.filter - Search filter in the format of
1921+
* `{name} {comparison} {filterString}`.
1922+
* - **`name`**: the name of the field to compare
1923+
* - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
1924+
* (not equal)
1925+
* - **`filterString`**: the string to filter to. For string fields, this
1926+
* can be a regular expression.
1927+
* @param {number} options.maxApiCalls - Maximum number of API calls to make.
1928+
* @param {number} options.maxResults - Maximum number of subnetworks to return.
1929+
* @param {string} options.pageToken - A previously-returned page token
1930+
* representing part of the larger set of results to view.
1931+
* @param {function} callback - The callback function.
1932+
* @param {?error} callback.err - An error returned while making this request.
1933+
* @param {module:compute/subnetwork} callback.subnetworks - Subnetwork objects
1934+
* from your project.
1935+
* @param {?object} callback.nextQuery - If present, query with this object to
1936+
* check for more results.
1937+
* @param {object} callback.apiResponse - The full API response.
1938+
*
1939+
* @example
1940+
* gce.getSubnetworks(function(err, subnetworks) {
1941+
* // `subnetworks` is an array of `Subnetworks` objects.
1942+
* });
1943+
*
1944+
* //-
1945+
* // To control how many API requests are made and page through the results
1946+
* // manually, set `autoPaginate` to `false`.
1947+
* //-
1948+
* function callback(err, subnetworks, nextQuery, apiResponse) {
1949+
* if (nextQuery) {
1950+
* // More results exist.
1951+
* gce.getSubnetworks(nextQuery, callback);
1952+
* }
1953+
* }
1954+
*
1955+
* gce.getSubnetworks({
1956+
* autoPaginate: false
1957+
* }, callback);
1958+
*
1959+
* //-
1960+
* // Get the subnetworks from your project as a readable object stream.
1961+
* //-
1962+
* gce.getSubnetworks()
1963+
* .on('error', console.error)
1964+
* .on('data', function(subnetwork) {
1965+
* // `subnetwork` is a `Subnetwork` object.
1966+
* })
1967+
* .on('end', function() {
1968+
* // All subnetworks retrieved.
1969+
* });
1970+
*
1971+
* //-
1972+
* // If you anticipate many results, you can end a stream early to prevent
1973+
* // unnecessary processing and API requests.
1974+
* //-
1975+
* gce.getSubnetworks()
1976+
* .on('data', function(subnetwork) {
1977+
* this.end();
1978+
* });
1979+
*/
1980+
Compute.prototype.getSubnetworks = function(options, callback) {
1981+
var self = this;
1982+
1983+
if (is.fn(options)) {
1984+
callback = options;
1985+
options = {};
1986+
}
1987+
1988+
options = options || {};
1989+
1990+
this.request({
1991+
uri: '/aggregated/subnetworks',
1992+
qs: options
1993+
}, function(err, resp) {
1994+
if (err) {
1995+
callback(err, null, null, resp);
1996+
return;
1997+
}
1998+
1999+
var nextQuery = null;
2000+
2001+
if (resp.nextPageToken) {
2002+
nextQuery = extend({}, options, {
2003+
pageToken: resp.nextPageToken
2004+
});
2005+
}
2006+
2007+
var regions = resp.items || {};
2008+
2009+
var subnetworks = Object.keys(regions).reduce(function(acc, regionName) {
2010+
var region = self.region(regionName.replace('regions/', ''));
2011+
var subnetworks = regions[regionName].subnetworks || [];
2012+
2013+
subnetworks.forEach(function(subnetwork) {
2014+
var subnetworkInstance = region.subnetwork(subnetwork.name);
2015+
subnetworkInstance.metadata = subnetwork;
2016+
acc.push(subnetworkInstance);
2017+
});
2018+
2019+
return acc;
2020+
}, []);
2021+
2022+
callback(null, subnetworks, nextQuery, resp);
2023+
});
2024+
};
2025+
20272026
/**
20282027
* Get a list of virtual machine instances.
20292028
*

lib/compute/network.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ var ServiceObject = require('../common/service-object.js');
3737
*/
3838
var util = require('../common/util.js');
3939

40-
/**
41-
* @type {module:compute/region}
42-
* @private
43-
*/
44-
var Region = require('./region.js');
45-
4640
/*! Developer Documentation
4741
*
4842
* @param {module:compute} compute - The Compute module this network belongs to.
@@ -232,7 +226,8 @@ Network.prototype.createFirewall = function(name, config, callback) {
232226
* @param {module:compute/region|string} config.region - The region where the
233227
* Subnetwork resides.
234228
* @param {string} config.range - The range of internal addresses that
235-
* are owned by this subnetwork. [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range
229+
* are owned by this subnetwork.
230+
* [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) range
236231
* of addresses that are legal on this network. (Alias for
237232
* `config.ipCidrRange`)
238233
* @param {function} callback - The callback function.
@@ -244,10 +239,10 @@ Network.prototype.createFirewall = function(name, config, callback) {
244239
* @param {object} callback.apiResponse - The full API response.
245240
*
246241
* @example
247-
* var name = 'new-subnetwork-name';
242+
* var region = gce.region('us-east1');
248243
*
249244
* var config = {
250-
* region : 'us-east1',
245+
* region: region,
251246
* range: '10.0.1.0/24'
252247
* };
253248
*
@@ -256,25 +251,24 @@ Network.prototype.createFirewall = function(name, config, callback) {
256251
*
257252
* // `operation` is an Operation object that can be used to check the status
258253
* // of the request.
259-
* });
254+
* }
260255
*
261-
* network.createSubnetwork(name, config, callback);
256+
* network.createSubnetwork('new-subnetwork-name', config, callback);
262257
*/
263258
Network.prototype.createSubnetwork = function(name, config, callback) {
264259
config = extend({}, config, {
265260
network: this.formattedName
266261
});
267262

268-
var region;
263+
var region = config.region;
269264

270-
if (config.region instanceof Region) {
271-
region = config.region;
272-
} else {
273-
region = this.compute.region(config.region);
265+
if (is.string(region)) {
266+
region = this.compute.region(region);
274267
}
268+
275269
delete config.region;
276270

277-
return region.createSubnetwork(name, config, callback);
271+
region.createSubnetwork(name, config, callback);
278272
};
279273

280274
/**

0 commit comments

Comments
 (0)