Skip to content
Browse files

support --backup-id on launch (cloudtask and cloudtask-launch-workers)

  • Loading branch information...
1 parent b2c74bc commit 7db5e8fe64f5a83baafa3d1f3aaefc929ceee120 @lirazsiri lirazsiri committed Aug 3, 2011
Showing with 52 additions and 26 deletions.
  1. +10 −1 cloudtask/_hub.py
  2. +29 −19 cloudtask/task.py
  3. +4 −1 cloudtask/taskconf.py
  4. +9 −5 cmd_launch_workers.py
View
11 cloudtask/_hub.py
@@ -14,6 +14,7 @@ def __init__(self, apikey, wait_first=5, wait_status=0, wait_retry=5, retries=2)
self.apikey = apikey
self.wait_first = wait_first
self.wait_status = wait_status
+ self.wait_retry = wait_retry
self.retries = retries
def retry(self, callable, *args, **kwargs):
@@ -24,6 +25,9 @@ def retry(self, callable, *args, **kwargs):
if e.name == 'HubAccount.InvalidApiKey':
raise self.Error(e)
+ if e.name == 'BackupRecord.NotFound':
+ raise self.Error(e)
+
time.sleep(self.wait_retry)
raise self.Error(e)
@@ -39,9 +43,14 @@ def launch(self, howmany, **kwargs):
time_started = time.time()
kwargs.update(sec_updates='SKIP')
+
+ name = kwargs.pop('backup_id', None)
+ if not name:
+ name = 'core'
+
while True:
if len(pending_ids) < howmany:
- server = retry(hub.servers.launch, 'core', **kwargs)
+ server = retry(hub.servers.launch, name, **kwargs)
pending_ids.add(server.instanceid)
if time.time() - time_started < self.wait_first:
View
48 cloudtask/task.py
@@ -8,31 +8,31 @@
3) CLOUDTASK_{PARAM_NAME} environment variable (lowest precedence)
Options:
- --force Don't ask for confirmation
+ --force Don't ask for confirmation
- --hub-apikey= Hub API KEY (required if launching workers)
-
- --ec2-region= Region for instance launch (default: us-east-1)
- --ec2-size= Instance launch size (default: m1.small)
- --ec2-type= Instance launch type <s3|ebs> (default: s3)
+ --hub-apikey= Hub API KEY (required if launching workers)
+ --backup-id= TurnKey Backup ID to restore on launch
+ --ec2-region= Region for instance launch (default: us-east-1)
+ --ec2-size= Instance launch size (default: m1.small)
+ --ec2-type= Instance launch type <s3|ebs> (default: s3)
- --sessions= Path where sessions are stored (default: $HOME/.cloudtask)
+ --sessions= Path where sessions are stored (default: $HOME/.cloudtask)
- --user= Username to execute commands as (default: root)
- --pre= Worker setup command
- --post= Worker cleanup command
- --overlay= Path to worker filesystem overlay
- --timeout= How many seconds to wait before giving up
- --split= Number of workers to execute jobs in parallel
+ --user= Username to execute commands as (default: root)
+ --pre= Worker setup command
+ --post= Worker cleanup command
+ --overlay= Path to worker filesystem overlay
+ --timeout= How many seconds to wait before giving up
+ --split= Number of workers to execute jobs in parallel
- --workers= List of pre-launched workers to use
+ --workers= List of pre-launched workers to use
- path/to/file | host-1 ... host-N
+ path/to/file | host-1 ... host-N
- --report= Task reporting hook, examples:
+ --report= Task reporting hook, examples:
- sh: command || py: file || py: code
- mail: from@foo.com to@bar.com
+ sh: command || py: file || py: code
+ mail: from@foo.com to@bar.com
Usage:
@@ -107,7 +107,8 @@ def filter(job):
table = [ ('jobs', '%d (%s)' % (len(jobs), job_range)) ]
for attr in ('command', 'hub-apikey',
- 'ec2-region', 'ec2-size', 'ec2-type', 'user', 'workers',
+ 'ec2-region', 'ec2-size', 'ec2-type',
+ 'user', 'backup-id', 'workers',
'overlay', 'post', 'pre', 'timeout', 'report'):
val = taskconf[attr.replace('-', '_')]
@@ -223,6 +224,15 @@ def main(cls):
if taskconf.split == 1:
taskconf.split = None
+ elif opt == '--backup-id':
+ try:
+ taskconf.backup_id = int(val)
+ except ValueError:
+ error("--backup-id '%s' is not an integer " % val)
+
+ if taskconf.backup_id < 1:
+ error("--backup-id can't be smaller than 1")
+
else:
opt = opt[2:]
taskconf[opt.replace('-', '_')] = val
View
5 cloudtask/taskconf.py
@@ -7,12 +7,13 @@ class TaskConf:
post = None
overlay = None
- hub_apikey = None
timeout = None
split = None
workers = []
+ hub_apikey = None
+ backup_id = None
ec2_region = 'us-east-1'
ec2_size = 'm1.small'
ec2_type = 's3'
@@ -49,4 +50,6 @@ def ec2_opts(self):
for attr in self.__all__
if attr.startswith('ec2_') ])
opts['label'] = 'Cloudtask: ' + self.command
+ if self.backup_id:
+ opts['backup_id'] = self.backup_id
return opts
View
14 cmd_launch_workers.py
@@ -11,6 +11,8 @@
--apikey Hub APIKEY
Environment: HUB_APIKEY
+ --backup-id TurnKey Backup ID to restore
+
--region Region for instance launch (default: us-east-1)
Regions:
@@ -64,15 +66,17 @@ def main():
'size': "m1.small",
'type': "s3",
'label': "Cloudtask worker",
+ 'backup_id': None,
}
apikey = os.environ.get('HUB_APIKEY', os.environ.get('CLOUDTASK_APIKEY'))
try:
- opts, args = getopt.getopt(sys.argv[1:],
- 'h', [ 'help',
- 'apikey=' ] +
- [ key + '=' for key in kwargs ])
+ opts, args = getopt.gnu_getopt(sys.argv[1:],
+ 'h', [ 'help',
+ 'apikey=' ] +
+ [ key.replace('_', '-') + '='
+ for key in kwargs ])
except getopt.GetoptError, e:
usage(e)
@@ -84,7 +88,7 @@ def main():
apikey = val
for key in kwargs:
- if opt == '--' + key:
+ if opt == '--' + key.replace('_', '-'):
kwargs[key] = val
break

0 comments on commit 7db5e8f

Please sign in to comment.
Something went wrong with that request. Please try again.