2011-08-11 11:53:52 -05:00
|
|
|
require 'fog/compute/models/server'
|
2010-11-08 12:21:31 +00:00
|
|
|
|
|
|
|
module Fog
|
2011-06-16 16:28:54 -07:00
|
|
|
module Compute
|
|
|
|
class Brightbox
|
2010-11-08 12:21:31 +00:00
|
|
|
|
2011-08-11 11:53:52 -05:00
|
|
|
class Server < Fog::Compute::Server
|
2010-11-08 12:21:31 +00:00
|
|
|
|
|
|
|
identity :id
|
2011-08-22 17:41:18 +01:00
|
|
|
attribute :resource_type
|
2010-11-08 12:21:31 +00:00
|
|
|
attribute :url
|
2011-08-22 17:41:18 +01:00
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
attribute :name
|
2011-05-24 14:59:48 -07:00
|
|
|
attribute :state, :aliases => 'status'
|
2011-08-22 17:41:18 +01:00
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
attribute :hostname
|
|
|
|
attribute :user_data
|
2011-08-22 17:41:18 +01:00
|
|
|
attribute :console_url
|
|
|
|
attribute :console_token
|
2010-11-08 12:21:31 +00:00
|
|
|
|
2011-08-22 17:41:18 +01:00
|
|
|
# Times
|
2011-08-26 16:00:24 +01:00
|
|
|
attribute :created_at, :type => :time
|
|
|
|
attribute :started_at, :type => :time
|
|
|
|
attribute :console_token_expires, :type => :time
|
|
|
|
attribute :deleted_at, :type => :time
|
2010-11-08 12:21:31 +00:00
|
|
|
|
2011-08-22 17:41:18 +01:00
|
|
|
# Links - to be replaced
|
2011-05-24 14:59:48 -07:00
|
|
|
attribute :account_id, :aliases => "account", :squash => "id"
|
|
|
|
attribute :image_id, :aliases => "image", :squash => "id"
|
2011-10-14 16:01:23 +05:30
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
attribute :snapshots
|
|
|
|
attribute :cloud_ips
|
|
|
|
attribute :interfaces
|
2011-09-22 11:14:55 +01:00
|
|
|
attribute :server_groups
|
2011-10-14 16:02:01 +05:30
|
|
|
attribute :zone
|
|
|
|
attribute :server_type
|
2010-11-08 12:21:31 +00:00
|
|
|
|
2011-04-14 16:31:58 -07:00
|
|
|
def initialize(attributes={})
|
2011-09-30 15:06:22 +01:00
|
|
|
self.image_id ||= 'img-4gqhs' # Ubuntu Lucid 10.04 server (i686)
|
2011-04-14 16:31:58 -07:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2011-10-14 16:01:23 +05:30
|
|
|
def zone_id
|
2011-10-24 16:11:33 +05:30
|
|
|
if t_zone_id = attributes[:zone_id]
|
|
|
|
t_zone_id
|
|
|
|
elsif zone
|
|
|
|
zone[:id] || zone['id']
|
|
|
|
end
|
2011-10-14 16:01:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def flavor_id
|
2011-10-24 16:11:33 +05:30
|
|
|
if t_flavour_id = attributes[:flavor_id]
|
|
|
|
t_flavour_id
|
|
|
|
elsif server_type
|
|
|
|
server_type[:id] || server_type['id']
|
|
|
|
end
|
2011-10-14 16:01:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def zone_id=(incoming_zone_id)
|
|
|
|
attributes[:zone_id] = incoming_zone_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def flavor_id=(incoming_flavour_id)
|
|
|
|
attributes[:flavor_id] = incoming_flavour_id
|
|
|
|
end
|
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
def snapshot
|
|
|
|
requires :identity
|
|
|
|
connection.snapshot_server(identity)
|
|
|
|
end
|
|
|
|
|
2010-11-16 10:38:41 +00:00
|
|
|
def reboot
|
|
|
|
false
|
2010-11-08 12:21:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
requires :identity
|
|
|
|
connection.start_server(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
requires :identity
|
|
|
|
connection.stop_server(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def shutdown
|
|
|
|
requires :identity
|
|
|
|
connection.shutdown_server(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
|
|
|
connection.destroy_server(identity)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def flavor
|
|
|
|
requires :flavor_id
|
2010-11-19 13:45:45 -08:00
|
|
|
connection.flavors.get(flavor_id)
|
2010-11-08 12:21:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
requires :image_id
|
2010-11-19 13:45:45 -08:00
|
|
|
connection.images.get(image_id)
|
2010-11-08 12:21:31 +00:00
|
|
|
end
|
|
|
|
|
2011-02-22 16:36:15 -08:00
|
|
|
def private_ip_address
|
2011-09-30 17:50:31 +01:00
|
|
|
unless interfaces.empty?
|
|
|
|
interfaces.first["ipv4_address"]
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2011-02-22 16:36:15 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def public_ip_address
|
2011-09-30 17:50:31 +01:00
|
|
|
unless cloud_ips.empty?
|
|
|
|
cloud_ips.first["public_ip"]
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2011-02-22 16:36:15 -08:00
|
|
|
end
|
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
def ready?
|
2011-05-24 14:59:48 -07:00
|
|
|
self.state == 'active'
|
2010-11-08 12:21:31 +00:00
|
|
|
end
|
|
|
|
|
2011-03-02 01:10:41 +08:00
|
|
|
def activate_console
|
|
|
|
requires :identity
|
|
|
|
response = connection.activate_console_server(identity)
|
|
|
|
[response["console_url"], response["console_token"], response["console_token_expires"]]
|
|
|
|
end
|
|
|
|
|
2010-11-08 12:21:31 +00:00
|
|
|
def save
|
2011-08-23 17:22:07 +01:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
2010-11-08 12:21:31 +00:00
|
|
|
requires :image_id
|
|
|
|
options = {
|
2010-11-19 13:45:45 -08:00
|
|
|
:image => image_id,
|
|
|
|
:name => name,
|
|
|
|
:zone => zone_id,
|
2011-09-22 11:14:55 +01:00
|
|
|
:user_data => user_data,
|
|
|
|
:server_groups => server_groups
|
2010-11-08 12:21:31 +00:00
|
|
|
}.delete_if {|k,v| v.nil? || v == "" }
|
2011-08-19 13:55:07 +01:00
|
|
|
unless flavor_id.nil? || flavor_id == ""
|
|
|
|
options.merge!(:server_type => flavor_id)
|
|
|
|
end
|
2010-11-09 17:40:04 +00:00
|
|
|
data = connection.create_server(options)
|
2010-11-08 12:21:31 +00:00
|
|
|
merge_attributes(data)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|