~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/gwacl/deletedisk.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.  This software is licensed under the
 
2
// GNU Lesser General Public License version 3 (see the file COPYING).
 
3
 
 
4
// A poller object used to delete a disk.
 
5
//
 
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/
 
12
//
 
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
 
16
// poller).
 
17
 
 
18
package gwacl
 
19
 
 
20
import (
 
21
    "fmt"
 
22
    "regexp"
 
23
    "time"
 
24
)
 
25
 
 
26
var deleteDiskTimeout = 30 * time.Minute
 
27
var deleteDiskInterval = 10 * time.Second
 
28
 
 
29
type diskDeletePoller struct {
 
30
    api      *ManagementAPI
 
31
    diskName string
 
32
}
 
33
 
 
34
var _ poller = &diskDeletePoller{}
 
35
 
 
36
func (poller diskDeletePoller) poll() (*x509Response, error) {
 
37
    return nil, poller.api._DeleteDisk(poller.diskName)
 
38
}
 
39
 
 
40
// isInUseError returns whether or not the given string is of the "disk in use"
 
41
// type.
 
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)
 
51
}
 
52
 
 
53
func (poller diskDeletePoller) isDone(response *x509Response, pollerErr error) (bool, error) {
 
54
    if pollerErr == nil {
 
55
        return true, nil
 
56
    }
 
57
    if isInUseError(pollerErr.Error(), poller.diskName) {
 
58
        // The error is of the "disk in use" type: continue polling.
 
59
        return false, nil
 
60
    }
 
61
    // The error is *not* of the "disk in use" type: stop polling and return
 
62
    // the error.
 
63
    return true, pollerErr
 
64
}