2011-08-10 09:03:51 -04:00
|
|
|
require 'fog/compute/models/server'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Glesys
|
|
|
|
|
|
|
|
class Server < Fog::Compute::Server
|
|
|
|
extend Fog::Deprecation
|
|
|
|
|
|
|
|
identity :serverid
|
|
|
|
|
|
|
|
attribute :hostname
|
|
|
|
attribute :datacenter
|
|
|
|
attribute :cpucores
|
|
|
|
attribute :memorysize
|
|
|
|
attribute :disksize
|
|
|
|
attribute :transfer
|
2013-02-09 08:53:51 -05:00
|
|
|
attribute :uptime
|
2012-02-20 14:36:39 -05:00
|
|
|
attribute :templatename
|
2011-08-10 09:03:51 -04:00
|
|
|
attribute :managedhosting
|
|
|
|
attribute :platform
|
|
|
|
attribute :cost
|
2012-02-20 14:36:39 -05:00
|
|
|
attribute :rootpassword
|
2011-08-10 09:03:51 -04:00
|
|
|
attribute :state
|
|
|
|
attribute :iplist
|
2013-01-22 15:26:22 -05:00
|
|
|
attribute :description
|
2013-02-09 08:53:51 -05:00
|
|
|
attribute :usage
|
2013-01-27 06:26:17 -05:00
|
|
|
attribute :glera_enabled, :aliases => "gleraenabled"
|
|
|
|
attribute :supported_features, :aliases => "supportedfeatures"
|
2011-08-10 09:03:51 -04:00
|
|
|
|
|
|
|
def ready?
|
|
|
|
state == 'running'
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
requires :identity
|
2012-12-22 18:27:08 -05:00
|
|
|
service.start(:serverid => identity)
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
requires :identity
|
2012-12-22 18:27:08 -05:00
|
|
|
service.stop(:serverid => identity)
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
2012-06-12 08:54:07 -04:00
|
|
|
def reboot
|
|
|
|
requires :identity
|
2012-12-22 18:27:08 -05:00
|
|
|
service.reboot(:serverid => identity)
|
2012-06-12 08:54:07 -04:00
|
|
|
end
|
|
|
|
|
2013-01-27 06:01:32 -05:00
|
|
|
def destroy(options = {})
|
2011-08-10 09:03:51 -04:00
|
|
|
requires :identity
|
2013-01-27 06:01:32 -05:00
|
|
|
service.destroy(options.merge!({:serverid => identity}))
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
raise "Operation not supported" if self.identity
|
2012-02-20 14:36:39 -05:00
|
|
|
requires :hostname, :rootpassword
|
2011-08-10 09:03:51 -04:00
|
|
|
|
|
|
|
options = {
|
2012-02-20 14:36:39 -05:00
|
|
|
:datacenter => datacenter || "Falkenberg",
|
|
|
|
:platform => platform || "Xen",
|
|
|
|
:hostname => hostname,
|
|
|
|
:templatename => templatename || "Debian-6 x64",
|
|
|
|
:disksize => disksize || "10",
|
|
|
|
:memorysize => memorysize || "512",
|
|
|
|
:cpucores => cpucores || "1",
|
|
|
|
:rootpassword => rootpassword,
|
|
|
|
:transfer => transfer || "500",
|
2012-12-22 18:27:08 -05:00
|
|
|
}
|
|
|
|
data = service.create(options)
|
2011-08-10 09:03:51 -04:00
|
|
|
merge_attributes(data.body['response']['server'])
|
|
|
|
data.status == 200 ? true : false
|
|
|
|
end
|
2012-02-20 14:36:39 -05:00
|
|
|
|
2013-01-27 08:56:05 -05:00
|
|
|
def setup(credentials = {})
|
|
|
|
requires :public_ip_address, :username
|
|
|
|
require 'net/ssh'
|
|
|
|
|
|
|
|
attrs = attributes.dup
|
|
|
|
attrs.delete(:rootpassword)
|
|
|
|
|
|
|
|
commands = [
|
|
|
|
%{mkdir -p .ssh},
|
|
|
|
%{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attrs))}" >> ~/attributes.json}
|
|
|
|
]
|
|
|
|
if public_key
|
|
|
|
commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
|
|
|
|
end
|
|
|
|
|
|
|
|
if credentials[:password].nil? && !rootpassword.nil?
|
|
|
|
credentials[:password] = rootpassword
|
|
|
|
end
|
|
|
|
|
2013-03-06 11:41:34 -05:00
|
|
|
# wait for glesys to be ready
|
|
|
|
wait_for { sshable?(credentials) }
|
|
|
|
|
2013-01-27 08:56:05 -05:00
|
|
|
Fog::SSH.new(public_ip_address, username, credentials).run(commands)
|
|
|
|
end
|
|
|
|
|
2013-01-27 08:56:28 -05:00
|
|
|
def ssh(command, options={}, &block)
|
|
|
|
if options[:password].nil? && !rootpassword.nil?
|
|
|
|
options[:password] = rootpassword
|
|
|
|
end
|
|
|
|
super(command, options, &block)
|
|
|
|
end
|
|
|
|
|
2013-02-01 14:36:44 -05:00
|
|
|
def ips
|
|
|
|
Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).all
|
|
|
|
end
|
|
|
|
|
|
|
|
def ip(ip)
|
|
|
|
Fog::Compute::Glesys::Ips.new(:serverid => identity, :server => self, :service => service).get(ip)
|
|
|
|
end
|
|
|
|
|
2013-01-27 06:52:16 -05:00
|
|
|
def public_ip_address(options = {})
|
|
|
|
|
2013-02-01 11:06:37 -05:00
|
|
|
return nil if iplist.nil?
|
|
|
|
|
2013-01-27 06:52:16 -05:00
|
|
|
type = options[:type] || nil
|
|
|
|
|
|
|
|
ips = case type
|
|
|
|
when :ipv4 then iplist.select { |ip| ip["version"] == 4 }
|
|
|
|
when :ipv6 then iplist.select { |ip| ip["version"] == 6 }
|
|
|
|
else iplist.sort_by { |ip| ip["version"] }
|
|
|
|
end
|
|
|
|
|
|
|
|
if ips.empty?
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
ips.first["ipaddress"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|