99 "time"
1010
1111 "cloud.google.com/go/compute/metadata"
12- log "github.com/Sirupsen/logrus "
12+ logutil "github.com/docker/infrakit/pkg/log "
1313 "golang.org/x/oauth2/google"
1414 "google.golang.org/api/compute/v1"
1515 "google.golang.org/api/googleapi"
@@ -112,10 +112,12 @@ type computeServiceWrapper struct {
112112 service * compute.Service
113113}
114114
115+ var log = logutil .New ("module" , "provider/google" )
116+
115117// NewAPI creates a new API instance.
116118func NewAPI (project , zone string ) (API , error ) {
117119 if project == "" {
118- log .Debugln ("Project not passed on the command line" )
120+ log .Debug ("Project not passed on the command line" , "project" , project )
119121
120122 project = findProject ()
121123 if project == "" {
@@ -124,16 +126,16 @@ func NewAPI(project, zone string) (API, error) {
124126 }
125127
126128 if zone == "" {
127- log .Debugln ("Zone not passed on the command line" )
129+ log .Debug ("Zone not passed on the command line" )
128130
129131 zone = findZone ()
130132 if zone == "" {
131133 return nil , errors .New ("Missing zone" )
132134 }
133135 }
134136
135- log .Debugln ("Project:" , project )
136- log .Debugln ("Zone:" , zone )
137+ log .Debug ("Project:" , "project " , project )
138+ log .Debug ("Zone:" , "zone " , zone )
137139
138140 serviceProvider := func () (* compute.Service , error ) {
139141 client , err := google .DefaultClient (context .TODO (), compute .ComputeScope )
@@ -159,15 +161,15 @@ func NewAPI(project, zone string) (API, error) {
159161
160162func findProject () string {
161163 if metadata .OnGCE () {
162- log .Debugln ("- Query the metadata server..." )
164+ log .Debug ("- Query the metadata server..." )
163165
164166 projectID , err := metadata .ProjectID ()
165167 if err == nil {
166168 return projectID
167169 }
168170 }
169171
170- log .Debugln (" - Look for" , EnvProject , "env variable..." )
172+ log .Debug (" - Look for env var" , "project" , EnvProject )
171173
172174 value , found := os .LookupEnv (EnvProject )
173175 if found && value != "" {
@@ -179,15 +181,15 @@ func findProject() string {
179181
180182func findZone () string {
181183 if metadata .OnGCE () {
182- log .Debugln ("- Query the metadata server..." )
184+ log .Debug ("- Query the metadata server..." )
183185
184186 zone , err := metadata .Zone ()
185187 if err == nil {
186188 return zone
187189 }
188190 }
189191
190- log .Debugln (" - Look for" , EnvZone , "env variable..." )
192+ log .Debug (" - Look for env var" , "zone" , EnvZone )
191193
192194 value , found := os .LookupEnv (EnvZone )
193195 if found && value != "" {
@@ -290,6 +292,7 @@ func (g *computeServiceWrapper) CreateInstance(name string, settings *InstanceSe
290292 Preemptible : settings .Preemptible ,
291293 },
292294 }
295+ log .Debug ("Creating instance" , "instance" , instance )
293296
294297 return g .doCall (g .service .Instances .Insert (g .project , g .zone , instance ))
295298}
@@ -325,26 +328,26 @@ func (g *computeServiceWrapper) attachedDisk(instanceName string, settings DiskS
325328
326329 var existingDisk * compute.Disk
327330 if settings .ReuseExisting {
328- log .Debugln ("Trying to reuse disk" , diskName )
331+ log .Debug ("Trying to reuse disk" , diskName )
329332
330333 disk , err := g .service .Disks .Get (g .project , g .zone , diskName ).Do ()
331334 if err != nil || disk == nil {
332- log .Debugln ("Couldn't find existing disk" , diskName )
335+ log .Debug ("Couldn't find existing disk" , diskName )
333336 } 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 )
335338 if err := g .doCall (g .service .Disks .Delete (g .project , g .zone , disk .Name )); err != nil {
336339 return nil , err
337340 }
338341 } else {
339- log .Debugln ("Found existing disk" , diskName )
342+ log .Debug ("Found existing disk" , diskName )
340343 existingDisk = disk
341344 }
342345 }
343346
344347 if existingDisk != nil {
345348 disk .Source = existingDisk .SelfLink
346349 } else if settings .Image == "" {
347- log .Debugln ("Creating standalone disk" , diskName )
350+ log .Debug ("Creating standalone disk" , diskName )
348351
349352 if err := g .doCall (g .service .Disks .Insert (g .project , g .zone , & compute.Disk {
350353 Name : diskName ,
0 commit comments