Class: Xen::Instance

Inherits:
Object
  • Object
show all
Includes:
Parentable
Defined in:
lib/xen/instance.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parentable

#slice

Constructor Details

#initialize(options = {}) ⇒ Instance

Returns a new instance of Instance.



6
7
8
9
10
11
12
13
14
# File 'lib/xen/instance.rb', line 6

def initialize(options={})
  @name       = options[:name]
  @domid      = options[:domid]
  @memory     = options[:memory]
  @cpu_time   = options[:cpu_time]
  @vcpus      = options[:vcpus]
  @state      = options[:state]
  @start_time = Time.at(options[:start_time].to_f) if options[:start_time]
end

Instance Attribute Details

#cpu_timeObject (readonly)

Returns the value of attribute cpu_time.



4
5
6
# File 'lib/xen/instance.rb', line 4

def cpu_time
  @cpu_time
end

#domidObject (readonly)

Returns the value of attribute domid.



4
5
6
# File 'lib/xen/instance.rb', line 4

def domid
  @domid
end

#memoryObject (readonly)

Returns the value of attribute memory.



4
5
6
# File 'lib/xen/instance.rb', line 4

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/xen/instance.rb', line 4

def name
  @name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



4
5
6
# File 'lib/xen/instance.rb', line 4

def start_time
  @start_time
end

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/xen/instance.rb', line 4

def state
  @state
end

#vcpusObject (readonly)

Returns the value of attribute vcpus.



4
5
6
# File 'lib/xen/instance.rb', line 4

def vcpus
  @vcpus
end

Class Method Details

.allObject



24
25
26
27
28
# File 'lib/xen/instance.rb', line 24

def self.all
  Xen::Command.detailed_instance_list.collect do |instance|
    new(instance)
  end
end

.create(name) ⇒ Object



37
38
39
40
# File 'lib/xen/instance.rb', line 37

def self.create(name)
  output = Xen::Command.start_instance(name.to_s + Xen::CONFIG_FILE_EXTENSION)
  $? == 0 ? true : false
end

.dom0(*args) ⇒ Object

A convenience wrapper for find(:dom0).</tt>.



48
49
50
# File 'lib/xen/instance.rb', line 48

def self.dom0(*args)
  find_by_name(:dom0)
end

.find(*args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/xen/instance.rb', line 16

def self.find(*args)
  options = args.extract_options!
  case args.first
  when :all       then all
  else            find_by_name(args.first)
  end
end

.find_by_name(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/xen/instance.rb', line 30

def self.find_by_name(name)
  Xen::Command.detailed_instance_list(name).each do |instance|
    return new(instance)
  end
  return false
end

.shutdown(name) ⇒ Object



42
43
44
45
# File 'lib/xen/instance.rb', line 42

def self.shutdown(name)
  output = Xen::Command.shutdown_instance(name)
  $? == 0 ? true : false
end

Instance Method Details

#destroyObject



61
62
# File 'lib/xen/instance.rb', line 61

def destroy
end

#pauseObject



64
65
# File 'lib/xen/instance.rb', line 64

def pause
end

#rebootObject



56
57
58
59
# File 'lib/xen/instance.rb', line 56

def reboot
  `xm reboot #{name}`
  $? == 0 ? true : false
end

#uptimeObject



52
53
54
# File 'lib/xen/instance.rb', line 52

def uptime
  start_time ? Time.now - start_time : nil
end