Package starcluster :: Module exception
[hide private]
[frames] | no frames]

Source Code for Module starcluster.exception

  1  #!/usr/bin/env python 
  2  """ 
  3  StarCluster Exception Classes 
  4  """ 
  5  import os 
  6  from starcluster import static 
  7  from starcluster.logger import log 
  8  from starcluster.templates.config import config_template, copy_paste_template 
  9   
10 -class BaseException(Exception):
11 - def __init__(self, *args):
12 self.msg = args[0]
13 - def __str__(self):
14 return self.msg
15 - def explain(self):
16 return "%s: %s" % (self.__class__.__name__, self.msg)
17
18 -class SSHError(BaseException):
19 """Base class for all SSH related errors"""
20
21 -class SSHConnectionError(SSHError):
22 """Raised when ssh fails to to connect to a host (socket error)"""
23 - def __init__(self, host, port):
24 self.msg = "failed to connect to host %s on port %s" % (host,port)
25
26 -class SSHAuthException(SSHError):
27 """Raised when an ssh connection fails to authenticate"""
28 - def __init__(self, user, host):
29 self.msg = "failed to authenticate to host %s as user %s" % (user, host)
30
31 -class SSHNoCredentialsError(BaseException):
32 - def __init__(self, *args):
33 self.msg = "No password or key specified"
34
35 -class AWSError(BaseException):
36 pass
37
38 -class AMIDoesNotExist(AWSError):
39 - def __init__(self, image_id):
40 self.msg = "AMI %s does not exist" % image_id
41
42 -class InstanceDoesNotExist(AWSError):
43 - def __init__(self, instance_id):
44 self.msg = "instance %s does not exist" % instance_id
45
46 -class SecurityGroupDoesNotExist(AWSError):
47 - def __init__(self, sg_name):
48 self.msg = "security group %s does not exist" % sg_name
49
50 -class KeyPairDoesNotExist(AWSError):
51 - def __init__(self, keyname):
52 self.msg = "keypair %s does not exist" % keyname
53
54 -class ZoneDoesNotExist(AWSError):
55 - def __init__(self, zone):
56 self.msg = "zone %s does not exist" % zone
57
58 -class VolumeDoesNotExist(AWSError):
59 - def __init__(self, vol_id):
60 self.msg = "volume %s does not exist" % vol_id
61
62 -class InstanceNotRunning(AWSError):
63 - def __init__(self, instance_id):
64 self.msg = "instance %s is not running" % instance_id
65
66 -class InvalidBucketName(AWSError):
67 - def __init__(self, bucket_name):
68 self.msg = "bucket name %s is not valid" % bucket_name
69
70 -class InvalidImageName(AWSError):
71 - def __init__(self, image_name):
72 self.msg = "image name %s is not valid" % image_name
73
74 -class EC2CertRequired(AWSError):
75 - def __init__(self):
76 self.msg = "No certificate file (pem) file specified"
77
78 -class EC2PrivateKeyRequired(AWSError):
79 - def __init__(self):
80 self.msg = "No certificate file (pem) file specified"
81
82 -class EC2CertDoesNotExist(AWSError):
83 - def __init__(self, key):
84 self.msg = "EC2 certificate file %s does not exist" % key
85
86 -class EC2PrivateKeyDoesNotExist(AWSError):
87 - def __init__(self, key):
88 self.msg = "EC2 private key file %s does not exist" % key
89
90 -class SpotHistoryError(AWSError):
91 - def __init__(self, start, end):
92 self.msg = "no spot price history for the dates specified: " + \ 93 "%s - %s" % (start, end)
94
95 -class InvalidIsoDate(BaseException):
96 - def __init__(self, date):
97 self.msg = "Invalid date specified: %s" % date
98
99 -class ConfigError(BaseException):
100 """Base class for all config related errors"""
101
102 -class ConfigSectionMissing(ConfigError):
103 pass
104
105 -class ConfigHasNoSections(ConfigError):
106 - def __init__(self, cfg_file):
107 self.msg = "No valid sections defined in config file %s" % cfg_file
108
109 -class PluginNotFound(ConfigError):
110 - def __init__(self, plugin):
111 self.msg = 'Plugin "%s" not found in config' % plugin
112
113 -class MultipleDefaultTemplates(ConfigError):
114 - def __init__(self, defaults):
115 msg = 'Cluster templates %s each have DEFAULT=True in your config.' 116 msg += ' Only one cluster can be the default. Please pick one.' 117 l = '' 118 if len(defaults) == 2: 119 tmpl_list = ' and '.join(defaults) 120 else: 121 first = defaults[0:-1] 122 last = defaults[-1] 123 tmpl_list = ', and '.join([', '.join(first), last]) 124 self.msg = msg % tmpl_list
125
126 -class NoDefaultTemplateFound(ConfigError):
127 - def __init__(self, options=None):
128 msg = "No default cluster template specified. To set the default cluster " 129 msg += "template, set DEFAULT_TEMPLATE in the [global] section " 130 msg += "of the config to the name of one of your cluster templates " 131 if options: 132 msg +='(' + ', '.join(options) + ')' 133 self.msg = msg
134
135 -class ConfigNotFound(ConfigError):
136 - def __init__(self, *args, **kwargs):
137 super(ConfigNotFound, self).__init__(*args, **kwargs) 138 self.cfg = args[1] 139 self.template = copy_paste_template
140
141 - def create_config(self):
142 cfg_parent_dir = os.path.dirname(self.cfg) 143 if not os.path.exists(cfg_parent_dir): 144 os.makedirs(cfg_parent_dir) 145 cfg_file = open(self.cfg, 'w') 146 cfg_file.write(config_template) 147 cfg_file.close() 148 log.info("Config template written to %s. Please customize this file." % 149 self.cfg)
150
151 - def display_options(self):
152 print 'Options:' 153 print '--------' 154 print '[1] Show the StarCluster config template' 155 print '[2] Write config template to %s' % self.cfg 156 print '[q] Quit' 157 resp = raw_input('\nPlase enter your selection: ') 158 if resp == '1': 159 print self.template 160 elif resp == '2': 161 print 162 self.create_config()
163
164 -class KeyNotFound(ConfigError):
165 - def __init__(self, keyname):
166 self.msg = "key %s not found in config" % keyname
167
168 -class InvalidDevice(BaseException):
169 - def __init__(self, device):
170 self.msg = "invalid device specified: %s" % device
171
172 -class InvalidPartition(BaseException):
173 - def __init__(self, part):
174 self.msg = "invalid partition specified: %s" % part
175
176 -class PluginError(BaseException):
177 """Base class for plugin errors"""
178
179 -class PluginLoadError(PluginError):
180 """Raised when an error is encountered while loading a plugin"""
181
182 -class PluginSyntaxError(PluginError):
183 """Raised when plugin contains syntax errors"""
184
185 -class ValidationError(BaseException):
186 """Base class for validation related errors"""
187
188 -class ClusterReceiptError(BaseException):
189 """Raised when Cluster class fails to create a receipt on the master node"""
190
191 -class ClusterValidationError(ValidationError):
192 """Cluster validation related errors"""
193
194 -class IncompatibleSettings(ClusterValidationError):
195 """Raised when two or more settings conflict with each other"""
196
197 -class InvalidZone(ClusterValidationError):
198 """Raised when user specified a zone that is not the same as the zone of the 199 volumes being attached"""
200 - def __init__(self, zone, common_vol_zone):
201 self.msg = "zone %s does not match common volume zone %s" % (zone, common_vol_zone)
202
203 -class VolumesZoneError(ClusterValidationError):
204 - def __init__(self, volumes):
205 self.msg = 'Volumes %s are not in the same availability zone' % ', '.join(volumes)
206
207 -class ClusterTemplateDoesNotExist(BaseException):
208 """ 209 Exception raised when user requests a cluster template that does not exist 210 """
211 - def __init__(self, cluster_name):
212 self.msg = "cluster template %s does not exist" % cluster_name
213
214 -class ClusterDoesNotExist(BaseException):
215 """ 216 Exception raised when user requests a running cluster that does not exist 217 """
218 - def __init__(self, cluster_name):
219 self.msg = "cluster %s does not exist" % cluster_name
220
221 -class ClusterExists(BaseException):
222 - def __init__(self, cluster_name):
223 self.msg = "Cluster with tag name %s already exists. " % cluster_name 224 self.msg += "\n\nEither choose a different tag name, or stop the " 225 self.msg += "existing cluster using:" 226 self.msg += "\n\n $ starcluster stop %s" % cluster_name 227 self.msg += "\n\nIf you wish to use these existing instances anyway, " + \ 228 "pass --no-create to the start command"
229
230 -class CancelledStartRequest(BaseException):
231 - def __init__(self, tag):
232 self.msg = "Request to start cluster '%s' was cancelled" % tag 233 self.msg += "\n\nPlease be aware that instances may still be running. " 234 self.msg += "\nYou can check this from the output of:" 235 self.msg += "\n\n $ starcluster listclusters" 236 self.msg += "\n\nIf you wish to destroy these instances please run:" 237 self.msg += "\n\n $ starcluster stop %s" % tag 238 self.msg += "\n\nYou can then use:\n\n $ starcluster listinstances" 239 self.msg += "\n\nto verify that the instances have been terminated." 240 self.msg += "\n\nAnother option is to use the AWS management console to" 241 self.msg += "\nterminate the instances manually." 242 self.msg += "\n\nIf you would like to re-use these instances, rerun the" 243 self.msg += "\nsame start command with the --no-create option"
244
245 -class CancelledCreateVolume(BaseException):
246 - def __init__(self):
247 self.msg = "Request to create volume was cancelled" 248 self.msg += "\n\nPlease be aware that the volume host instance may still" 249 self.msg += " be running. " 250 self.msg += "\n\nTo destroy this instance please run:" 251 self.msg += "\n\n $ starcluster stop %s" % static.VOLUME_GROUP_NAME 252 self.msg += "\n\nand then use\n\n $ starcluster listinstances" 253 self.msg += "\n\nto verify that this instance has been terminated." 254 self.msg += "\n\nAnother option is to use the AWS management console to" 255 self.msg += "\nterminate this instance manually."
256
257 -class CancelledCreateImage(BaseException):
258 - def __init__(self, bucket, image_name):
259 self.msg = "Request to createimage was cancelled" 260 self.msg += "\n\nDepending on how far along the process was before it " 261 self.msg += "was cancelled, \nsome intermediate files might still be " 262 self.msg += "around in /mnt on the instance. " 263 self.msg += "\n\nAlso, some of these intermediate files " 264 self.msg += "might have been uploaded to S3 in the '%s' bucket" % bucket 265 self.msg += "\nyou specified. You can check this by running: " 266 self.msg += "\n\n $ starcluster showbucket %s\n\n" % bucket 267 self.msg += "and looking for files like '%s.manifest.xml' " % image_name 268 self.msg += "or '%s.part.*'" % image_name 269 self.msg += "\nRe-executing the same creatimage command should take care " 270 self.msg += "of these \nintermediate files and will also automatically " 271 self.msg += "override any partially uploaded files in S3."
272
273 -class ExperimentalFeature(BaseException):
274 - def __init__(self, feature_name):
275 self.msg = "%s is an experimental feature for this " % feature_name 276 self.msg += "release. \nIf you wish to test this feature, set " 277 self.msg += "ENABLE_EXPERIMENTAL=True \nin the [global] section of the " 278 self.msg += "config. \nYou have officially been warned :D"
279