forked from googleapis/google-cloud-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddress.js
More file actions
145 lines (129 loc) · 4.11 KB
/
Copy pathaddress.js
File metadata and controls
145 lines (129 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*!
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*!
* @module compute/address
*/
'use strict';
/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util.js');
/*! Developer Documentation
*
* @param {module:region} region - Region this address belongs to.
* @param {string} name - The name of the address.
*/
/**
* An Address object allows you to interact with a Google Compute Engine
* address.
*
* @resource [Instances and Networks]{@link https://cloud.google.com/compute/docs/instances-and-network}
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses} *
*
* @constructor
* @alias module:compute/address
*
* @example
* var gcloud = require('gcloud')({
* keyFilename: '/path/to/keyfile.json',
* projectId: 'grape-spaceship-123'
* });
*
* var gce = gcloud.compute();
*
* var region = gce.region('region-name');
*
* var address = region.address('address1');
*/
function Address(region, name) {
this.region = region;
this.name = name;
this.metadata = {};
}
/**
* Delete the address.
*
* @resource [Addresses: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/delete}
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {module:compute/operation} callback.operation - An operation object
* that can be used to check the status of the request.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* address.delete(function(err, operation, apiResponse) {
* // `operation` is an Operation object that can be used to check the status
* // of the request.
* });
*/
Address.prototype.delete = function(callback) {
callback = callback || util.noop;
var region = this.region;
this.makeReq_('DELETE', '', null, null, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
var operation = region.operation(resp.name);
operation.metadata = resp;
callback(null, operation, resp);
});
};
/**
* Get the metadata of this address.
*
* @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses}
* @resource [Addresses: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/get}
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request
* @param {object} callback.metadata - The address's metadata.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* address.getMetadata(function(err, metadata, apiResponse) {});
*/
Address.prototype.getMetadata = function(callback) {
callback = callback || util.noop;
var self = this;
this.makeReq_('GET', '', null, null, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
self.metadata = resp;
callback(null, self.metadata, resp);
});
};
/**
* Make a new request object from the provided arguments and wrap the callback
* to intercept non-successful responses.
*
* @private
*
* @param {string} method - Action.
* @param {string} path - Request path.
* @param {*} query - Request query object.
* @param {*} body - Request body contents.
* @param {function} callback - The callback function.
*/
Address.prototype.makeReq_ = function(method, path, query, body, callback) {
path = '/addresses/' + this.name + path;
this.region.makeReq_(method, path, query, body, callback);
};
module.exports = Address;