~ubuntu-branches/ubuntu/maverick/euca2ools/maverick-updates

« back to all changes in this revision

Viewing changes to bin/euca-terminate-instances

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2010-03-05 16:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20100305165925-40rmhda8swzojyva
Tags: 1.2-0ubuntu5
* Cherry pick fixes from upstream, up to bzr r265, fixes:
  - LP: #522398 - throw exceptions instead of sys.exit(1)
  - LP: #522396 - fix version string
  - LP: #523332 - check rsync return code
  - LP: #516738 - upstream fix for image store
  - LP: #525137 - don't sys.exit(1)
  - LP: #526697 - merge upstream fix for this one
  - LP: #531076 - fix euca-describe-instances against one instance
  - LP: #526591 - fix config file parsing

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# Author: Neil Soman neil@eucalyptus.com
34
34
 
35
35
import getopt, sys, os
36
 
from euca2ools import Euca2ool, InstanceValidationError, Util
 
36
from euca2ools import Euca2ool, InstanceValidationError, Util, ConnectionFailed
37
37
 
38
38
usage_string = """
39
39
Stops specified instances.
49
49
 
50
50
"""
51
51
 
52
 
version_string = """    euca-terminate-instances version: 1.0 (BSD)"""
53
52
 
54
 
def usage():
 
53
def usage(status=1):
55
54
    print usage_string
56
55
    Util().usage()
 
56
    sys.exit(status)
57
57
 
58
58
def version():
59
 
    print version_string
 
59
    print Util().version()
60
60
    sys.exit()
61
61
 
62
62
def display_instances(instances, instance_ids):
73
73
 
74
74
    for name, value in euca.opts:
75
75
        if name in ('-h', '--help'):
76
 
            usage()
 
76
            usage(0)
77
77
        elif name == '--version':
78
78
            version()
79
79
 
86
86
            print 'Invalid instance id' 
87
87
            sys.exit(1)
88
88
 
89
 
        euca_conn = euca.make_connection()
 
89
        try:
 
90
            euca_conn = euca.make_connection()
 
91
        except ConnectionFailed, e:
 
92
            print e.message
 
93
            sys.exit(1)
90
94
        try:
91
95
            instances = euca_conn.terminate_instances(instance_ids)
92
96
        except Exception, ex: