lib/EC2/instances.rb in kunley-amazon-ec2-0.3.4 vs lib/EC2/instances.rb in kunley-amazon-ec2-0.3.8
- old
+ new
@@ -88,22 +88,11 @@
raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
raise ArgumentError, ":addressing_type must be 'direct' or 'public'" unless options[:addressing_type] == "public" || options[:addressing_type] == "direct"
raise ArgumentError, ":instance_type must be 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', or 'c1.xlarge'" unless options[:instance_type] == "m1.small" || options[:instance_type] == "m1.large" || options[:instance_type] == "m1.xlarge" || options[:instance_type] == "c1.medium" || options[:instance_type] == "c1.xlarge"
raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
- # If :user_data is passed in then URL escape and Base64 encode it
- # as needed. Need for URL Escape + Base64 encoding is determined
- # by :base64_encoded param.
- if options[:user_data]
- if options[:base64_encoded]
- user_data = options[:user_data]
- else
- user_data = Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
- end
- else
- user_data = nil
- end
+ user_data = extract_user_data(options)
params = {
"ImageId" => options[:image_id],
"MinCount" => options[:min_count].to_s,
"MaxCount" => options[:max_count].to_s,
@@ -116,9 +105,23 @@
params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
return response_generator(:action => "RunInstances", :params => params)
+ end
+
+ # If :user_data is passed in then URL escape and Base64 encode it
+ # as needed. Need for URL Escape + Base64 encoding is determined
+ # by :base64_encoded param.
+ def extract_user_data(options)
+ return unless options[:user_data]
+ if options[:user_data]
+ if options[:base64_encoded]
+ Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
+ else
+ options[:user_data]
+ end
+ end
end
#Amazon Developer Guide Docs:
#