Class: Fog::Compute::Libvirt::Pool

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#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

#initialize(attributes = {}) ⇒ Pool

Can be created by passing in XML



17
18
19
20
21
22
# File 'lib/fog/libvirt/models/compute/pool.rb', line 17

def initialize(attributes={} )
  self.xml  ||= nil unless attributes[:xml]
  self.create_persistent  ||= true unless attributes[:create_persistent]
  self.create_auto_build ||= true unless attributes[:create_auto_build]
  super
end

Instance Method Details

#active?Boolean

Is the pool active or not?

Returns:

  • (Boolean)


96
97
98
99
100
# File 'lib/fog/libvirt/models/compute/pool.rb', line 96

def active?
  requires :raw

  @raw.active?
end

#allocationObject

Retrieves the allocated disk space of the pool



136
137
138
139
# File 'lib/fog/libvirt/models/compute/pool.rb', line 136

def allocation
  requires :raw
  @raw.info.allocation
end

#auto_start=(flag) ⇒ Object

Set autostart value of the storage pool (true|false)



89
90
91
92
93
# File 'lib/fog/libvirt/models/compute/pool.rb', line 89

def auto_start=(flag)
  requires :raw

  @raw.auto_start(flag)
end

#auto_start?Boolean

Will the pool autostart or not?

Returns:

  • (Boolean)


103
104
105
106
107
# File 'lib/fog/libvirt/models/compute/pool.rb', line 103

def auto_start?
  requires :raw

  @raw.autostart?
end

#buildObject

Build this storage pool



67
68
69
70
71
# File 'lib/fog/libvirt/models/compute/pool.rb', line 67

def build
  requires :raw

  @raw.build unless @raw.nil?
end

#capacityObject

Retrieves the capacity of disk space of the pool



142
143
144
145
# File 'lib/fog/libvirt/models/compute/pool.rb', line 142

def capacity
  requires :raw
  @raw.info.capacity
end

#destroy(destroy_options = {}) ⇒ Object

Destroys the storage pool



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/libvirt/models/compute/pool.rb', line 74

def destroy( destroy_options={})
  requires :raw

  # Shutdown pool if active
  @raw.destroy if @raw.active?

  # Delete corresponding data in this pool
  # @raw.delete

  # If this is a persistent domain we need to undefine it
  @raw.undefine if @raw.persistent?

end

#nameObject

Retrieves the name of the pool



124
125
126
127
# File 'lib/fog/libvirt/models/compute/pool.rb', line 124

def name
  requires :raw
  @raw.name
end

#num_of_volumesObject

Retrieves the number of volumes available in this pool



148
149
150
151
# File 'lib/fog/libvirt/models/compute/pool.rb', line 148

def num_of_volumes
  requires :raw
  @raw.num_of_volumes
end

#persistent?Boolean

Is the pool persistent or not?

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/fog/libvirt/models/compute/pool.rb', line 110

def persistent?
  requires :raw
  @raw.persistent?
end

#saveObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/libvirt/models/compute/pool.rb', line 24

def save
  requires :xml
  unless xml.nil?
    pool=nil
    if self.create_persistent
      pool=connection.raw.define_storage_pool_xml(xml)
    else
      pool=connection.raw.create_storage_pool_xml(xml)
    end
    self.raw=pool
    true
  else
    raise Fog::Errors::Error.new('Creating a new pool requires proper xml')
    false
  end
end

#shutdownObject

Shuts down the pool



59
60
61
62
63
64
# File 'lib/fog/libvirt/models/compute/pool.rb', line 59

def shutdown
  requires :raw

  @raw.destroy
  true
end

#startObject

Start the pool = make it active Performs a libvirt create (= start)



44
45
46
47
48
# File 'lib/fog/libvirt/models/compute/pool.rb', line 44

def start
  requires :raw

  @raw.create
end

#stateObject



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fog/libvirt/models/compute/pool.rb', line 153

def state
  requires :raw

  #INACTIVE = INT2NUM(VIR_STORAGE_POOL_INACTIVE)     virStoragePoolState
  #BUILDING = INT2NUM(VIR_STORAGE_POOL_BUILDING)
  #RUNNING  = INT2NUM(VIR_STORAGE_POOL_RUNNING)
  #DEGRADED = INT2NUM(VIR_STORAGE_POOL_DEGRADED)
  #INACCESSIBLE = INT2NUM(VIR_STORAGE_POOL_INACCESSIBLE)
  states=[:inactive, :building,:running,:degrated,:inaccessible]

  return states[@raw.info.state]

end

#stopObject

Stop the pool = make it non-active Performs a libvirt destroy (= stop)



52
53
54
55
56
# File 'lib/fog/libvirt/models/compute/pool.rb', line 52

def stop
  requires :raw

  @raw.destroy
end

#uuidObject

Retrieves the uuid of the pool



130
131
132
133
# File 'lib/fog/libvirt/models/compute/pool.rb', line 130

def uuid
  requires :raw
  @raw.uuid
end

#volumesObject

Retrieves the volumes of this pool



168
169
170
171
172
173
174
175
176
# File 'lib/fog/libvirt/models/compute/pool.rb', line 168

def volumes

  volumes=Array.new
  @raw.list_volumes.each do |volume|
    fog_volume=connection.volumes.all(:name => volume).first
    volumes << fog_volume
  end
  return volumes
end

#xml_descObject

Returns the xml description of the current pool



116
117
118
119
120
# File 'lib/fog/libvirt/models/compute/pool.rb', line 116

def xml_desc
  requires :raw

  @raw.xml_desc unless @raw.nil?
end