@@ -52,46 +52,42 @@ function main(
52
52
// const networkName = 'global/networks/default';
53
53
54
54
const compute = require ( '@google-cloud/compute' ) ;
55
- const compute_protos = compute . protos . google . cloud . compute . v1 ;
55
+ const computeProtos = compute . protos . google . cloud . compute . v1 ;
56
56
57
57
// Create a new instance with the values provided above in the specified project and zone.
58
58
async function createInstance ( ) {
59
- const instancesClient = new compute . InstancesClient ( { fallback : 'rest' } ) ;
60
-
61
- // Describe the size and source image of the boot disk to attach to the instance.
62
- const attachedDisk = new compute_protos . AttachedDisk ( ) ;
63
- const initializeParams = new compute_protos . AttachedDiskInitializeParams ( ) ;
64
-
65
- initializeParams . diskSizeGb = '10' ;
66
- initializeParams . sourceImage = sourceImage ;
67
-
68
- attachedDisk . initializeParams = initializeParams ;
69
- attachedDisk . autoDelete = true ;
70
- attachedDisk . boot = true ;
71
- attachedDisk . type = compute_protos . AttachedDisk . Type . PERSISTENT ;
72
-
73
- // Use the network interface provided in the networkName argument.
74
- const networkInterface = new compute_protos . NetworkInterface ( ) ;
75
- networkInterface . name = networkName ;
76
-
77
- // Collect information into the Instance object.
78
- const instance = new compute_protos . Instance ( ) ;
79
- instance . name = instanceName ;
80
- instance . disks = [ attachedDisk ] ;
81
- instance . machineType = `zones/${ zone } /machineTypes/${ machineType } ` ;
82
- instance . networkInterfaces = [ networkInterface ] ;
59
+ const instancesClient = new compute . InstancesClient ( ) ;
83
60
84
61
console . log ( `Creating the ${ instanceName } instance in ${ zone } ...` ) ;
85
62
86
63
let [ operation ] = await instancesClient . insert ( {
87
- instanceResource : instance ,
64
+ instanceResource : {
65
+ name : instanceName ,
66
+ disks : [
67
+ {
68
+ // Describe the size and source image of the boot disk to attach to the instance.
69
+ initializeParams : {
70
+ diskSizeGb : '10' ,
71
+ sourceImage,
72
+ } ,
73
+ autoDelete : true ,
74
+ boot : true ,
75
+ type : computeProtos . AttachedDisk . Type . PERSISTENT ,
76
+ } ,
77
+ ] ,
78
+ machineType : `zones/${ zone } /machineTypes/${ machineType } ` ,
79
+ networkInterfaces : [
80
+ {
81
+ // Use the network interface provided in the networkName argument.
82
+ name : networkName ,
83
+ } ,
84
+ ] ,
85
+ } ,
88
86
project : projectId ,
89
87
zone,
90
88
} ) ;
91
89
92
- const operationsClient = new compute . ZoneOperationsClient ( {
93
- fallback : 'rest' ,
94
- } ) ;
90
+ const operationsClient = new compute . ZoneOperationsClient ( ) ;
95
91
96
92
// Wait for the create operation to complete.
97
93
while ( operation . status !== 'DONE' ) {
0 commit comments