Class: Coral::Cloud::Server
- Inherits:
-
Core
- Object
- Core
- Coral::Cloud::Server
- Defined in:
- lib/coral_cloud/server.rb
Instance Attribute Summary collapse
-
#cloud ⇒ Object
readonly
—————————————————————————– Property accessors / modifiers.
-
#machine ⇒ Object
—————————————————————————– Property accessors / modifiers.
-
#name ⇒ Object
readonly
—————————————————————————– Property accessors / modifiers.
Instance Method Summary collapse
-
#commit(options = {}) ⇒ Object
—————————————————————————–.
-
#destroy(options = {}) ⇒ Object
—————————————————————————–.
-
#hostname ⇒ Object
—.
-
#hostname=(hostname) ⇒ Object
—.
-
#initialize(options = {}) ⇒ Server
constructor
—————————————————————————– Constructor / Destructor.
-
#internal_ip ⇒ Object
—.
-
#internal_ip=(internal_ip) ⇒ Object
—.
-
#process_puppet_message(line) ⇒ Object
—————————————————————————– Utilities.
-
#public_ip ⇒ Object
—.
-
#public_ip=(public_ip) ⇒ Object
—.
-
#push(options = {}) ⇒ Object
—————————————————————————–.
-
#repositories(options = {}, return_objects = true) ⇒ Object
—————————————————————————–.
-
#shares(options = {}, return_objects = true) ⇒ Object
—.
-
#start(options = {}) ⇒ Object
—————————————————————————– Management.
-
#sync_remotes(options = {}) ⇒ Object
—————————————————————————– Repository operations.
-
#update(options = {}) ⇒ Object
—————————————————————————–.
-
#virtual_hostname ⇒ Object
—.
-
#virtual_hostname=(virtual_hostname) ⇒ Object
—.
-
#virtual_ip ⇒ Object
—.
-
#virtual_ip=(virtual_ip) ⇒ Object
—.
Constructor Details
#initialize(options = {}) ⇒ Server
Constructor / Destructor
9 10 11 12 13 14 |
# File 'lib/coral_cloud/server.rb', line 9 def initialize( = {}) super() self.machine = ( .has_key?(:machine) ? [:machine] : '' ) @cloud = ( .has_key?(:cloud) ? [:cloud] : Coral.create_cloud(@name, ) ) end |
Instance Attribute Details
#cloud ⇒ Object (readonly)
Property accessors / modifiers
19 20 21 |
# File 'lib/coral_cloud/server.rb', line 19 def cloud @cloud end |
#machine ⇒ Object
Property accessors / modifiers
19 20 21 |
# File 'lib/coral_cloud/server.rb', line 19 def machine @machine end |
#name ⇒ Object (readonly)
Property accessors / modifiers
19 20 21 |
# File 'lib/coral_cloud/server.rb', line 19 def name @name end |
Instance Method Details
#commit(options = {}) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/coral_cloud/server.rb', line 220 def commit( = {}) repositories().each do |name, repo| if repo.can_persist? repo.commit('.', ) end end return true end |
#destroy(options = {}) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/coral_cloud/server.rb', line 172 def destroy( = {}) return true if ! @machine if @machine.created? do_destroy = false if [:force] do_destroy = true else choice = nil begin choice = ui.ask("Are you sure you want to remove: #{@name}?") rescue Errors::UIExpectsTTY end do_destroy = choice.upcase == "Y" end if do_destroy @machine.destroy end end return true end |
#hostname ⇒ Object
36 37 38 |
# File 'lib/coral_cloud/server.rb', line 36 def hostname return @cloud.server(@name, 'hostname', '', :string) end |
#hostname=(hostname) ⇒ Object
42 43 44 |
# File 'lib/coral_cloud/server.rb', line 42 def hostname=hostname @cloud.set_server(@name, 'hostname', hostname) end |
#internal_ip ⇒ Object
60 61 62 |
# File 'lib/coral_cloud/server.rb', line 60 def internal_ip return @cloud.server(@name, 'internal_ip', '', :string) end |
#internal_ip=(internal_ip) ⇒ Object
66 67 68 |
# File 'lib/coral_cloud/server.rb', line 66 def internal_ip=internal_ip @cloud.set_server(@name, 'internal_ip', internal_ip) end |
#process_puppet_message(line) ⇒ Object
Utilities
249 250 251 |
# File 'lib/coral_cloud/server.rb', line 249 def (line) return line.match(/err:\s+/) ? { :success => false, :prefix => 'FAIL' } : true end |
#public_ip ⇒ Object
48 49 50 |
# File 'lib/coral_cloud/server.rb', line 48 def public_ip return @cloud.server(@name, 'public_ip', '', :string) end |
#public_ip=(public_ip) ⇒ Object
54 55 56 |
# File 'lib/coral_cloud/server.rb', line 54 def public_ip=public_ip @cloud.set_server(@name, 'public_ip', public_ip) end |
#push(options = {}) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/coral_cloud/server.rb', line 231 def push( = {}) sync_remotes() success = true repositories().each do |name, repo| if repo.can_persist? success = repo.push!(@name, ) do |line| (line) end break unless success end end return success end |
#repositories(options = {}, return_objects = true) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/coral_cloud/server.rb', line 96 def repositories( = {}, return_objects = true) repositories = array([:repos], @cloud.repositories.keys, true) results = ( return_objects ? {} : [] ) return results unless repositories.is_a?(Array) repositories.each do |repo_name| if @cloud.repositories.has_key?(repo_name) if return_objects results[repo_name] = @cloud.repositories[repo_name] else results << repo_name end end end return results end |
#shares(options = {}, return_objects = true) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/coral_cloud/server.rb', line 116 def shares( = {}, return_objects = true) shares = array([:shares], @cloud.shares.keys, true) results = ( return_objects ? {} : [] ) return results unless shares.is_a?(Array) shares.each do |share_name| if @cloud.shares.has_key?(share_name) if return_objects results[share_name] = @cloud.shares[share_name] else results << share_name end end end return results end |
#start(options = {}) ⇒ Object
Management
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/coral_cloud/server.rb', line 137 def start( = {}) sync_remotes() return true if ! @machine ["provision.enabled"] = false if @machine.created? @machine.start() else @machine.up() end return true end |
#sync_remotes(options = {}) ⇒ Object
Repository operations
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/coral_cloud/server.rb', line 199 def sync_remotes( = {}) repositories().each do |repo_name, repo| if repo.can_persist? if @name != 'all' repo.set_remote(@name, public_ip, ) end server_ips = [] @cloud.servers.each do |server_name, server| server_ips << server.public_ip end [:add] = true repo.set_remote('all', server_ips, ) end end return true end |
#update(options = {}) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/coral_cloud/server.rb', line 154 def update( = {}) sync_remotes() success = true return success if ! @machine if @machine.created? if @machine.state == :running success = Coral::Command.new("vagrant provision #{@name}").exec!() do |line| (line) end end end return success end |
#virtual_hostname ⇒ Object
72 73 74 |
# File 'lib/coral_cloud/server.rb', line 72 def virtual_hostname return @cloud.search(@name, 'virtual_hostname', '', :string) end |
#virtual_hostname=(virtual_hostname) ⇒ Object
78 79 80 |
# File 'lib/coral_cloud/server.rb', line 78 def virtual_hostname=virtual_hostname @cloud.set_server(@name, 'virtual_hostname', virtual_hostname) end |
#virtual_ip ⇒ Object
84 85 86 |
# File 'lib/coral_cloud/server.rb', line 84 def virtual_ip return @cloud.search(@name, 'virtual_ip', '', :string) end |
#virtual_ip=(virtual_ip) ⇒ Object
90 91 92 |
# File 'lib/coral_cloud/server.rb', line 90 def virtual_ip=virtual_ip @cloud.set_server(@name, 'virtual_ip', virtual_ip) end |