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.
41 42 43 44 |
# File 'lib/fog/clodo/models/compute/server.rb', line 41 def initialize(attributes={}) self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666 super attributes end |
Instance Method Details
#add_ip_address ⇒ Object
66 67 68 |
# File 'lib/fog/clodo/models/compute/server.rb', line 66 def add_ip_address service.add_ip_address(id) end |
#delete_ip_address(ip_address) ⇒ Object
74 75 76 |
# File 'lib/fog/clodo/models/compute/server.rb', line 74 def delete_ip_address(ip_address) service.delete_ip_address(id, ip_address) end |
#destroy ⇒ Object
46 47 48 49 50 |
# File 'lib/fog/clodo/models/compute/server.rb', line 46 def destroy requires :id service.delete_server(id) true end |
#image ⇒ Object
52 53 54 55 |
# File 'lib/fog/clodo/models/compute/server.rb', line 52 def image requires :image_id image_id # API does not support image details request. :-( end |
#move_ip_address(ip_address) ⇒ Object
70 71 72 |
# File 'lib/fog/clodo/models/compute/server.rb', line 70 def move_ip_address(ip_address) service.move_ip_address(id, ip_address) end |
#password ⇒ Object
113 114 115 |
# File 'lib/fog/clodo/models/compute/server.rb', line 113 def password vps_root_pass end |
#private_ip_address ⇒ Object
57 58 59 |
# File 'lib/fog/clodo/models/compute/server.rb', line 57 def private_ip_address nil end |
#public_ip_address ⇒ Object
61 62 63 64 |
# File 'lib/fog/clodo/models/compute/server.rb', line 61 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
78 79 80 |
# File 'lib/fog/clodo/models/compute/server.rb', line 78 def ready? self.state == 'is_running' end |
#reboot(type = 'SOFT') ⇒ Object
82 83 84 85 86 |
# File 'lib/fog/clodo/models/compute/server.rb', line 82 def reboot(type = 'SOFT') requires :id service.reboot_server(id, type) true end |
#save ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/fog/clodo/models/compute/server.rb', line 88 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
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fog/clodo/models/compute/server.rb', line 96 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
109 110 111 |
# File 'lib/fog/clodo/models/compute/server.rb', line 109 def ssh(commands) super(commands, password ? {:password => password} : {}) end |