Class: Fog::Compute::Vmfusion::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Vmfusion::Server
- Defined in:
- lib/fog/compute/vmfusion/server.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
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
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/fog/compute/vmfusion/server.rb', line 14 def password @password end |
Instance Method Details
#clone(name) ⇒ Object
Fussion doesn’t have the concept of templates so one just clones regular VMs.
24 25 26 27 28 29 |
# File 'lib/fog/compute/vmfusion/server.rb', line 24 def clone(name) requires :raw ::Fission::VM.clone(@raw[:fission].name,name) return service.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.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/compute/vmfusion/server.rb', line 33 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.
74 75 76 |
# File 'lib/fog/compute/vmfusion/server.rb', line 74 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.
147 148 149 150 |
# File 'lib/fog/compute/vmfusion/server.rb', line 147 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.
171 172 173 174 |
# File 'lib/fog/compute/vmfusion/server.rb', line 171 def mac_addresses requires :raw macs(@raw[:fission]) end |
#path ⇒ Object
Path to the VM’s vmx file on the local disk.
138 139 140 141 |
# File 'lib/fog/compute/vmfusion/server.rb', line 138 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.
127 128 129 130 |
# File 'lib/fog/compute/vmfusion/server.rb', line 127 def power_state requires :raw @raw[:fission].state.data end |
#poweroff ⇒ Object
78 79 80 |
# File 'lib/fog/compute/vmfusion/server.rb', line 78 def poweroff stop end |
#private_ip_address ⇒ Object
161 162 163 |
# File 'lib/fog/compute/vmfusion/server.rb', line 161 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.
157 158 159 |
# File 'lib/fog/compute/vmfusion/server.rb', line 157 def public_ip_address ipaddress end |
#ready? ⇒ Boolean
132 133 134 135 |
# File 'lib/fog/compute/vmfusion/server.rb', line 132 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.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fog/compute/vmfusion/server.rb', line 97 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.
109 110 111 |
# File 'lib/fog/compute/vmfusion/server.rb', line 109 def resume start end |
#save ⇒ Object
There is currently no documented model of creating VMs from scratch sans Fusion’s wizard.
18 19 20 |
# File 'lib/fog/compute/vmfusion/server.rb', line 18 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.
185 186 187 188 189 190 191 192 193 |
# File 'lib/fog/compute/vmfusion/server.rb', line 185 def scp(local_path, remote_path, = {}) requires :ssh_ip_address, :username = {} [:password] = password unless self.password.nil? [:key_data] = [private_key] if self.private_key Fog::SCP.new(ssh_ip_address, 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.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/fog/compute/vmfusion/server.rb', line 197 def setup(credentials = {}) requires :public_key, :ssh_ip_address, :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(ssh_ip_address, 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(ssh_ip_address, 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.
85 86 87 88 89 90 91 92 93 |
# File 'lib/fog/compute/vmfusion/server.rb', line 85 def shutdown requires :raw if ready? @raw[:fission].stop return true else return false end end |
#ssh(commands) ⇒ Object
Simply spawn an SSH session.
180 181 182 |
# File 'lib/fog/compute/vmfusion/server.rb', line 180 def ssh(commands) super(commands, password ? {:password => password} : {}) 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.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/compute/vmfusion/server.rb', line 47 def start( = { :headless => false }) requires :raw unless ready? @raw[:fission].start(:headless => [:headless]) return true else return false end end |
#state ⇒ Object
165 166 167 |
# File 'lib/fog/compute/vmfusion/server.rb', line 165 def state power_state end |
#stop ⇒ Object
Stop is a hard stop, like pulling out the power cord.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fog/compute/vmfusion/server.rb', line 62 def stop requires :raw if ready? @raw[:fission].stop(:hard => true) return true else return false end end |
#suspend ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/fog/compute/vmfusion/server.rb', line 113 def suspend requires :raw if ready? @raw[:fission].suspend return true else return false end end |