2012-06-22 06:03:29 -04:00
|
|
|
require 'fog/core/model'
|
2012-07-24 11:27:28 -04:00
|
|
|
require 'fog/serverlove/util/compute/password_generator'
|
2012-06-22 06:03:29 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Serverlove
|
|
|
|
|
|
|
|
class Server < Fog::Model
|
|
|
|
|
2012-07-15 07:40:03 -04:00
|
|
|
identity :id, :aliases => 'server'
|
2012-06-22 06:03:29 -04:00
|
|
|
|
2012-07-15 07:40:03 -04:00
|
|
|
attribute :name
|
|
|
|
attribute :cpu
|
2012-07-15 11:27:44 -04:00
|
|
|
attribute :mem
|
2012-07-16 14:50:27 -04:00
|
|
|
attribute :smp
|
2012-07-15 11:27:44 -04:00
|
|
|
attribute :ide_0_0, :aliases => 'ide:0:0'
|
|
|
|
attribute :ide_0_1, :aliases => 'ide:0:1'
|
|
|
|
attribute :ide_1_0, :aliases => 'ide:1:0'
|
|
|
|
attribute :ide_1_1, :aliases => 'ide:1:1'
|
|
|
|
attribute :boot
|
2012-07-15 07:40:03 -04:00
|
|
|
attribute :persistent
|
2012-07-16 14:50:27 -04:00
|
|
|
attribute :vnc
|
2012-07-15 07:40:03 -04:00
|
|
|
attribute :vnc_password, :aliases => 'vnc:password'
|
2012-06-22 06:03:29 -04:00
|
|
|
attribute :status
|
|
|
|
attribute :user
|
|
|
|
attribute :started
|
2012-07-15 12:04:33 -04:00
|
|
|
attribute :nic_0_model, :aliases => 'nic:0:model'
|
|
|
|
attribute :nic_0_dhcp, :aliases => 'nic:0:dhcp'
|
2012-06-22 06:03:29 -04:00
|
|
|
|
|
|
|
def save
|
2012-07-15 07:40:03 -04:00
|
|
|
attributes = {}
|
|
|
|
|
|
|
|
if(identity)
|
|
|
|
attributes = connection.update_server(identity, allowed_attributes).body
|
|
|
|
else
|
|
|
|
requires :name
|
|
|
|
requires :cpu
|
2012-07-15 12:04:33 -04:00
|
|
|
attributes = connection.create_server(self.defaults.merge(allowed_attributes)).body
|
2012-07-15 07:40:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
merge_attributes(attributes)
|
|
|
|
self
|
2012-06-22 06:03:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :identity
|
|
|
|
connection.destroy_server(identity)
|
2012-07-15 07:40:03 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_attributes
|
2012-07-16 14:22:30 -04:00
|
|
|
allowed = [
|
2012-07-16 14:50:27 -04:00
|
|
|
:name, :cpu, :smp, :mem, :persistent,
|
2012-07-16 14:22:30 -04:00
|
|
|
:vnc_password, :vnc,
|
|
|
|
:ide_0_0, :ide_0_1, :ide_1_0, :ide_1_1,
|
|
|
|
:boot, :nic_0_model, :nic_0_dhcp
|
|
|
|
]
|
2012-07-15 07:40:03 -04:00
|
|
|
attributes.select {|k,v| allowed.include? k}
|
|
|
|
end
|
2012-07-15 12:04:33 -04:00
|
|
|
|
|
|
|
def self.defaults
|
2012-07-16 14:22:30 -04:00
|
|
|
# TODO: Document default settings.
|
|
|
|
# Note that VNC password standards are strict (need explaining)
|
2012-07-24 11:27:28 -04:00
|
|
|
{ 'nic:0:model' => 'e1000', 'nic:0:dhcp' => 'auto',
|
|
|
|
'smp' => 'auto', 'vnc' => 'auto',
|
|
|
|
'vnc:password' => Fog::Compute::Serverlove::PasswordGenerator.generate
|
|
|
|
}
|
2012-07-15 12:04:33 -04:00
|
|
|
end
|
2012-06-22 06:03:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|