Class: Slugforge::Host
- Inherits:
-
Object
- Object
- Slugforge::Host
- Defined in:
- lib/slugforge/models/host.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#slug_name ⇒ Object
readonly
Returns the value of attribute slug_name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #add_action(action) ⇒ Object
- #complete? ⇒ Boolean
- #deploy(slug_name, logger, opts) ⇒ Object
- #effective_action ⇒ Object
- #elapsed_time ⇒ Object
- #failed? ⇒ Boolean
- #has_action?(action) ⇒ Boolean
- #id ⇒ Object
-
#initialize(pattern, server = nil) ⇒ Host
constructor
A new instance of Host.
- #install? ⇒ Boolean
- #ip ⇒ Object
- #is_autoscaled? ⇒ Boolean
- #name ⇒ Object
- #output ⇒ Object
- #record_event(status) ⇒ Object
- #remove_action(action) ⇒ Object
- #ssh_host ⇒ Object
- #stage? ⇒ Boolean
- #success? ⇒ Boolean
- #terminated? ⇒ Boolean
- #timeline ⇒ Object
- #to_status ⇒ Object
Constructor Details
#initialize(pattern, server = nil) ⇒ Host
Returns a new instance of Host.
8 9 10 11 12 13 14 15 16 |
# File 'lib/slugforge/models/host.rb', line 8 def initialize(pattern, server=nil) @pattern = pattern @server = server @deploy_results = [] @timeline = [] @start_time = Time.now @actions = [] self end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/slugforge/models/host.rb', line 6 def pattern @pattern end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
6 7 8 |
# File 'lib/slugforge/models/host.rb', line 6 def server @server end |
#slug_name ⇒ Object (readonly)
Returns the value of attribute slug_name.
6 7 8 |
# File 'lib/slugforge/models/host.rb', line 6 def slug_name @slug_name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/slugforge/models/host.rb', line 6 def status @status end |
Instance Method Details
#add_action(action) ⇒ Object
76 77 78 |
# File 'lib/slugforge/models/host.rb', line 76 def add_action(action) @actions << action end |
#complete? ⇒ Boolean
64 65 66 |
# File 'lib/slugforge/models/host.rb', line 64 def complete? success? || failed? end |
#deploy(slug_name, logger, opts) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/slugforge/models/host.rb', line 109 def deploy(slug_name, logger, opts) begin record_event :started if opts[:pretend] logger.log "not actually #{effective_action} slug (#{name})", {:color => :yellow, :status => :pretend} else logger.say_status :deploy, "#{effective_action} to host #{name} as #{username(opts)}", :green Net::SSH.start(ssh_host, username(opts), ssh_opts(opts)) do |ssh| host_slug = detect_slug(ssh, slug_name, logger) unless opts[:force] host_slug ||= copy_slug(ssh, slug_name, logger, opts) explode_slug(ssh, host_slug, logger, opts) if stage? install_slug(ssh, host_slug, logger, opts) if install? end end record_event :deployed rescue => e record_event :failed = "#{e.class.to_s}: #{e.to_s}" logger.log "#{} (#{ip}: #{name})", {:color => :red, :status => :fail} @deploy_results << {:output => } end logger.say_status :deploy, "#{effective_action} complete for host: #{name}", success? ? :green : :red @deploy_results end |
#effective_action ⇒ Object
96 97 98 99 |
# File 'lib/slugforge/models/host.rb', line 96 def effective_action return "installing" if @actions.include?(:install) "staging" end |
#elapsed_time ⇒ Object
51 52 53 |
# File 'lib/slugforge/models/host.rb', line 51 def elapsed_time Time.at(Time.now - @start_time).strftime('%M:%S') end |
#failed? ⇒ Boolean
72 73 74 |
# File 'lib/slugforge/models/host.rb', line 72 def failed? @status == :failed? end |
#has_action?(action) ⇒ Boolean
80 81 82 |
# File 'lib/slugforge/models/host.rb', line 80 def has_action?(action) @actions.include?(action) end |
#id ⇒ Object
30 31 32 |
# File 'lib/slugforge/models/host.rb', line 30 def id nil end |
#install? ⇒ Boolean
92 93 94 |
# File 'lib/slugforge/models/host.rb', line 92 def install? @actions.include?(:install) end |
#ip ⇒ Object
22 23 24 |
# File 'lib/slugforge/models/host.rb', line 22 def ip @pattern end |
#is_autoscaled? ⇒ Boolean
34 35 36 |
# File 'lib/slugforge/models/host.rb', line 34 def is_autoscaled? false end |
#name ⇒ Object
18 19 20 |
# File 'lib/slugforge/models/host.rb', line 18 def name "name:#{@pattern}" end |
#output ⇒ Object
105 106 107 |
# File 'lib/slugforge/models/host.rb', line 105 def output @deploy_results.map { |result| result[:output] unless result[:exit_code] == 0 }.compact end |
#record_event(status) ⇒ Object
55 56 57 58 |
# File 'lib/slugforge/models/host.rb', line 55 def record_event(status) @status = status @timeline << {:status => status, :elapsed_time => elapsed_time} end |
#remove_action(action) ⇒ Object
84 85 86 |
# File 'lib/slugforge/models/host.rb', line 84 def remove_action(action) @actions.delete(action) end |
#ssh_host ⇒ Object
26 27 28 |
# File 'lib/slugforge/models/host.rb', line 26 def ssh_host @pattern end |
#stage? ⇒ Boolean
88 89 90 |
# File 'lib/slugforge/models/host.rb', line 88 def stage? @actions.include?(:stage) end |
#success? ⇒ Boolean
68 69 70 |
# File 'lib/slugforge/models/host.rb', line 68 def success? [:deployed, :terminated].include?(@status) && output.empty? end |
#terminated? ⇒ Boolean
101 102 103 |
# File 'lib/slugforge/models/host.rb', line 101 def terminated? @status == :terminated? end |
#timeline ⇒ Object
60 61 62 |
# File 'lib/slugforge/models/host.rb', line 60 def timeline @timeline.map { |event| "#{event[:status]} @ #{event[:elapsed_time]}" }.join ', ' end |
#to_status ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/slugforge/models/host.rb', line 38 def to_status { :name => name, :ip => ip, :pattern => @pattern, :slug_name => @slug_name, :status => @status.to_s, :output => @deploy_results, :start_time => @start_time, :timeline => timeline, } end |