1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/clodo/models/compute/server.rb

127 lines
3.3 KiB
Ruby
Raw Normal View History

require 'fog/compute/models/server'
2011-09-30 17:45:09 -04:00
module Fog
module Compute
class Clodo
class Server < Fog::Compute::Server
2011-09-30 17:45:09 -04:00
identity :id
attribute :addresses
attribute :name
attribute :image_id, :aliases => 'imageId'
attribute :type
2011-09-30 17:45:09 -04:00
attribute :state, :aliases => 'status'
attribute :type
2011-09-30 17:45:09 -04:00
attribute :vps_memory
attribute :vps_memory_max
attribute :vps_os_title
attribute :vps_os_bits
attribute :vps_os_type
attribute :vps_vnc
attribute :vps_cpu_load
attribute :vps_cpu_max
attribute :vps_cpu_1h_min
attribute :vps_cpu_1h_max
attribute :vps_mem_load
attribute :vps_mem_max
attribute :vps_mem_1h_min
attribute :vps_mem_1h_max
attribute :vps_hdd_load
attribute :vps_hdd_max
attribute :vps_traf_rx
attribute :vps_traf_tx
attribute :vps_createdate
attribute :vps_billingdate
attribute :vps_update
attribute :vps_update_days
attribute :vps_root_pass, :aliases => ['adminPass','password']
attribute :vps_user_pass
attribute :vps_vnc_pass
def initialize(attributes={})
self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666
2011-10-14 15:19:12 -04:00
super attributes
2011-09-30 17:45:09 -04:00
end
def destroy
requires :id
2012-12-22 18:29:06 -05:00
service.delete_server(id)
2011-09-30 17:45:09 -04:00
true
end
def image
requires :image_id
image_id # API does not support image details request. :-(
end
def private_ip_address
nil
end
def public_ip_address
pubaddrs = addresses && addresses['public'] ? addresses['public'].select {|ip| ip['primary_ip']} : nil
pubaddrs && !pubaddrs.empty? ? pubaddrs.first['ip'] : nil
end
2011-11-27 15:05:46 -05:00
def add_ip_address
2012-12-22 18:29:06 -05:00
service.add_ip_address(id)
2011-11-27 15:05:46 -05:00
end
def move_ip_address(ip_address)
2012-12-22 18:29:06 -05:00
service.move_ip_address(id, ip_address)
2011-11-27 15:05:46 -05:00
end
def delete_ip_address(ip_address)
2012-12-22 18:29:06 -05:00
service.delete_ip_address(id, ip_address)
2011-11-27 15:05:46 -05:00
end
2011-09-30 17:45:09 -04:00
def ready?
self.state == 'is_running'
end
def reboot(type = 'SOFT')
requires :id
2012-12-22 18:29:06 -05:00
service.reboot_server(id, type)
2011-09-30 17:45:09 -04:00
true
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
2011-09-30 17:45:09 -04:00
requires :image_id
2012-12-22 18:29:06 -05:00
data = service.create_server(image_id, attributes)
2011-09-30 17:45:09 -04:00
merge_attributes(data.body['server'])
true
end
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
Fog::SSH.new(public_ip_address, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l #{username}},
2012-04-25 10:31:28 -04:00
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
2011-09-30 17:45:09 -04:00
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
def ssh(commands)
super(commands, password ? {:password => password} : {})
2011-09-30 17:45:09 -04:00
end
def password
vps_root_pass
2011-09-30 17:45:09 -04:00
end
private
end
end
end
end