@@ -52,6 +52,12 @@ var Snapshot = require('./snapshot.js');
52
52
*/
53
53
var Network = require ( './network.js' ) ;
54
54
55
+ /**
56
+ * @type {module:compute/operation }
57
+ * @private
58
+ */
59
+ var Operation = require ( './operation.js' ) ;
60
+
55
61
/**
56
62
* @type {module:common/util }
57
63
* @private
@@ -218,6 +224,25 @@ Compute.prototype.network = function(name) {
218
224
return new Network ( this , name ) ;
219
225
} ;
220
226
227
+ /**
228
+ * Get a reference to a Google Compute Engine operation.
229
+ *
230
+ * @param {string } name - Name of the existing operation.
231
+ * @return {module:compute/operation }
232
+ *
233
+ * @example
234
+ * var gcloud = require('gcloud')({
235
+ * keyFilename: '/path/to/keyfile.json'
236
+ * });
237
+ *
238
+ * var compute = gcloud.compute();
239
+ *
240
+ * var operation = compute.operation('operation-name');
241
+ */
242
+ Compute . prototype . operation = function ( name ) {
243
+ return new Operation ( this , name ) ;
244
+ } ;
245
+
221
246
/**
222
247
* Create a firewall rule. For a detailed description of method's options see
223
248
* [API reference](https://goo.gl/kTMHep).
@@ -242,8 +267,10 @@ Compute.prototype.network = function(name) {
242
267
* @param {function } callback - The callback function.
243
268
*
244
269
* @example
245
- * var callback = function(err, firewall, apiResponse ) {
270
+ * var callback = function(err, firewall, operation ) {
246
271
* // `firewall` is a Firewall object.
272
+ * // `operation` is an Operation object and can be used to check the status
273
+ * // of firewall rule creation.
247
274
* };
248
275
*
249
276
* var compute = gcloud.compute({
@@ -298,7 +325,9 @@ Compute.prototype.createFirewall = function(name, options, callback) {
298
325
}
299
326
var firewall = self . firewall ( name ) ;
300
327
firewall . metadata = options ;
301
- callback ( null , firewall , resp ) ;
328
+ var operation = self . operation ( resp . name ) ;
329
+ operation . metadata = resp ;
330
+ callback ( null , firewall , operation ) ;
302
331
} ) ;
303
332
} ;
304
333
@@ -316,8 +345,10 @@ Compute.prototype.createFirewall = function(name, options, callback) {
316
345
* @param {function } callback - The callback function.
317
346
*
318
347
* @example
319
- * var callback = function(err, network, apiResponse ) {
348
+ * var callback = function(err, network, operation ) {
320
349
* // `network` is a Network object.
350
+ * // `operation` is an Operation object and can be used to check the status
351
+ * // of network creation.
321
352
* };
322
353
*
323
354
* var compute = gcloud.compute({
@@ -349,7 +380,9 @@ Compute.prototype.createNetwork = function(name, options, callback) {
349
380
}
350
381
var network = self . network ( name ) ;
351
382
network . metadata = options ;
352
- callback ( null , network , resp ) ;
383
+ var operation = self . operation ( resp . name ) ;
384
+ operation . metadata = resp ;
385
+ callback ( null , network , operation ) ;
353
386
} ) ;
354
387
} ;
355
388
@@ -943,6 +976,104 @@ Compute.prototype.getNetworks = function(options, callback) {
943
976
} ) ;
944
977
} ;
945
978
979
+ /**
980
+ * Get a list of global operations. For a detailed description of method's
981
+ * options see [API reference](https://goo.gl/gX4C1u).
982
+ *
983
+ * @param {object } options - Operation search options.
984
+ * @param {boolean= } options.autoPaginate - Have pagination handled
985
+ * automatically. Default: true.
986
+ * @param {number= } options.maxResults - Maximum number of operations to return.
987
+ * @param {string= } options.filter - Search filter. The filter must contain:
988
+ * `FIELD_NAME COMPARISON_STRING LITERAL_STRING`. `FIELD_NAME` is the name
989
+ * of the field to compare. `COMPARISON` is the comparison operator that can
990
+ * be either `eq` or `ne`. `LITERAL_STRING` is the string to filter to.
991
+ * For string fields `LITERAL_STRING` can be a regular expression.
992
+ * @param {string= } pageToken - Page identifier used in paginated search.
993
+ * @param {function } callback - The callback function.
994
+ *
995
+ * @example
996
+ * var callback = function(err, operations) {
997
+ * // `operations` is an array of `Operation` objects.
998
+ * };
999
+ *
1000
+ * compute.getOperations(
1001
+ * {
1002
+ * filter: 'name eq operation-[0-9]'
1003
+ * }, callback);
1004
+ *
1005
+ * //-
1006
+ * // To control how many API requests are made and page through the results
1007
+ * // manually, set `autoPaginate` to `false`.
1008
+ * //-
1009
+ * var callback = function(err, operations, nextQuery, apiResponse) {
1010
+ * if (nextQuery) {
1011
+ * // More results exist.
1012
+ * compute.getOperations(nextQuery, callback);
1013
+ * }
1014
+ * };
1015
+ *
1016
+ * compute.getOperations({
1017
+ * autoPaginate: false
1018
+ * }, callback);
1019
+ *
1020
+ * //-
1021
+ * // Get the operations from your project as a readable object stream.
1022
+ * //-
1023
+ * compute.getOperations()
1024
+ * .on('error', console.error)
1025
+ * .on('data', function(operation) {
1026
+ * // `operation` is a `Operation` object.
1027
+ * })
1028
+ * .on('end', function() {
1029
+ * // All operations retrieved.
1030
+ * });
1031
+ *
1032
+ * //-
1033
+ * // If you anticipate many results, you can end a stream early to prevent
1034
+ * // unnecessary processing and API requests.
1035
+ * //-
1036
+ * compute.getOperations()
1037
+ * .on('data', function(operation) {
1038
+ * this.end();
1039
+ * });
1040
+ */
1041
+ Compute . prototype . getOperations = function ( options , callback ) {
1042
+ if ( util . is ( options , 'function' ) ) {
1043
+ callback = options ;
1044
+ options = { } ;
1045
+ }
1046
+
1047
+ options = options || { } ;
1048
+
1049
+ var self = this ;
1050
+ this . makeReq_ (
1051
+ 'GET' ,
1052
+ '/global/operations' ,
1053
+ options ,
1054
+ null , function ( err , resp ) {
1055
+ if ( err ) {
1056
+ callback ( err ) ;
1057
+ return ;
1058
+ }
1059
+
1060
+ var nextQuery = null ;
1061
+
1062
+ if ( resp . nextPageToken ) {
1063
+ nextQuery = extend ( { } , options , {
1064
+ pageToken : resp . nextPageToken
1065
+ } ) ;
1066
+ }
1067
+
1068
+ var operations = ( resp . items || [ ] ) . map ( function ( operationObject ) {
1069
+ var operation = self . operation ( operationObject . name ) ;
1070
+ operation . metadata = operationObject ;
1071
+ return operation ;
1072
+ } ) ;
1073
+ callback ( null , operations , nextQuery , resp ) ;
1074
+ } ) ;
1075
+ } ;
1076
+
946
1077
/**
947
1078
* Make a new request object from the provided arguments and wrap the callback
948
1079
* to intercept non-successful responses.
@@ -980,7 +1111,8 @@ streamRouter.extend(Compute, [
980
1111
'getAddresses' ,
981
1112
'getSnapshots' ,
982
1113
'getFirewalls' ,
983
- 'getNetworks'
1114
+ 'getNetworks' ,
1115
+ 'getOperations'
984
1116
] ) ;
985
1117
986
1118
module . exports = Compute ;
0 commit comments