1
// Copyright 2013 Canonical Ltd. This software is licensed under the
2
// GNU Lesser General Public License version 3 (see the file COPYING).
4
// A poller object used to delete a disk.
6
// It takes an indeterminate time for a disk previously attached to a
7
// deleted VM to become "not in use" and thus be available for deletion.
8
// When we receive the "disk is still attached" error, we try again every
9
// 10 seconds until it succeeds, with a timeout of 30 minutes).
10
// This bug might be related to:
11
// http://social.msdn.microsoft.com/Forums/en-US/WAVirtualMachinesforWindows/thread/4394c75d-59ff-4634-8212-2ad71bf6fbd5/
13
// Once this bug is fixed in Windows Azure, this file and the related tests
14
// can safely be removed, and ManagementAPI._DeleteDisk() can replace the
15
// current implementation of ManagementAPI.DeleteDisk() (which uses this
26
var deleteDiskTimeout = 30 * time.Minute
27
var deleteDiskInterval = 10 * time.Second
29
type diskDeletePoller struct {
34
var _ poller = &diskDeletePoller{}
36
func (poller diskDeletePoller) poll() (*x509Response, error) {
37
return nil, poller.api._DeleteDisk(poller.diskName)
40
// isInUseError returns whether or not the given string is of the "disk in use"
42
// Here is a real-world example of the error in question:
43
// "BadRequest - A disk with name gwacldiske5w7lkj is currently in use
44
// by virtual machine gwaclrolemvo1yab running within hosted service
45
// gwacl623yosxtppsa9577xy5, deployment gwaclmachinewes4n64f. (http
46
// code 400: Bad Request)"
47
func isInUseError(errString string, diskName string) bool {
48
pattern := fmt.Sprintf("BadRequest - A disk with name %s is currently in use by virtual machine.*", regexp.QuoteMeta(diskName))
49
reg := regexp.MustCompile(pattern)
50
return reg.MatchString(errString)
53
func (poller diskDeletePoller) isDone(response *x509Response, pollerErr error) (bool, error) {
57
if isInUseError(pollerErr.Error(), poller.diskName) {
58
// The error is of the "disk in use" type: continue polling.
61
// The error is *not* of the "disk in use" type: stop polling and return
63
return true, pollerErr