Class: Engineyard::Hudson::AppcloudEnv

Inherits:
Object
  • Object
show all
Includes:
EY::UtilityMethods
Defined in:
lib/engineyard-hudson/appcloud_env.rb

Instance Method Summary collapse

Instance Method Details

#clean_host_name(environment) ⇒ Object

Currently the engineyard gem has badly formed URLs in its same data This method cleans app_master_hostname.compute-1.amazonaws.com -> app-master-hostname.compute-1.amazonaws.com



44
45
46
# File 'lib/engineyard-hudson/appcloud_env.rb', line 44

def clean_host_name(environment)
  environment.instances.first.public_hostname.gsub!(/_/,'-') if environment.instances.first
end

#default_query_environmentsObject



38
39
40
# File 'lib/engineyard-hudson/appcloud_env.rb', line 38

def default_query_environments
  %w[hudson hudson_server hudson_production hudson_server_production]
end

#find_environments(options = {}) ⇒ Object

Returns [environment, account] based on current .eyrc credentials and/or CLI options Returns [nil, nil] if no unique environment can be selected



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/engineyard-hudson/appcloud_env.rb', line 13

def find_environments(options = {})
  Thor::Base.shell = EY::CLI::UI
  EY.ui = EY::CLI::UI.new
  query_environments = options[:environment] ? [options[:environment]] : default_query_environments
  query_environments.inject([]) do |envs, env_name|
    begin
      if environment = fetch_environment(env_name, options[:account])
        clean_host_name(environment)
        envs << [env_name, environment..name, environment]
      end
    rescue EY::NoEnvironmentError
    rescue EY::MultipleMatchesError => e
      # e.message looks something like:
      # Multiple environments possible, please be more specific:
      # 
      #   hudson # ey <command> --environment='hudson' --account='drnic-demo'
      #   hudson # ey <command> --environment='hudson' --account='rails-hudson'
      e.message.scan(/--environment='([^']+)' --account='([^']+)'/) do
        envs << [$1, $2, nil]
      end
    end
    envs
  end
end