@@ -37,6 +37,12 @@ var ServiceObject = require('../common/service-object.js');
3737 */
3838var util = require ( '../common/util.js' ) ;
3939
40+ /**
41+ * @type {module:compute/region }
42+ * @private
43+ */
44+ var Region = require ( './region.js' ) ;
45+
4046/*! Developer Documentation
4147 *
4248 * @param {module:compute } compute - The Compute module this network belongs to.
@@ -214,6 +220,137 @@ Network.prototype.createFirewall = function(name, config, callback) {
214220 this . compute . createFirewall ( name , config , callback ) ;
215221} ;
216222
223+ /**
224+ * Create a subnetwork in this network.
225+ *
226+ * @resource [Subnetwork Resource]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks#resource}
227+ * @resource [Subnetwork: insert API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/subnetworks/insert}
228+ *
229+ * @param {string } name - Name of the subnetwork.
230+ * @param {object } config - See a
231+ * [Subnetwork resource](https://cloud.google.com/compute/docs/reference/v1/subnetworks#resource).
232+ * @param {string= } config.description - An optional description of this
233+ * resource. Provide this property when you create the resource.
234+ * @param {string } config.ipCidrRange - The range of internal addresses that
235+ * are owned by this subnetwork. Provide this property when you create the
236+ * subnetwork. For example, 10.0.0.0/8 or 192.168.0.0/16. Ranges must be
237+ * unique and non-overlapping within a network.
238+ * @param {string } config.region - URL of the region where the Subnetwork
239+ * resides.
240+ * @param {function } callback - The callback function.
241+ * @param {?error } callback.err - An error returned while making this request.
242+ * @param {module:compute/rule } callback.rule - The created Rule object.
243+ * @param {module:compute/operation } callback.operation - An operation object
244+ * that can be used to check the status of the request.
245+ * @param {object } callback.apiResponse - The full API response.
246+ *
247+ * @example
248+ * var name = 'new-subnetwork-name';
249+ *
250+ * var config = {
251+ * region : 'regions/us-east1',
252+ * ipCidrRange: '10.0.1.0/24'
253+ * };
254+ *
255+ * network.createSubnetwork(name, config,
256+ * function (err, subnetwork, operation, apiResponse) {
257+ * // `subnetwork` is a Subnetwork object.
258+ *
259+ * // `operation` is an Operation object that can be used to check the status
260+ * // of the request.
261+ * });
262+ */
263+ Network . prototype . createSubnetwork = function ( name , config , callback ) {
264+ config = extend ( { } , config , {
265+ network : this . formattedName
266+ } ) ;
267+
268+ var region = new Region ( this . compute , config . region ) ;
269+ delete config . region ;
270+
271+ return region . createSubnetwork ( name , config , callback ) ;
272+ } ;
273+
274+ /**
275+ * Get a list of subnetworks in this network.
276+ * * @resource [Subnetworks Overview]{@link https://cloud.google.com/compute/docs/subnetworks}
277+ * @resource [Subnetworks: list API Documentation]{@link https://cloud.google.com/compute/docs/reference/latest/subnetworks}
278+ *
279+ * @param {object= } options - Subnetwork search options.
280+ * @param {boolean } options.autoPaginate - Have pagination handled
281+ * automatically. Default: true.
282+ * @param {string } options.filter - Search filter in the format of
283+ * `{name} {comparison} {filterString}`.
284+ * - **`name`**: the name of the field to compare
285+ * - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
286+ * (not equal)
287+ * - **`filterString`**: the string to filter to. For string fields, this
288+ * can be a regular expression.
289+ * @param {number } options.maxApiCalls - Maximum number of API calls to make.
290+ * @param {number } options.maxResults - Maximum number of firewalls to return.
291+ * @param {string } options.pageToken - A previously-returned page token
292+ * representing part of the larger set of results to view.
293+ * @param {function } callback - The callback function.
294+ * @param {?error } callback.err - An error returned while making this request.
295+ * @param {module:compute/firewall } callback.subnetworks - Subnetwork objects
296+ * from your project.
297+ * @param {?object } callback.nextQuery - If present, query with this object to
298+ * check for more results.
299+ * @param {object } callback.apiResponse - The full API response.
300+ *
301+ * @example
302+ * gce.getSubnetworks(function(err, subnetworks) {
303+ * // `subnetworks` is an array of `Subnetworks` objects.
304+ * });
305+ *
306+ * //-
307+ * // To control how many API requests are made and page through the results
308+ * // manually, set `autoPaginate` to `false`.
309+ * //-
310+ * function callback(err, subnetworks, nextQuery, apiResponse) {
311+ * if (nextQuery) {
312+ * // More results exist.
313+ * gce.getSubnetworks(nextQuery, callback);
314+ * }
315+ * }
316+ *
317+ * gce.getSubnetworks({
318+ * autoPaginate: false
319+ * }, callback);
320+ * * //-
321+ * // Get the firewalls from your project as a readable object stream.
322+ * //-
323+ * gce.getSubnetworks()
324+ * .on('error', console.error)
325+ * .on('data', function(subnetwork) {
326+ * // `subnetwork` is a `Subnetwork` object.
327+ * })
328+ * .on('end', function() {
329+ * // All firewalls retrieved.
330+ * });
331+ *
332+ * //-
333+ * // If you anticipate many results, you can end a stream early to prevent
334+ * // unnecessary processing and API requests.
335+ * //-
336+ * gce.getSubnetworks()
337+ * .on('data', function(subnetwork) {
338+ * this.end();
339+ * });
340+ */
341+ Network . prototype . getSubnetworks = function ( options , callback ) {
342+ if ( is . fn ( options ) ) {
343+ callback = options ;
344+ options = { } ;
345+ }
346+
347+ options = extend ( { } , options , {
348+ filter : 'network eq .*' + this . formattedName
349+ } ) ;
350+
351+ return this . compute . getSubnetworks ( options , callback ) ;
352+ } ;
353+
217354/**
218355 * Delete the network.
219356 *
0 commit comments