Handle PD already being attached to the machine.

pull/6/head
Brendan Burns 2014-12-11 13:00:26 -08:00
parent 222c819800
commit 1dcb025559
1 changed files with 15 additions and 0 deletions

View File

@ -376,6 +376,21 @@ func (gce *GCECloud) AttachDisk(diskName string, readOnly bool) error {
}
attachedDisk := gce.convertDiskToAttachedDisk(disk, readWrite)
_, err = gce.service.Instances.AttachDisk(gce.projectID, gce.zone, gce.instanceID, attachedDisk).Do()
if err != nil {
// Check if the disk is already attached to this instance. We do this only
// in the error case, since it is expected to be exceptional.
instance, err := gce.service.Instances.Get(gce.projectID, gce.zone, gce.instanceID).Do()
if err != nil {
return err
}
for _, disk := range instance.Disks {
if disk.InitializeParams.DiskName == diskName {
// Disk is already attached, we're good to go.
return nil
}
}
}
return err
}