Class OpenNebula::ImageRepository

  1. OpenNebula/ImageRepository.rb
Parent: Object
Pool VirtualNetworkPool ClusterPool ImagePool VirtualMachinePool HostPool UserPool XMLElement PoolElement XMLPool User VirtualNetwork Cluster Image VirtualMachine Host Enumerable Client ImageRepository Error OpenNebula dot/f_0.png

The ImageRepository class represents and abstraction of the Image Repository, and it provides basic operations to manage and mantain it. This class is used by the OpenNebula daemon (through the image hook) to save and update images, and by the OpenNebula CLI to create and delete them

Methods

public instance

  1. create
  2. delete
  3. update_source

Constants

FS_UTILS = { :dd => "env dd", :mkfs => "env mkfs" }

Public instance methods

create (image, template)
[show source]
    # File OpenNebula/ImageRepository.rb, line 17
17:         def create(image, template)
18:             if image.nil?
19:                 error_msg = "Image could not be found, aborting."
20:                 return OpenNebula::Error.new(error_msg)
21:             end
22: 
23:             # ------ Allocate the Image ------
24:             result = image.allocate(template)
25: 
26:             if OpenNebula.is_error?(result)
27:                 return result
28:             end
29: 
30: 
31:             # ------ Copy the Image file ------
32:             image.info
33: 
34:             if image['TEMPLATE/PATH'] and image['TEMPLATE/SOURCE'].nil?
35:                 # --- CDROM, DATABLOCK or OS based on a PATH ---
36:                 file_path = image['TEMPLATE/PATH']
37: 
38:                 if !File.exists?(file_path)
39:                     error_msg = "Image file could not be found, aborting."
40:                     return OpenNebula::Error.new(error_msg)
41:                 end
42: 
43:                 result = copy(file_path, image['SOURCE'])
44:             elsif image['TEMPLATE/SIZE'] and image['TEMPLATE/FSTYPE'] and  \
45:                             image['TEMPLATE/TYPE'] == 'DATABLOCK'
46:                 # --- Empty DATABLOCK ---
47:                 result = dd(image['TEMPLATE/SIZE'], image['SOURCE'])
48: 
49:                 if !OpenNebula.is_error?(result)
50:                     result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE'])
51:                 end
52:             elsif image['TEMPLATE/PATH'].nil? and image['TEMPLATE/SOURCE'].nil?
53:                 error_msg = "Image path not present, aborting."
54:                 result = OpenNebula::Error.new(error_msg)
55:             elsif image['TEMPLATE/PATH'] and image['TEMPLATE/SOURCE']
56:                 error_msg = "Template malformed, PATH and SOURCE are" <<
57:                             " mutuallly exclusive"
58:                 result = OpenNebula::Error.new(error_msg)
59:             end
60: 
61: 
62:             # ------ Enable the Image ------
63:             if !OpenNebula.is_error?(result)
64:                 image.enable
65:             else
66:                 image.delete
67:             end
68: 
69:             return result
70:         end
delete (image)
[show source]
    # File OpenNebula/ImageRepository.rb, line 75
75:         def delete(image)
76:             if image.nil?
77:                 error_msg = "Image could not be found, aborting."
78:                 return OpenNebula::Error.new(error_msg)
79:             end
80: 
81:             result = image.info
82: 
83:             if !OpenNebula.is_error?(result)
84:                 file_path = image['SOURCE']
85: 
86:                 result = image.delete
87: 
88:                 if !OpenNebula.is_error?(result)
89:                     result = remove(file_path)
90:                 end
91:             end
92: 
93:             return result
94:         end
update_source (image, source)
[show source]
     # File OpenNebula/ImageRepository.rb, line 99
 99:         def update_source(image, source)
100:             if image.nil?
101:                 error_msg = "Image could not be found, aborting."
102:                 return OpenNebula::Error.new(error_msg)
103:             end
104: 
105:             result = image.info
106: 
107:             if !OpenNebula.is_error?(result)
108:                 result = move(source, image['SOURCE'])
109: 
110:                 image.enable
111:             end
112: 
113:             return result
114:         end