Class: Fog::Compute::Clodo::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Clodo::Server
- Defined in:
- lib/fog/clodo/models/compute/server.rb
Instance Method Summary collapse
- #add_ip_address ⇒ Object
- #delete_ip_address(ip_address) ⇒ Object
- #destroy ⇒ Object
- #image ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #move_ip_address(ip_address) ⇒ Object
- #password ⇒ Object
- #private_ip_address ⇒ Object
- #public_ip_address ⇒ Object
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #ssh(commands) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
43 44 45 46 |
# File 'lib/fog/clodo/models/compute/server.rb', line 43 def initialize(attributes={}) self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666 super attributes end |
Instance Method Details
#add_ip_address ⇒ Object
68 69 70 |
# File 'lib/fog/clodo/models/compute/server.rb', line 68 def add_ip_address service.add_ip_address(id) end |
#delete_ip_address(ip_address) ⇒ Object
76 77 78 |
# File 'lib/fog/clodo/models/compute/server.rb', line 76 def delete_ip_address(ip_address) service.delete_ip_address(id, ip_address) end |
#destroy ⇒ Object
48 49 50 51 52 |
# File 'lib/fog/clodo/models/compute/server.rb', line 48 def destroy requires :id service.delete_server(id) true end |
#image ⇒ Object
54 55 56 57 |
# File 'lib/fog/clodo/models/compute/server.rb', line 54 def image requires :image_id image_id # API does not support image details request. :-( end |
#move_ip_address(ip_address) ⇒ Object
72 73 74 |
# File 'lib/fog/clodo/models/compute/server.rb', line 72 def move_ip_address(ip_address) service.move_ip_address(id, ip_address) end |
#password ⇒ Object
115 116 117 |
# File 'lib/fog/clodo/models/compute/server.rb', line 115 def password vps_root_pass end |
#private_ip_address ⇒ Object
59 60 61 |
# File 'lib/fog/clodo/models/compute/server.rb', line 59 def private_ip_address nil end |
#public_ip_address ⇒ Object
63 64 65 66 |
# File 'lib/fog/clodo/models/compute/server.rb', line 63 def public_ip_address pubaddrs = addresses && addresses['public'] ? addresses['public'].select {|ip| ip['primary_ip']} : nil pubaddrs && !pubaddrs.empty? ? pubaddrs.first['ip'] : nil end |
#ready? ⇒ Boolean
80 81 82 |
# File 'lib/fog/clodo/models/compute/server.rb', line 80 def ready? self.state == 'is_running' end |
#reboot(type = 'SOFT') ⇒ Object
84 85 86 87 88 |
# File 'lib/fog/clodo/models/compute/server.rb', line 84 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#save ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/fog/clodo/models/compute/server.rb', line 90 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :image_id data = service.create_server(image_id, attributes) merge_attributes(data.body['server']) true end |
#setup(credentials = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fog/clodo/models/compute/server.rb', line 98 def setup(credentials = {}) requires :ssh_ip_address, :identity, :public_key, :username Fog::SSH.new(ssh_ip_address, username, credentials).run([ %{mkdir .ssh}, %{echo "#{public_key}" >> ~/.ssh/authorized_keys}, %{passwd -l #{username}}, %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json}, ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#ssh(commands) ⇒ Object
111 112 113 |
# File 'lib/fog/clodo/models/compute/server.rb', line 111 def ssh(commands) super(commands, password ? {:password => password} : {}) end |