Class: Fog::Compute::Serverlove::Server

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/serverlove/models/compute/server.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Class Method Details

.defaultsObject



61
62
63
64
65
66
67
68
# File 'lib/fog/serverlove/models/compute/server.rb', line 61

def self.defaults
  # TODO: Document default settings.
  # Note that VNC password standards are strict (need explaining)
  { 'nic:0:model' => 'e1000', 'nic:0:dhcp' => 'auto',
    'smp' => 'auto', 'vnc' => 'auto',
    'vnc:password' => Fog::Compute::Serverlove::PasswordGenerator.generate
  }
end

Instance Method Details

#allowed_attributesObject



51
52
53
54
55
56
57
58
59
# File 'lib/fog/serverlove/models/compute/server.rb', line 51

def allowed_attributes
  allowed = [
              :name, :cpu, :smp, :mem, :persistent,
              :vnc_password, :vnc,
              :ide_0_0, :ide_0_1, :ide_1_0, :ide_1_1,
              :boot, :nic_0_model, :nic_0_dhcp
            ]
  attributes.select {|k,v| allowed.include? k}
end

#destroyObject



45
46
47
48
49
# File 'lib/fog/serverlove/models/compute/server.rb', line 45

def destroy
  requires :identity
  service.destroy_server(identity)
  self
end

#saveObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/serverlove/models/compute/server.rb', line 30

def save
  attributes = {}

  if(identity)
    attributes = service.update_server(identity, allowed_attributes).body
  else
    requires :name
    requires :cpu
    attributes = service.create_server(self.class.defaults.merge(allowed_attributes)).body
  end

  merge_attributes(attributes)
  self
end