35
35
$ client ->setClientId ('YOUR_CLIENT_ID ' );
36
36
$ client ->setClientSecret ('YOUR_CLIENT_SECRET ' );
37
37
$ client ->setRedirectUri ('YOUR_REDIRECT_URI ' );
38
- $ client ->setDeveloperKey ('YOUR_DEVELOPER_KEY ' );
39
38
$ computeService = new Google_ComputeService ($ client );
40
39
41
40
/**
46
45
/**
47
46
* Constants for sample request parameters.
48
47
*/
49
- define ('API_VERSION ' , 'v1beta13 ' );
48
+ define ('API_VERSION ' , 'v1beta14 ' );
50
49
define ('BASE_URL ' , 'https://www.googleapis.com/compute/ ' .
51
50
API_VERSION . '/projects/ ' );
52
51
define ('GOOGLE_PROJECT ' , 'google ' );
53
52
define ('DEFAULT_PROJECT ' , $ project );
54
53
define ('DEFAULT_NAME ' , 'new-node ' );
55
54
define ('DEFAULT_NAME_WITH_METADATA ' , 'new-node-with-metadata ' );
56
55
define ('DEFAULT_MACHINE_TYPE ' , BASE_URL . DEFAULT_PROJECT .
57
- '/machineTypes/n1-standard-1 ' );
58
- define ('DEFAULT_ZONE ' , BASE_URL . DEFAULT_PROJECT . '/zones/us-central1-a ' );
56
+ '/global/machineTypes/n1-standard-1 ' );
57
+ define ('DEFAULT_ZONE_NAME ' , 'us-central1-a ' );
58
+ define ('DEFAULT_ZONE ' , BASE_URL . DEFAULT_PROJECT . '/zones/ ' . DEFAULT_ZONE_NAME );
59
59
define ('DEFAULT_IMAGE ' , BASE_URL . GOOGLE_PROJECT .
60
- '/images/ubuntu -12-04-v20120912 ' );
60
+ '/global/ images/gcel -12-04-v20130104 ' );
61
61
define ('DEFAULT_NETWORK ' , BASE_URL . DEFAULT_PROJECT .
62
- '/networks/default ' );
62
+ '/global/ networks/default ' );
63
63
64
64
/**
65
65
* Generates the markup for a specific Google Compute Engine API request.
@@ -119,7 +119,8 @@ function generateMarkup($apiRequestName, $apiResponse) {
119
119
* Google Compute Engine API request to retrieve the list of instances in your
120
120
* Google Compute Engine project.
121
121
*/
122
- $ instances = $ computeService ->instances ->listInstances (DEFAULT_PROJECT );
122
+ $ instances = $ computeService ->instances ->listInstances (DEFAULT_PROJECT ,
123
+ DEFAULT_ZONE_NAME );
123
124
$ instancesListMarkup = generateMarkup ('List Instances ' , $ instances );
124
125
125
126
/**
@@ -164,7 +165,7 @@ function generateMarkup($apiRequestName, $apiResponse) {
164
165
*/
165
166
$ name = DEFAULT_NAME ;
166
167
$ machineType = DEFAULT_MACHINE_TYPE ;
167
- $ zone = DEFAULT_ZONE ;
168
+ $ zone = DEFAULT_ZONE_NAME ;
168
169
$ image = DEFAULT_IMAGE ;
169
170
170
171
$ googleNetworkInterfaceObj = new Google_NetworkInterface ();
@@ -174,12 +175,11 @@ function generateMarkup($apiRequestName, $apiResponse) {
174
175
$ new_instance = new Google_Instance ();
175
176
$ new_instance ->setName ($ name );
176
177
$ new_instance ->setImage ($ image );
177
- $ new_instance ->setZone ($ zone );
178
178
$ new_instance ->setMachineType ($ machineType );
179
179
$ new_instance ->setNetworkInterfaces (array ($ googleNetworkInterfaceObj ));
180
180
181
181
$ insertInstance = $ computeService ->instances ->insert (DEFAULT_PROJECT ,
182
- $ new_instance );
182
+ $ zone , $ new_instance );
183
183
$ insertInstanceMarkup = generateMarkup ('Insert Instance ' , $ insertInstance );
184
184
185
185
/**
@@ -188,7 +188,7 @@ function generateMarkup($apiRequestName, $apiResponse) {
188
188
*/
189
189
$ name = DEFAULT_NAME_WITH_METADATA ;
190
190
$ machineType = DEFAULT_MACHINE_TYPE ;
191
- $ zone = DEFAULT_ZONE ;
191
+ $ zone = DEFAULT_ZONE_NAME ;
192
192
$ image = DEFAULT_IMAGE ;
193
193
194
194
$ googleNetworkInterfaceObj = new Google_NetworkInterface ();
@@ -205,54 +205,55 @@ function generateMarkup($apiRequestName, $apiResponse) {
205
205
$ new_instance = new Google_Instance ();
206
206
$ new_instance ->setName ($ name );
207
207
$ new_instance ->setImage ($ image );
208
- $ new_instance ->setZone ($ zone );
209
208
$ new_instance ->setMachineType ($ machineType );
210
209
$ new_instance ->setNetworkInterfaces (array ($ googleNetworkInterfaceObj ));
211
210
$ new_instance ->setMetadata ($ metadata );
212
211
213
212
$ insertInstanceWithMetadata = $ computeService ->instances ->insert (
214
- DEFAULT_PROJECT , $ new_instance );
213
+ DEFAULT_PROJECT , $ zone , $ new_instance );
215
214
$ insertInstanceWithMetadataMarkup = generateMarkup (
216
215
'Insert Instance With Metadata ' , $ insertInstanceWithMetadata );
217
216
218
217
/**
219
218
* Google Compute Engine API request to get an instance matching the outlined
220
219
* parameters from your Google Compute Engine project.
221
220
*/
222
- $ getInstance = $ computeService ->instances ->get (DEFAULT_PROJECT , DEFAULT_NAME );
221
+ $ getInstance = $ computeService ->instances ->get (DEFAULT_PROJECT ,
222
+ DEFAULT_ZONE_NAME , DEFAULT_NAME );
223
223
$ getInstanceMarkup = generateMarkup ('Get Instance ' , $ getInstance );
224
224
225
225
/**
226
226
* Google Compute Engine API request to get an instance matching the outlined
227
227
* parameters from your Google Compute Engine project.
228
228
*/
229
229
$ getInstanceWithMetadata = $ computeService ->instances ->get (DEFAULT_PROJECT ,
230
- DEFAULT_NAME_WITH_METADATA );
230
+ DEFAULT_ZONE_NAME , DEFAULT_NAME_WITH_METADATA );
231
231
$ getInstanceWithMetadataMarkup = generateMarkup ('Get Instance With Metadata ' ,
232
232
$ getInstanceWithMetadata );
233
233
234
234
/**
235
235
* Google Compute Engine API request to delete an instance matching the
236
236
* outlined parameters from your Google Compute Engine project.
237
237
*/
238
- $ deleteInstance = $ computeService ->instances ->delete (DEFAULT_PROJECT , DEFAULT_NAME );
238
+ $ deleteInstance = $ computeService ->instances ->delete (DEFAULT_PROJECT ,
239
+ DEFAULT_ZONE_NAME , DEFAULT_NAME );
239
240
$ deleteInstanceMarkup = generateMarkup ('Delete Instance ' , $ deleteInstance );
240
241
241
242
/**
242
243
* Google Compute Engine API request to delete an instance matching the
243
244
* outlined parameters from your Google Compute Engine project.
244
245
*/
245
246
$ deleteInstanceWithMetadata = $ computeService ->instances ->delete (DEFAULT_PROJECT ,
246
- DEFAULT_NAME_WITH_METADATA );
247
+ DEFAULT_ZONE_NAME , DEFAULT_NAME_WITH_METADATA );
247
248
$ deleteInstanceWithMetadataMarkup = generateMarkup (
248
249
'Delete Instance With Metadata ' , $ deleteInstanceWithMetadata );
249
250
250
251
/**
251
- * Google Compute Engine API request to retrieve the list of all operations
252
- * associated with your Google Compute Engine project.
252
+ * Google Compute Engine API request to retrieve the list of all global
253
+ * operations associated with your Google Compute Engine project.
253
254
*/
254
- $ operations = $ computeService ->operations -> listOperations (DEFAULT_PROJECT );
255
- $ operationsListMarkup = generateMarkup ('List Operations ' , $ operations );
255
+ $ globalOperations = $ computeService ->globalOperations -> listGlobalOperations (DEFAULT_PROJECT );
256
+ $ operationsListMarkup = generateMarkup ('List Global Operations ' , $ globalOperations );
256
257
257
258
// The access token may have been updated lazily.
258
259
$ _SESSION ['access_token ' ] = $ client ->getAccessToken ();
@@ -323,7 +324,7 @@ function generateMarkup($apiRequestName, $apiResponse) {
323
324
endif ?>
324
325
325
326
if (isset ($ operationsListMarkup )): ?>
326
- listOperations"> print $ operationsListMarkup ?>
327
+ listGlobalOperations"> print $ operationsListMarkup ?>
327
328
endif ?>
328
329
329
330
0 commit comments