2
# Programmer: Chris Bunch
4
FILE_FLAG_NOT_VALID_MSG = "File must be either a directory or end with .tar.gz"
5
IPS_FLAG_NOT_A_YAML_MSG = "YAML file must end with .yaml or .yml"
6
MIN_FLAG_NOT_A_NUM_MSG = "Min images must be a positive integer"
7
MAX_FLAG_NOT_A_NUM_MSG = "Max images must be a positive integer"
8
TABLE_FLAG_NOT_IN_SET_MSG = "Invalid table type. Table must be set to one of the following: #{VALID_TABLE_TYPES.join(', ')}"
9
MIN_FLAG_NOT_POSITIVE_MSG = "Minimum image number must be larger than zero"
10
MAX_FLAG_NOT_POSITIVE_MSG = "Maximum image number must be larger than zero"
12
MAX_SMALLER_THAN_MIN_MSG = "Maximum image number must be larger than the minimum image number"
14
YAML_CONTROL_MSG = "The provided IP yaml file did not have one IP address for the controller node"
16
EC2_USAGE_MSG = "You did not provide an ips.yaml file, and you did not provide a machine id."
17
EC2_IPS_MISSING_MSG = "You did not provide ips.yaml or its empty."
18
INSTANCE_FLAG_NOT_IN_SET_MSG = "The instance type you provided was not one of the allowed values. Currently we allow m1.large, m1.xlarge, and c1.xlarge as the instance types."
20
DJINN_SERVER_DIED_MSG = "\nEither the head node was unable to get IP addresses for any slave nodes or a bug in the head node's code caused it to crash. We have left your virtual machines running in case you wish to submit a bug report or investigate further via the Troubleshooting page."
22
RW_REQUIRES_VOLDEMORT_MSG = "The r and w flags can only be used in conjunction with the Voldemort database. Please either specify the voldemort database to be used or remove the r and w flags."
24
BACKUP_TAR_EXISTS_MSG = "The tar file you specified to back up to already exists. Please specify a new file name and try again."
25
RESTORE_TAR_NOT_EXISTS_MSG = "The tar file you specified to back up from does not exist. Please specify a new file name and try again."
27
FILE_REGEX = /\.tar\.gz$/
28
POS_NUM_REGEX = /^[1-9]\d*$/
29
TAR_REGEX = /\.tar\.gz$/
30
YAML_REGEX = /\.ya?ml$/
32
def parse_args(command_line)
33
raise if command_line.class != Array
38
command_line.each { |arg|
40
arg = arg[1, arg.length]
41
arg = arg[1, arg.length] if arg[0].chr == "-" # to handle --arg
43
if !ALL_FLAGS.include?(arg)
44
abort "The flag #{arg} cannot be used here.\n\n#{USAGE}"
47
arg_hash[arg] = "NO ARG"
49
arg_hash[arg_found] = arg
52
abort "The parameter #{arg} was specified without a corresponding flag."
59
arg_hash = parse_args(ARGV)
63
unless ALL_FLAGS.include?(flag)
64
message = "Flag #{flag} not recognized.\n\n" + USAGE
69
if arg_hash['help'] || arg_hash['h'] || arg_hash['usage']
73
if arg_hash['version']
78
abort(MIN_FLAG_NOT_A_NUM_MSG) if arg_hash['min'] !~ POS_NUM_REGEX
79
min_images = Integer(arg_hash['min'])
81
abort("--min needs to be at least one")
88
abort(MAX_FLAG_NOT_A_NUM_MSG) if arg_hash['max'] !~ POS_NUM_REGEX
89
max_images = Integer(arg_hash['max'])
91
unless arg_hash['min']
92
min_images = max_images
95
#max_images = min_images
98
#if min_images > max_images
99
# abort(MAX_SMALLER_THAN_MIN_MSG)
103
true_location = File.expand_path(arg_hash['file'])
104
file_doesnt_exist = "The specified AppEngine program, #{arg_hash['file']}," +
105
" didn't exist. Please specify one that exists and try again"
106
abort(file_doesnt_exist) unless File.exists?(true_location)
108
if not ((File.directory?(true_location)) or (true_location =~ TAR_REGEX))
109
abort(FILE_FLAG_NOT_VALID_MSG)
111
FILE_LOCATION = arg_hash['file']
117
abort(TABLE_FLAG_NOT_IN_SET_MSG) unless VALID_TABLE_TYPES.include?(arg_hash['table'])
118
TABLE = arg_hash['table']
123
if arg_hash['infrastructure']
124
abort(INFRASTRUCTURE_FLAG_NOT_IN_SET_MSG) unless VALID_CLOUD_TYPES.include?(arg_hash['infrastructure'])
125
INFRASTRUCTURE = arg_hash['infrastructure']
132
IPS = YAML.load_file(arg_hash['ips'])
134
ips_doesnt_exist = "The configuration file you specified, " +
135
"#{arg_hash['ips']}, did not exist. Please specify one that" +
136
" exists and try again."
137
abort(ips_doesnt_exist)
144
abort("n must be a positive integer") if arg_hash['n'] !~ POS_NUM_REGEX
146
REPLICATION = Integer(arg_hash['n'])
152
abort(RW_REQUIRES_VOLDEMORT_MSG) if TABLE != "voldemort"
154
VOLDEMORT_R = Integer(arg_hash['r'])
160
abort(RW_REQUIRES_VOLDEMORT_MSG) if TABLE != "voldemort"
162
VOLDEMORT_W = Integer(arg_hash['w'])
167
MIN_IMAGES = min_images
168
MAX_IMAGES = max_images
170
if arg_hash['machine']
171
MACHINE = arg_hash['machine']
172
if MACHINE == "NO ARG"
173
abort("You failed to provide an argument for the #{flag} flag. Please do so and try again.")
176
MACHINE = ENV['APPSCALE_MACHINE']
179
possible_instance_types = ["m1.large", "m1.xlarge", "c1.xlarge"]
180
if arg_hash['instance_type']
181
abort(INSTANCE_FLAG_NOT_IN_SET_MSG) unless possible_instance_types.include?(arg_hash['instance_type'])
182
INSTANCE_TYPE = arg_hash['instance_type']
184
INSTANCE_TYPE = "m1.large"
187
if arg_hash['v'] or arg_hash['verbose']
205
if arg_hash['keyname']
206
KEYNAME = arg_hash['keyname']
211
if arg_hash['appname']
212
APPNAME = arg_hash['appname'].gsub(/[^\w\d-]/, "")
217
if arg_hash['appengine']
218
APPENGINE = Integer(arg_hash['appengine'])
229
if arg_hash['separate']
236
EMAIL = arg_hash['email']
241
CONFIRM = !arg_hash['confirm'].nil?
243
if arg_hash['backup_to_tar']
244
if File.exists?(arg_hash['backup_to_tar'])
245
abort(BACKUP_TAR_EXISTS_MSG)
248
BACKUP_TAR_LOCATION = arg_hash['backup_to_tar']
250
BACKUP_TAR_LOCATION = nil
253
if arg_hash['backup_to_ebs']
254
BACKUP_EBS_LOCATION = arg_hash['backup_to_ebs']
256
BACKUP_EBS_LOCATION = nil
259
if arg_hash['restore_from_tar']
260
unless File.exists?(arg_hash['restore_from_tar'])
261
abort(RESTORE_TAR_NOT_EXISTS_MSG)
264
RESTORE_FROM_TAR = arg_hash['restore_from_tar']
266
RESTORE_FROM_TAR = nil
269
if arg_hash['restore_from_ebs']
270
RESTORE_FROM_EBS = arg_hash['restore_from_ebs']
272
RESTORE_FROM_EBS = nil
275
if FILE_LOCATION && (RESTORE_FROM_TAR || RESTORE_FROM_EBS)
276
bad_restore_params = "You cannot restore an AppScale instance " +
277
"and upload a new application. Please remove one and try again."
278
abort(bad_restore_params)