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(name, options = {}) ⇒ Instance

Returns a new instance of Instance.



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

def initialize(name, options={})
  @name       = 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.



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

def cpu_time
  @cpu_time
end

#domidObject (readonly)

Returns the value of attribute domid.



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

def domid
  @domid
end

#memoryObject (readonly)

Returns the value of attribute memory.



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

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#vcpusObject (readonly)

Returns the value of attribute vcpus.



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

def vcpus
  @vcpus
end

Class Method Details

.allObject



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

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

.create(name) ⇒ Object



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

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>.



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

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

.find(*args) ⇒ Object



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

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



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

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

.shutdown(name) ⇒ Object



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

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

Instance Method Details

#destroyObject



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

def destroy
end

#pauseObject



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

def pause
end

#rebootObject



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

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

#uptimeObject



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

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