@@ -931,6 +931,121 @@ Compute.prototype.getDisks = function(options, callback) {
931931 } ) ;
932932} ;
933933
934+ /**
935+ * Get a list of instance groups.
936+ *
937+ * @resource [InstanceGroups Overview]{@link https://cloud.google.com/compute/docs/reference/v1/instanceGroups}
938+ * @resource [InstanceGroups: aggregatedList API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/instanceGroups/aggregatedList}
939+ *
940+ * @param {object= } options - Instance group search options.
941+ * @param {boolean } options.autoPaginate - Have pagination handled
942+ * automatically. Default: true.
943+ * @param {string } options.filter - Search filter in the format of
944+ * `{name} {comparison} {filterString}`.
945+ * - **`name`**: the name of the field to compare
946+ * - **`comparison`**: the comparison operator, `eq` (equal) or `ne`
947+ * (not equal)
948+ * - **`filterString`**: the string to filter to. For string fields, this
949+ * can be a regular expression.
950+ * @param {number } options.maxResults - Maximum number of instance groups to
951+ * return.
952+ * @param {string } options.pageToken - A previously-returned page token
953+ * representing part of the larger set of results to view.
954+ * @param {function } callback - The callback function.
955+ * @param {?error } callback.err - An error returned while making this request.
956+ * @param {module:compute/instance-group } callback.instanceGroups -
957+ * InstanceGroup objects from your project.
958+ * @param {?object } callback.nextQuery - If present, query with this object to
959+ * check for more results.
960+ * @param {object } callback.apiResponse - The full API response.
961+ *
962+ * @example
963+ * gce.getInstanceGroups(function(err, instanceGroups) {
964+ * // `instanceGroup` is an array of `InstanceGroup` objects.
965+ * });
966+ *
967+ * //-
968+ * // To control how many API requests are made and page through the results
969+ * // manually, set `autoPaginate` to `false`.
970+ * //-
971+ * function callback(err, groups, nextQuery, apiResponse) {
972+ * if (nextQuery) {
973+ * // More results exist.
974+ * gce.getInstanceGroups(nextQuery, callback);
975+ * }
976+ * }
977+ *
978+ * gce.getInstanceGroups({
979+ * autoPaginate: false
980+ * }, callback);
981+ *
982+ * //-
983+ * // Get the instance groups from your project as a readable object stream.
984+ * //-
985+ * gce.getInstanceGroups()
986+ * .on('error', console.error)
987+ * .on('data', function(instanceGroup) {
988+ * // `instanceGroup` is an `InstanceGroup` object.
989+ * })
990+ * .on('end', function() {
991+ * // All instance groups retrieved.
992+ * });
993+ *
994+ * //-
995+ * // If you anticipate many results, you can end a stream early to prevent
996+ * // unnecessary processing and API requests.
997+ * //-
998+ * gce.getInstanceGroups()
999+ * .on('data', function(instanceGroup) {
1000+ * this.end();
1001+ * });
1002+ */
1003+ Compute . prototype . getInstanceGroups = function ( options , callback ) {
1004+ var self = this ;
1005+
1006+ if ( is . fn ( options ) ) {
1007+ callback = options ;
1008+ options = { } ;
1009+ }
1010+
1011+ options = options || { } ;
1012+
1013+ this . request ( {
1014+ uri : '/aggregated/instanceGroups' ,
1015+ qs : options
1016+ } , function ( err , resp ) {
1017+ if ( err ) {
1018+ callback ( err , null , null , resp ) ;
1019+ return ;
1020+ }
1021+
1022+ var nextQuery = null ;
1023+
1024+ if ( resp . nextPageToken ) {
1025+ nextQuery = extend ( { } , options , {
1026+ pageToken : resp . nextPageToken
1027+ } ) ;
1028+ }
1029+
1030+ var zones = resp . items || { } ;
1031+
1032+ var instanceGroups = Object . keys ( zones ) . reduce ( function ( acc , zoneName ) {
1033+ var zone = self . zone ( zoneName . replace ( 'zones/' , '' ) ) ;
1034+ var instanceGroups = zones [ zoneName ] . instanceGroups || [ ] ;
1035+
1036+ instanceGroups . forEach ( function ( group ) {
1037+ var instanceGroupInstance = zone . instanceGroup ( group . name ) ;
1038+ instanceGroupInstance . metadata = group ;
1039+ acc . push ( instanceGroupInstance ) ;
1040+ } ) ;
1041+
1042+ return acc ;
1043+ } , [ ] ) ;
1044+
1045+ callback ( null , instanceGroups , nextQuery , resp ) ;
1046+ } ) ;
1047+ } ;
1048+
9341049/**
9351050 * Get a list of firewalls.
9361051 *
@@ -2128,6 +2243,7 @@ streamRouter.extend(Compute, [
21282243 'getAddresses' ,
21292244 'getAutoscalers' ,
21302245 'getDisks' ,
2246+ 'getInstanceGroups' ,
21312247 'getFirewalls' ,
21322248 'getHealthChecks' ,
21332249 'getNetworks' ,
0 commit comments