Class: Fog::Compute::Vmfusion::Server
- Defined in:
- lib/fog/vmfusion/models/compute/server.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
- #private_key ⇒ Object
-
#private_key_path ⇒ Object
Just setting local versions of some variables that were going to use for SSH operations.
- #public_key ⇒ Object
- #public_key_path ⇒ Object
-
#username ⇒ Object
Sets up a conveinent way to SSH into a Fusion VM using credentials stored in your .fog file.
Attributes inherited from Model
Instance Method Summary collapse
-
#clone(name) ⇒ Object
Fussion doesn’t have the concept of templates so one just clones regular VMs.
-
#destroy(options = { :force => false }) ⇒ Object
Destroy, deletes the VM from the local disk but only hard stops the VM before doing so if you set :force to true.
-
#halt ⇒ Object
Halt and poweroff are just synonyms for stop.
-
#ipaddress ⇒ Object
We obtain the first ipaddress.
-
#mac_addresses ⇒ Object
Collecting all mac_addresses the VM has…mostly just because we are doing the same thing for the vSphere provider.
-
#path ⇒ Object
Path to the VM’s vmx file on the local disk.
-
#power_state ⇒ Object
The power state of the VM is commonly going to be three values; running, not running, or suspended.
- #poweroff ⇒ Object
- #private_ip_address ⇒ Object
-
#public_ip_address ⇒ Object
Keeping these three methods around for API compatibility reasons.
- #ready? ⇒ Boolean
-
#reboot ⇒ Object
Attempt a graceful shutdown, wait for the VM to completely shutdown and then start it again.
-
#resume ⇒ Object
Resuming from suspend is the same thing as start to Fusion.
-
#save ⇒ Object
There is currently no documented model of creating VMs from scratch sans Fusion’s wizard.
-
#scp(local_path, remote_path, upload_options = {}) ⇒ Object
SCP something to our VM.
-
#setup(credentials = {}) ⇒ Object
Sets up a new SSH key on the VM so one doesn’t need to use a password ever again.
-
#shutdown ⇒ Object
This is a graceful shutdown but Fusion is only capable of a graceful shutdown if tools are installed.
-
#ssh(commands) ⇒ Object
Simply spawn an SSH session.
-
#start(options = { :headless => false }) ⇒ Object
Start is pretty self explanatory…if you pass :headless as true you won’t get a console on launch.
- #state ⇒ Object
-
#stop ⇒ Object
Stop is a hard stop, like pulling out the power cord.
- #suspend ⇒ Object
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
16 17 18 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 16 def password @password end |
#private_key ⇒ Object
248 249 250 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 248 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
Just setting local versions of some variables that were going to use for SSH operations.
243 244 245 246 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 243 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
257 258 259 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 257 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
252 253 254 255 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 252 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#username ⇒ Object
Sets up a conveinent way to SSH into a Fusion VM using credentials stored in your .fog file.
182 183 184 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 182 def username @username ||= 'root' end |
Instance Method Details
#clone(name) ⇒ Object
Fussion doesn’t have the concept of templates so one just clones regular VMs.
27 28 29 30 31 32 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 27 def clone(name) requires :raw ::Fission::VM.clone(@raw[:fission].name,name) return connection.servers.get(name) end |
#destroy(options = { :force => false }) ⇒ Object
Destroy, deletes the VM from the local disk but only hard stops the VM before doing so if you set :force to true.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 36 def destroy( = { :force => false }) requires :raw if ready? if [:force] stop end end @raw[:fission].delete end |
#halt ⇒ Object
Halt and poweroff are just synonyms for stop.
77 78 79 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 77 def halt stop end |
#ipaddress ⇒ Object
We obtain the first ipaddress. This should generally be a safe assumption for Fusion. Even if an address is provided via NAT, bridge, or host only it will by accessible from the host machine the VM resides on.
150 151 152 153 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 150 def ipaddress requires :raw ip(@raw[:fission]) end |
#mac_addresses ⇒ Object
Collecting all mac_addresses the VM has…mostly just because we are doing the same thing for the vSphere provider.
174 175 176 177 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 174 def mac_addresses requires :raw macs(@raw[:fission]) end |
#path ⇒ Object
Path to the VM’s vmx file on the local disk.
141 142 143 144 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 141 def path requires :raw @raw[:fission].path end |
#power_state ⇒ Object
The power state of the VM is commonly going to be three values; running, not running, or suspended.
130 131 132 133 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 130 def power_state requires :raw @raw[:fission].state.data end |
#poweroff ⇒ Object
81 82 83 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 81 def poweroff stop end |
#private_ip_address ⇒ Object
164 165 166 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 164 def private_ip_address ipaddress end |
#public_ip_address ⇒ Object
Keeping these three methods around for API compatibility reasons. Makes the vmfusion provider function similar to cloud providers and the vsphere provider. Future goal is to add an actual private and public concept. Needs changes to fission and a determination what is a public or private address here; bridge, nat, host-only.
160 161 162 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 160 def public_ip_address ipaddress end |
#ready? ⇒ Boolean
135 136 137 138 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 135 def ready? requires :raw @raw[:fission].running?.data end |
#reboot ⇒ Object
Attempt a graceful shutdown, wait for the VM to completely shutdown and then start it again.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 100 def reboot if ready? shutdown wait_for { ! ready? } start return true else return false end end |
#resume ⇒ Object
Resuming from suspend is the same thing as start to Fusion.
112 113 114 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 112 def resume start end |
#save ⇒ Object
There is currently no documented model of creating VMs from scratch sans Fusion’s wizard.
21 22 23 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 21 def save raise Fog::Errors::Error.new('Creating a new vm is not yet supported') end |
#scp(local_path, remote_path, upload_options = {}) ⇒ Object
SCP something to our VM.
200 201 202 203 204 205 206 207 208 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 200 def scp(local_path, remote_path, = {}) requires :ipaddress, :username = {} [:password] = password unless self.password.nil? [:key_data] = [private_key] if self.private_key Fog::SCP.new(ipaddress, username, ).upload(local_path, remote_path, ) end |
#setup(credentials = {}) ⇒ Object
Sets up a new SSH key on the VM so one doesn’t need to use a password ever again.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 212 def setup(credentials = {}) requires :public_key, :ipaddress, :username credentials[:password] = password unless self.password.nil? credentails[:key_data] = [private_key] if self.private_key commands = [ %{mkdir .ssh}, ] if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end # wait for domain to be ready Timeout::timeout(360) do begin Timeout::timeout(8) do Fog::SSH.new(ipaddress, username, credentials.merge(:timeout => 4)).run('pwd') end rescue Errno::ECONNREFUSED sleep(2) retry rescue Net::SSH::AuthenticationFailed, Timeout::Error retry end end Fog::SSH.new(ipaddress, username, credentials).run(commands) end |
#shutdown ⇒ Object
This is a graceful shutdown but Fusion is only capable of a graceful shutdown if tools are installed. Fusion does the right thing though and if graceful can’t be initiated it just does a hard stop.
88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 88 def shutdown requires :raw if ready? @raw[:fission].stop return true else return false end end |
#ssh(commands) ⇒ Object
Simply spawn an SSH session.
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 187 def ssh(commands) requires :ipaddress, :username #requires :password, :private_key ={} [:password] = password unless password.nil? [:key_data] = [private_key] if private_key Fog::SSH.new(ipaddress, @username, ).run(commands) end |
#start(options = { :headless => false }) ⇒ Object
Start is pretty self explanatory…if you pass :headless as true you won’t get a console on launch.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 50 def start( = { :headless => false }) requires :raw unless ready? @raw[:fission].start(:headless => [:headless]) return true else return false end end |
#state ⇒ Object
168 169 170 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 168 def state power_state end |
#stop ⇒ Object
Stop is a hard stop, like pulling out the power cord.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 65 def stop requires :raw if ready? @raw[:fission].stop(:hard => true) return true else return false end end |
#suspend ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/fog/vmfusion/models/compute/server.rb', line 116 def suspend requires :raw if ready? @raw[:fission].suspend return true else return false end end |