mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add clodo support.
This commit is contained in:
parent
eb282c4fb6
commit
05d1ae032d
20 changed files with 878 additions and 0 deletions
31
lib/fog/clodo/models/compute/image.rb
Normal file
31
lib/fog/clodo/models/compute/image.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
|
||||
class Image < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :vps_type
|
||||
attribute :status
|
||||
attribute :os_type
|
||||
attribute :os_bits
|
||||
attribute :os_hvm
|
||||
|
||||
def initialize(new_attributes)
|
||||
super(new_attributes)
|
||||
merge_attributes(new_attributes['_attr']) if new_attributes['_attr']
|
||||
end
|
||||
|
||||
def ready?
|
||||
status == 'ACTIVE'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
25
lib/fog/clodo/models/compute/images.rb
Normal file
25
lib/fog/clodo/models/compute/images.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/clodo/models/compute/image'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
|
||||
class Images < Fog::Collection
|
||||
|
||||
model Fog::Compute::Clodo::Image
|
||||
|
||||
def all
|
||||
data = connection.list_images_detail.body['images']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
157
lib/fog/clodo/models/compute/server.rb
Normal file
157
lib/fog/clodo/models/compute/server.rb
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
|
||||
class Server < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :addresses
|
||||
attribute :name
|
||||
attribute :image_id, :aliases => 'imageId'
|
||||
attribute :state, :aliases => 'status'
|
||||
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
|
||||
|
||||
attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
|
||||
|
||||
def initialize(attributes={})
|
||||
self.image_id ||= attributes[:vps_os] ? attributes[:vps_os] : 666
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_server(id)
|
||||
true
|
||||
end
|
||||
|
||||
def image
|
||||
requires :image_id
|
||||
image_id # API does not support image details request. :-(
|
||||
end
|
||||
|
||||
def private_ip_address
|
||||
nil
|
||||
end
|
||||
|
||||
def private_key_path
|
||||
@private_key_path ||= Fog.credentials[:private_key_path]
|
||||
@private_key_path &&= File.expand_path(@private_key_path)
|
||||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= private_key_path && File.read(private_key_path)
|
||||
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
|
||||
|
||||
def public_key_path
|
||||
@public_key_path ||= Fog.credentials[:public_key_path]
|
||||
@public_key_path &&= File.expand_path(@public_key_path)
|
||||
end
|
||||
|
||||
def public_key
|
||||
@public_key ||= public_key_path && File.read(public_key_path)
|
||||
end
|
||||
|
||||
def ready?
|
||||
self.state == 'is_running'
|
||||
end
|
||||
|
||||
def reboot(type = 'SOFT')
|
||||
requires :id
|
||||
connection.reboot_server(id, type)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
requires :image_id
|
||||
options = {
|
||||
'name' => name
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
data = connection.create_server(image_id, options)
|
||||
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}},
|
||||
%{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json},
|
||||
%{echo "#{MultiJson.encode(metadata)}" >> ~/metadata.json}
|
||||
])
|
||||
rescue Errno::ECONNREFUSED
|
||||
sleep(1)
|
||||
retry
|
||||
end
|
||||
|
||||
def ssh(commands)
|
||||
requires :public_ip_address, :identity, :username
|
||||
|
||||
options = {}
|
||||
options[:key_data] = [private_key] if private_key
|
||||
Fog::SSH.new(public_ip_address, username, options).run(commands)
|
||||
end
|
||||
|
||||
def scp(local_path, remote_path, upload_options = {})
|
||||
requires :public_ip_address, :username
|
||||
|
||||
scp_options = {}
|
||||
scp_options[:key_data] = [private_key] if private_key
|
||||
Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options)
|
||||
end
|
||||
|
||||
def username
|
||||
@username ||= 'root'
|
||||
end
|
||||
|
||||
def password
|
||||
vps_root_pass
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
### def adminPass=(new_admin_pass)
|
||||
### @vps_root_pass= new_admin_pass
|
||||
### end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
36
lib/fog/clodo/models/compute/servers.rb
Normal file
36
lib/fog/clodo/models/compute/servers.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/clodo/models/compute/server'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
|
||||
class Servers < Fog::Collection
|
||||
|
||||
model Fog::Compute::Clodo::Server
|
||||
|
||||
def all
|
||||
data = connection.list_servers_detail.body['servers']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def bootstrap(new_attributes = {})
|
||||
server = create(new_attributes)
|
||||
server.wait_for { ready? }
|
||||
server.setup(:password => server.password)
|
||||
server
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
if server = connection.get_server_details(server_id).body['server']
|
||||
new(server)
|
||||
end
|
||||
rescue Fog::Compute::Clodo::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue