Class: AwsEc2::Profile
- Includes:
- Template
- Defined in:
- lib/aws_ec2/profile.rb
Constant Summary
Constants inherited from Base
Base::BUILD_ROOT, Base::SCRIPTS_INFO_PATH
Instance Method Summary collapse
- #check! ⇒ Object
- #load ⇒ Object
- #load_profile(file) ⇒ Object
- #profile_file(name) ⇒ Object
-
#profile_name ⇒ Object
Determines a valid profile_name.
Methods included from Template
Methods inherited from Base
#derandomize, #initialize, #randomize
Constructor Details
This class inherits a constructor from AwsEc2::Base
Instance Method Details
#check! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/aws_ec2/profile.rb', line 14 def check! file = profile_file(profile_name) return if File.exist?(file) 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 |
#load ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/aws_ec2/profile.rb', line 5 def load return @profile_params if @profile_params check! file = profile_file(profile_name) @profile_params = load_profile(file) end |
#load_profile(file) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/aws_ec2/profile.rb', line 23 def load_profile(file) return {} unless File.exist?(file) puts "Using profile: #{file}".colorize(:green) text = RenderMePretty.result(file, context: context) begin data = YAML.load(text) rescue Psych::SyntaxError => e tmp_file = file.sub("profiles", "tmp") IO.write(tmp_file, text) puts "There was an error evaluating in your yaml file #{file}".colorize(:red) puts "The evaludated yaml file has been saved at #{tmp_file} for debugging." puts "ERROR: #{e.}" exit 1 end data ? data : {} # in case the file is empty data.has_key?("run_instances") ? data["run_instances"] : data end |
#profile_file(name) ⇒ Object
60 61 62 |
# File 'lib/aws_ec2/profile.rb', line 60 def profile_file(name) "#{AwsEc2.root}/profiles/#{name}.yml" end |
#profile_name ⇒ Object
Determines a valid profile_name. Falls back to default
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aws_ec2/profile.rb', line 43 def profile_name # allow user to specify the path also if @options[:profile] && File.exist?(@options[:profile]) filename_profile = File.basename(@options[:profile], '.yml') end 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 |