9
9
"time"
10
10
11
11
"cloud.google.com/go/compute/metadata"
12
- log "github.com/Sirupsen/logrus "
12
+ logutil "github.com/docker/infrakit/pkg/log "
13
13
"golang.org/x/oauth2/google"
14
14
"google.golang.org/api/compute/v1"
15
15
"google.golang.org/api/googleapi"
@@ -112,10 +112,12 @@ type computeServiceWrapper struct {
112
112
service * compute.Service
113
113
}
114
114
115
+ var log = logutil .New ("module" , "provider/google" )
116
+
115
117
// NewAPI creates a new API instance.
116
118
func NewAPI (project , zone string ) (API , error ) {
117
119
if project == "" {
118
- log .Debugln ("Project not passed on the command line" )
120
+ log .Debug ("Project not passed on the command line" , "project" , project )
119
121
120
122
project = findProject ()
121
123
if project == "" {
@@ -124,16 +126,16 @@ func NewAPI(project, zone string) (API, error) {
124
126
}
125
127
126
128
if zone == "" {
127
- log .Debugln ("Zone not passed on the command line" )
129
+ log .Debug ("Zone not passed on the command line" )
128
130
129
131
zone = findZone ()
130
132
if zone == "" {
131
133
return nil , errors .New ("Missing zone" )
132
134
}
133
135
}
134
136
135
- log .Debugln ("Project:" , project )
136
- log .Debugln ("Zone:" , zone )
137
+ log .Debug ("Project:" , "project " , project )
138
+ log .Debug ("Zone:" , "zone " , zone )
137
139
138
140
serviceProvider := func () (* compute.Service , error ) {
139
141
client , err := google .DefaultClient (context .TODO (), compute .ComputeScope )
@@ -159,15 +161,15 @@ func NewAPI(project, zone string) (API, error) {
159
161
160
162
func findProject () string {
161
163
if metadata .OnGCE () {
162
- log .Debugln ("- Query the metadata server..." )
164
+ log .Debug ("- Query the metadata server..." )
163
165
164
166
projectID , err := metadata .ProjectID ()
165
167
if err == nil {
166
168
return projectID
167
169
}
168
170
}
169
171
170
- log .Debugln (" - Look for" , EnvProject , "env variable..." )
172
+ log .Debug (" - Look for env var" , "project" , EnvProject )
171
173
172
174
value , found := os .LookupEnv (EnvProject )
173
175
if found && value != "" {
@@ -179,15 +181,15 @@ func findProject() string {
179
181
180
182
func findZone () string {
181
183
if metadata .OnGCE () {
182
- log .Debugln ("- Query the metadata server..." )
184
+ log .Debug ("- Query the metadata server..." )
183
185
184
186
zone , err := metadata .Zone ()
185
187
if err == nil {
186
188
return zone
187
189
}
188
190
}
189
191
190
- log .Debugln (" - Look for" , EnvZone , "env variable..." )
192
+ log .Debug (" - Look for env var" , "zone" , EnvZone )
191
193
192
194
value , found := os .LookupEnv (EnvZone )
193
195
if found && value != "" {
@@ -290,6 +292,7 @@ func (g *computeServiceWrapper) CreateInstance(name string, settings *InstanceSe
290
292
Preemptible : settings .Preemptible ,
291
293
},
292
294
}
295
+ log .Debug ("Creating instance" , "instance" , instance )
293
296
294
297
return g .doCall (g .service .Instances .Insert (g .project , g .zone , instance ))
295
298
}
@@ -325,26 +328,26 @@ func (g *computeServiceWrapper) attachedDisk(instanceName string, settings DiskS
325
328
326
329
var existingDisk * compute.Disk
327
330
if settings .ReuseExisting {
328
- log .Debugln ("Trying to reuse disk" , diskName )
331
+ log .Debug ("Trying to reuse disk" , diskName )
329
332
330
333
disk , err := g .service .Disks .Get (g .project , g .zone , diskName ).Do ()
331
334
if err != nil || disk == nil {
332
- log .Debugln ("Couldn't find existing disk" , diskName )
335
+ log .Debug ("Couldn't find existing disk" , diskName )
333
336
} else if disk .SourceImage != sourceImage {
334
- log .Debugln ("Found existing disk that uses a wrong image. Let's delete" , diskName )
337
+ log .Debug ("Found existing disk that uses a wrong image. Let's delete" , diskName )
335
338
if err := g .doCall (g .service .Disks .Delete (g .project , g .zone , disk .Name )); err != nil {
336
339
return nil , err
337
340
}
338
341
} else {
339
- log .Debugln ("Found existing disk" , diskName )
342
+ log .Debug ("Found existing disk" , diskName )
340
343
existingDisk = disk
341
344
}
342
345
}
343
346
344
347
if existingDisk != nil {
345
348
disk .Source = existingDisk .SelfLink
346
349
} else if settings .Image == "" {
347
- log .Debugln ("Creating standalone disk" , diskName )
350
+ log .Debug ("Creating standalone disk" , diskName )
348
351
349
352
if err := g .doCall (g .service .Disks .Insert (g .project , g .zone , & compute.Disk {
350
353
Name : diskName ,
0 commit comments