Class: Fog::Terremark::Shared::Server

Inherits:
Model
  • Object
show all
Defined in:
lib/rackspace-fog/terremark/models/shared/server.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

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 Attributes::InstanceMethods

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

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#destroyObject



16
17
18
19
20
21
22
23
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 16

def destroy
  requires :id
  data = connection.power_off(id).body
  task = connection.tasks.new(data)
  task.wait_for { ready? }
  connection.delete_vapp(id)
  true
end

#graceful_restartObject



77
78
79
80
81
82
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 77

def graceful_restart
  requires :id
  shutdown
  wait_for { off? }
  power_on
end

#off?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 34

def off?
  status == '2'
end

#on?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 30

def on?
  status == '4'
end

#power_offObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 49

def power_off
  requires :id
  begin
    connection.power_off(id)
  rescue Excon::Errors::InternalServerError => e
    #Frankly we shouldn't get here ...
    raise e unless e.to_s =~ /because it is already powered off/
  end
  true
end

#power_on(options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 38

def power_on(options = {})
  requires :id
  begin
    connection.power_on(id)
  rescue Excon::Errors::InternalServerError => e
    #Frankly we shouldn't get here ...
    raise e unless e.to_s =~ /because it is already powered on/
  end
  true
end

#power_resetObject



71
72
73
74
75
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 71

def power_reset
  requires :id
  connection.power_reset(id)
  true
end

#ready?Boolean

{ ‘0’ => ‘Being created’, ‘2’ => ‘Powered Off’, ‘4’ => ‘Powered On’}

Returns:

  • (Boolean)


26
27
28
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 26

def ready?
  status == '2'
end

#saveObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 84

def save
  requires :name
  data = connection.instantiate_vapp(name)
  merge_attributes(data.body)
  task = connection.deploy_vapp(id)
  task.wait_for { ready? }
  task = connection.power_on(id)
  task.wait_for { ready? }
  true
end

#shutdownObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/rackspace-fog/terremark/models/shared/server.rb', line 60

def shutdown
  requires :id
  begin
    connection.power_shutdown(id)
  rescue Excon::Errors::InternalServerError => e
    #Frankly we shouldn't get here ...
    raise e unless e.to_s =~ /because it is already powered off/
  end
  true
end