lib/aws_ec2/profile.rb in aws-ec2-0.9.0 vs lib/aws_ec2/profile.rb in aws-ec2-1.0.0
- old
+ new
@@ -1,48 +1,55 @@
module AwsEc2
- class Profile
- include TemplateHelper
+ class Profile < Base
+ include AwsEc2::Template
- def initialize(options)
- @options = options
- end
-
def load
return @profile_params if @profile_params
check!
- @profile_params = load_profile(profile_file)
+ file = profile_file(profile_name)
+ @profile_params = load_profile(file)
end
def check!
- return if File.exist?(profile_file)
+ file = profile_file(profile_name)
+ return if File.exist?(file)
- puts "Unable to find a #{profile_file.colorize(:green)} profile file."
- puts "Please double check that it exists or that you specified the right profile."
- exit # EXIT HERE
+ puts "Unable to find a #{file.colorize(:green)} profile file."
+ puts "Please double check that it exists or that you specified the right profile.".colorize(:red)
+ exit 1
end
def load_profile(file)
return {} unless File.exist?(file)
puts "Using profile: #{file}".colorize(:green)
- data = YAML.load(erb_result(file))
+ text = RenderMePretty.result(file, context: context)
+ data = YAML.load(text)
data ? data : {} # in case the file is empty
data.has_key?("run_instances") ? data["run_instances"] : data
end
- def profile_file
- "#{AwsEc2.root}/profiles/#{profile_name}.yml"
- end
-
+ # Determines a valid profile_name. Falls back to default
def profile_name
# allow user to specify the path also
if @options[:profile] && File.exist?(@options[:profile])
- profile = File.basename(@options[:profile], '.yml')
+ filename_profile = File.basename(@options[:profile], '.yml')
end
- # conventional profile is the name of the ec2 instance
- profile || @options[:profile] || "default"
+ name = derandomize(@name)
+ if File.exist?(profile_file(name))
+ name_profile = name
+ end
+
+ filename_profile ||
+ @options[:profile] ||
+ name_profile || # conventional profile is the name of the ec2 instance
+ "default"
+ end
+
+ def profile_file(name)
+ "#{AwsEc2.root}/profiles/#{name}.yml"
end
end
end