-
Notifications
You must be signed in to change notification settings - Fork 67
/
brenda-run
executable file
·169 lines (157 loc) · 8.25 KB
/
brenda-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/python
# Brenda -- Blender render tool for Amazon Web Services
# Copyright (C) 2013 James Yonan <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys, os, optparse
from brenda import aws, config, run, version
def main():
usage = """\
usage: %s [options] demand|spot|script|price|stop|cancel|status|init|reset-keys
Version:
Brenda %s
Synopsis:
Start an EC2 on-demand or spot instance.
Commands:
spot : queue a request to start a lower-cost "spot" instance at
a specified maximum cost per hour.
price : show current spot prices.
demand : start a higher-cost "on-demand" instance.
script : output brenda-node script to be run on remote instance.
stop : stop all running EC2 instances (less fine-grained than
"brenda-tool prune").
cancel : cancel all spot requests.
status : show status of current EC2 spot requests and instances.
init : do one-time initialization of new AWS account by creating
"brenda" SSH key name and Security Group.
reset-keys : undo the effects of "init" by deleting "brenda" SSH key
name and Security Group.
Required config vars:
AWS_ACCESS_KEY : Amazon Web Services access key.
AWS_SECRET_KEY : Amazon Web Services secret key.
SSH_PUBKEY : SSH public key that created EC2 instances will recognize
as an authorized key. Defaults to $HOME/.ssh/id_rsa.pub
BLENDER_PROJECT : directory containing .blend file and all supporting files
for render. May be a compressed file on S3 in zip format
or any format supported by tar, i.e.
s3://BUCKET/myproject.zip, or local directory on render
farm node i.e. file:///my/local/blender/project
May also be an EBS snapshot, i.e. ebs://snap-66c5dd62
or ebs://my-snapshot-name
WORK_QUEUE : name of SQS queue (e.g. sqs://QUEUE) containing render
work.
RENDER_OUTPUT : render farm will save render output to this S3 bucket/prefix,
e.g. s3://BUCKET or s3://BUCKET/PREFIX
Optional config vars:
AMI_ID : Amazon ID of AMI that will be started. This should be an AMI
that already has Brenda pre-installed%s.
EC2_REGION : EC2 region name, defaults to US standard (optional).
INSTANCE_TYPE : EC2 instance type.
BID_PRICE : maximum spot market bid price for EC2 instance in dollars per
hour. Must be specified on the command line, if not specified
as a config variable.
SSH_KEY_NAME : EC2 ssh key name, default='brenda'
SECURITY_GROUP : EC2 security group, default='brenda'
ADDITIONAL_EBS_0, ADDITIONAL_EBS_1, ... : Additional EBS snapshots that
should be attached to the render-farm instance before Blender is
started. EBS snapshots can be up to 1 TB in size and can be used to
provide assets and additional data to the render process.
Syntax: ADDITIONAL_EBS_0="ebs://MY_SNAPSHOT,DIRECTORY" will mount
MY_SNAPSHOT in DIRECTORY (relative to Blender project location).
Example: ADDITIONAL_EBS_0="ebs://snap-ab957cc2,freebase" will
mount the EBS snapshot snap-ab957cc2 in a directory called
freebase in the same directory as the Blender project.
USE_ISTORE : boolean (0|1) that controls whether render-farm work
dir will be placed on an EC2 instance store volume
(/mnt/brenda, override with WORK_DIR).
Defaults to 1 on instances that support instance store
volumes, 0 otherwise.
[Note: all optional vars supported by brenda-node can also be specified here]
Examples:
Show current running EC2 instances and spot requests.
$ brenda-run status
Show current spot market prices for configured instance type:
$ brenda-run price
Start 4 default instances on EC2 spot market at a maximum price
of $0.07 per instance-hour:
$ brenda-run -N 4 -p 0.07 spot
Start 4 default instances on EC2 using higher on-demand pricing:
$ brenda-run -N 4 demand
Stop all running Brenda EC2 instances in this account:
$ brenda-run stop
Cancel all spot-requests:
$ brenda-run cancel""" % (sys.argv[0], version.VERSION, aws.get_default_ami_with_fmt(" (default=%s)"))
parser = optparse.OptionParser(usage)
parser.disable_interspersed_args()
defconf = aws.config_file_name()
parser.add_option("-c", "--config", dest="config", default=defconf,
help="Configuration file (default: %default)")
parser.add_option("-a", "--ami", dest="ami",
help="AMI ID to use when starting EC2 instances, overrides config variable AMI_ID"+aws.get_default_ami_with_fmt(", default=%s"))
parser.add_option("-N", "--n-instances", type="int", dest="n_instances", default=1,
help="Number of EC2 instances to start, default=%default")
parser.add_option("-i", "--instance-type", dest="instance_type",
help="EC2 instance type, overrides config variable INSTANCE_TYPE")
parser.add_option("-p", "--price", dest="price",
help="Maximum price in dollars per hour to bid on spot instances, overrides config variable BID_PRICE")
parser.add_option("-P", "--persistent", action="store_true", dest="persistent",
help="Make spot requests persistent")
parser.add_option("-T", "--terminate", action="store_true", dest="terminate",
help="For stop, terminate EC2 instances instead of stopping them (required for spot instances)")
parser.add_option("-I", "--idle", action="store_true", dest="idle",
help="Start the EC2 instances in the idle state, without automatically running brenda-node to begin task processing")
parser.add_option("-t", "--threshold", type="int", dest="threshold", default=0,
help="Match only on instances whose uptime is > n minutes after the hour, default=%default")
parser.add_option("", "--imatch", dest="imatch",
help="Match only on specific instance type(s), provide as a comma-separated list of instance types")
parser.add_option("", "--no-ssh-keys", action="store_true", dest="no_ssh_keys",
help="for init/reset-keys, don't create/remove a 'brenda' ssh key pair on AWS")
parser.add_option("", "--no-security-group", action="store_true", dest="no_security_group",
help="for init/reset-keys, don't create/remove a 'brenda' security group on AWS")
parser.add_option("", "--aws-ssh-pull", action="store_true", dest="aws_ssh_pull",
help="don't use local ssh keys, instead pull them from AWS")
parser.add_option("-d", "--dry-run", action="store_true", dest="dry_run",
help="show what would be done without actually doing it")
# Get command line arguments...
( opts, args ) = parser.parse_args()
#print "OPTS", (opts, args)
if not args:
print >>sys.stderr, "no work, run with -h for usage"
sys.exit(2)
# Get configuration
conf = config.Config(opts.config, 'BRENDA_')
#print "CONFIG", conf
# dispatch
if args[0] == 'demand':
run.demand(opts, conf)
elif args[0] == 'spot':
run.spot(opts, conf)
elif args[0] == 'price':
run.price(opts, conf)
elif args[0] == 'stop':
run.stop(opts, conf)
elif args[0] == 'cancel':
run.cancel(opts, conf)
elif args[0] == 'status':
run.status(opts, conf)
elif args[0] == 'init':
run.init(opts, conf)
elif args[0] == 'reset-keys':
run.reset_keys(opts, conf)
elif args[0] == 'script':
run.script(opts, conf)
else:
print >>sys.stderr, "unrecognized command:", args[0]
sys.exit(2)
main()