@@ -931,6 +931,121 @@ Compute.prototype.getDisks = function(options, callback) {
931
931
} ) ;
932
932
} ;
933
933
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
+ * // `instanceGroups` 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, instanceGroups, 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
+
934
1049
/**
935
1050
* Get a list of firewalls.
936
1051
*
@@ -2130,6 +2245,7 @@ streamRouter.extend(Compute, [
2130
2245
'getDisks' ,
2131
2246
'getFirewalls' ,
2132
2247
'getHealthChecks' ,
2248
+ 'getInstanceGroups' ,
2133
2249
'getNetworks' ,
2134
2250
'getOperations' ,
2135
2251
'getRegions' ,
0 commit comments