@@ -21,51 +21,58 @@ def create
2121 <CPU><%= resource[:cpu] %></CPU>
2222 <VCPU><%= resource[:vcpu] %></VCPU>
2323
24+ <% if resource[:os] %>
2425 <OS>
25- <% if resource[:os_kernel] %> <KERNEL><%= resource[:os_kernel] %></KERNEL><% end %>
26- <% if resource[:os_initrd] %> <INITRD><%= resource[:os_initrd] %></INITRD><% end %>
27- <% if resource[:os_arch] %> <ARCH><%= resource[:os_arch] %></ARCH><% end %>
28- <% if resource[:os_root] %> <ROOT><%= resource[:os_root] %></ROOT><% end %>
29- <% if resource[:os_kernel_cmd] %> <KERNEL_CMD><%= resource[:os_kernel_cmd] %></KERNEL_CMD><% end %>
30- <% if resource[:os_bootloader] %> <BOOTLOADER><%= resource[:os_bootloader] %></BOOTLOADER><% end %>
31- <% if resource[:os_boot] %> <BOOT><%= resource[:os_boot] %></BOOT><% end %>
26+ <% resource[:os].each do |key, value| %>
27+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
28+ <% end %>
3229 </OS>
30+ <% end %>
3331
32+ <% if resource[:disks] %>
3433<% resource[:disks].each do |disk| %>
3534 <DISK>
36- <IMAGE><%= disk %></IMAGE>
35+ <% disk.each do |key, value| %>
36+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
37+ <% end %>
3738 </DISK>
3839<% end %>
40+ <% end %>
41+
42+ <% if resource[:nics] %>
3943<% resource[:nics].each do |nic| %>
4044 <NIC>
41- <% if resource[:nic_model] %><MODEL><%= resource[:nic_model] %></MODEL><% end %>
42- <NETWORK><%= nic %></NETWORK>
45+ <% nic.each do |key, value| %>
46+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
47+ <% end %>
4348 </NIC>
4449<% end %>
50+ <% end %>
4551
52+ <% if resource[:graphics] %>
4653 <GRAPHICS>
47- <% if resource[:graphics_type] %><TYPE><%= resource[:graphics_type] %></TYPE><% end %>
48- <% if resource[:graphics_listen] %><LISTEN><%= resource[:graphics_listen] %></LISTEN><% end %>
49- <% if resource[:graphics_port] %><PORT><%= resource[:graphics_port] %></PORT><% end %>
50- <% if resource[:graphics_passwd] %><PASSWD><%= resource[:graphics_passwd] %></PASSWD><% end %>
51- <% if resource[:graphics_keymap] %><KEYMAP><%= resource[:graphics_keymap] %></KEYMAP><% end %>
54+ <% resource[:graphics].each do |key, value| %>
55+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
56+ <% end %>
5257 </GRAPHICS>
58+ <% end %>
59+
60+ <% if resource[:features] %>
5361 <FEATURES>
54- <% if resource[:acpi] %><ACPI><%= resource[:acpi] %></ACPI><% end %>
55- <% if resource[:pae] %><PAE><%= resource[:pae] %></PAE><% end %>
62+ <% resource[:features].each do |key, value| %>
63+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
64+ <% end %>
5665 </FEATURES>
57- <CONTEXT>
58- <% if resource[:context_network] %><NETWORK><%= resource[:context_network] %></NETWORK><% end %>
59- <% if resource[:context_files] %>
60- <FILES_DS><% resource[:context_files].each do |context_file| %>$FILE[IMAGE="<%= context_file %>"] <% end %></FILES_DS>
6166<% end %>
67+
6268<% if resource[:context] %>
63- <% resource[:context].each do |key, value| %>
64- <<%= key %>><%= value %></<%= key %>>
65- <% end %>
66- <% end %>
67- <% if resource[:context_ssh_pubkey] %><SSH_PUBLIC_KEY><%= resource[:context_ssh_pubkey] %></SSH_PUBLIC_KEY><% end %>
69+ <CONTEXT>
70+ <% resource[:context].each do |key, value| %>
71+ <<%= key.upcase %>><%= value %></<%= key.upcase %>>
72+ <% end %>
6873 </CONTEXT>
74+ <% end %>
75+
6976</TEMPLATE>
7077EOF
7178
@@ -94,39 +101,17 @@ def self.instances
94101 REXML ::Document . new ( onetemplate ( 'list' , '-x' ) ) . elements . collect ( "VMTEMPLATE_POOL/VMTEMPLATE" ) do |template |
95102 elements = template . elements
96103 new (
97- :name => elements [ "NAME" ] . text ,
98- :ensure => :present ,
99- :acpi => ( elements [ "TEMPLATE/FEATURES/ACPI" ] . text unless elements [ "TEMPLATE/FEATURES/ACPI" ] . nil? ) ,
100- :context => ( elements [ "TEMPLATE/CONTEXT" ] . text unless elements [ "TEMPLATE/CONTEXT" ] . nil? ) ,
101- :context_files => ( elements [ "TEMPLATE/CONTEXT/FILES_DS" ] . text . to_a unless elements [ "TEMPLATE/CONTEXT/FILES_DS" ] . nil? ) ,
102- :context_network => ( elements [ "TEMPLATE/CONTEXT/NETWORK" ] . text unless elements [ "TEMPLATE/CONTEXT/NETWORK" ] . nil? ) ,
103- :context_onegate => ( elements [ "TEMPLATE/CONTEXT/ONEGATE" ] . text unless elements [ "TEMPLATE/CONTEXT/ONEGATE" ] . nil? ) ,
104- :context_placement_cluster => ( elements [ "TEMPLATE/CONTEXT/PLACEMENT/CLUSTER" ] . text unless elements [ "TEMPLATE/CONTEXT/PLACEMENT/CLUSTER" ] . nil? ) ,
105- :context_placement_host => ( elements [ "TEMPLATE/CONTEXT/PLACEMENT/HOST" ] . text unless elements [ "TEMPLATE/CONTEXT/PLACEMENT/HOST" ] . nil? ) ,
106- :context_policy => ( elements [ "TEMPLATE/CONTEXT/POLICY" ] . text unless elements [ "TEMPLATE/CONTEXT/POLICY" ] . nil? ) ,
107- :context_ssh => ( elements [ "TEMPLATE/CONTEXT/SSH" ] . text unless elements [ "TEMPLATE/CONTEXT/SSH" ] . nil? ) ,
108- :context_ssh_pubkey => ( elements [ "TEMPLATE/CONTEXT/SSH_PUBLIC_KEY" ] . text unless elements [ "TEMPLATE/CONTEXT/SSH_PUBLIC_KEY" ] . nil? ) ,
109- :context_variables => ( elements [ "TEMPLATE/CONTEXT/VARIABLES" ] . text unless elements [ "TEMPLATE/CONTEXT/VARIABLES" ] . nil? ) ,
110- :cpu => ( elements [ "TEMPLATE/CPU" ] . text unless elements [ "TEMPLATE/CPU" ] . nil? ) ,
111- :disks => elements . collect ( "TEMPLATE/DISK/IMAGE" ) { |image | image . text } ,
112- :graphics_keymap => ( elements [ "TEMPLATE/GRAPHICS/KEYMAP" ] . text unless elements [ "TEMPLATE/GRAPHICS/KEYMAP" ] . nil? ) ,
113- :graphics_listen => ( elements [ "TEMPLATE/GRAPHICS/LISTEN" ] . text unless elements [ "TEMPLATE/GRAPHICS/LISTEN" ] . nil? ) ,
114- :graphics_passwd => ( elements [ "TEMPLATE/GRAPHICS/PASSWORD" ] . text unless elements [ "TEMPLATE/GRAPHICS/PASSWORD" ] . nil? ) ,
115- :graphics_port => ( elements [ "TEMPLATE/GRAPHICS/PORT" ] . text unless elements [ "TEMPLATE/GRAPHICS/PORT" ] . nil? ) ,
116- :graphics_type => ( elements [ "TEMPLATE/GRAPHICS/TYPE" ] . text unless elements [ "TEMPLATE/GRAPHICS/TYPE" ] . nil? ) ,
117- :memory => ( elements [ "TEMPLATE/MEMORY" ] . text unless elements [ "TEMPLATE/MEMORY" ] . nil? ) ,
118- :nic_model => ( elements [ "TEMPLATE/NIC/MODEL" ] . text unless elements [ "TEMPLATE/NIC/MODEL" ] . nil? ) ,
119- :nics => elements . collect ( "TEMPLATE/NIC/NETWORK" ) { |nic | nic . text } ,
120- :os_arch => ( elements [ "TEMPLATE/OS/ARCH" ] . text unless elements [ "TEMPLATE/OS/ARCH" ] . nil? ) ,
121- :os_boot => ( elements [ "TEMPLATE/OS/BOOT" ] . text unless elements [ "TEMPLATE/OS/BOOT" ] . nil? ) ,
122- :os_bootloader => ( elements [ "TEMPLATE/OS/BOOTLOADER" ] . text unless elements [ "TEMPLATE/OS/BOOTLOADER" ] . nil? ) ,
123- :os_initrd => ( elements [ "TEMPLATE/OS/INITRD" ] . text unless elements [ "TEMPLATE/OS/INITRD" ] . nil? ) ,
124- :os_kernel => ( elements [ "TEMPLATE/OS/KERNEL" ] . text unless elements [ "TEMPLATE/OS/KERNEL" ] . nil? ) ,
125- :os_kernel_cmd => ( elements [ "TEMPLATE/OS/KERNEL_CMD" ] . text unless elements [ "TEMPLATE/OS/KERNEL_CMD" ] . nil? ) ,
126- :os_root => ( elements [ "TEMPLATE/OS/ROOT" ] . text unless elements [ "TEMPLATE/OS/ROOT" ] . nil? ) ,
127- :pae => ( elements [ "TEMPLATE/FEATURES/PAE" ] . text unless elements [ "TEMPLATE/FEATURES/PAE" ] . nil? ) ,
128- :pci_bridge => ( elements [ "TEMPLATE/FEATURES/PCI_BRIDGE" ] . text unless elements [ "TEMPLATE/FEATURES/PCI_BRIDGE" ] . nil? ) ,
129- :vcpu => ( elements [ "TEMPLATE/VCPU" ] . text unless elements [ "TEMPLATE/VCPU" ] . nil? )
104+ :name => elements [ "NAME" ] . text ,
105+ :ensure => :present ,
106+ :context => Hash [ elements . collect ( 'TEMPLATE/CONTEXT/*' ) { |e | [ e . name . downcase , e . text ] } ] ,
107+ :cpu => ( elements [ "TEMPLATE/CPU" ] . text unless elements [ "TEMPLATE/CPU" ] . nil? ) ,
108+ :disks => elements . collect ( "TEMPLATE/DISK" ) { |e | Hash [ e . elements . collect { |f | [ f . name . downcase , f . text ] } ] } ,
109+ :features => Hash [ elements . collect ( 'TEMPLATE/FEATURES/*' ) { |e | [ e . name . downcase , { e . text => e . text , 'true' => true , 'false' => false } [ e . text ] ] } ] ,
110+ :graphics => Hash [ elements . collect ( 'TEMPLATE/GRAPHICS/*' ) { |e | [ e . name . downcase , e . text ] } ] ,
111+ :memory => ( elements [ "TEMPLATE/MEMORY" ] . text unless elements [ "TEMPLATE/MEMORY" ] . nil? ) ,
112+ :nics => elements . collect ( "TEMPLATE/NIC" ) { |e | Hash [ e . elements . collect { |f | [ f . name . downcase , f . text ] } ] } ,
113+ :os => Hash [ elements . collect ( 'TEMPLATE/OS/*' ) { |e | [ e . name . downcase , e . text ] } ] ,
114+ :vcpu => ( elements [ "TEMPLATE/VCPU" ] . text unless elements [ "TEMPLATE/VCPU" ] . nil? )
130115 )
131116 end
132117 end
@@ -140,98 +125,17 @@ def self.prefetch(resources)
140125 end
141126 end
142127
143- # setters
144- def memory = ( value )
145- raise "Can not yet modify memory on a template"
146- end
147- def cpu = ( value )
148- raise "Can not yet modify cpu on a template"
149- end
150- def vcpu = ( value )
151- raise "Can not yet modify vcpu on a template"
152- end
153- def os_kernel = ( value )
154- raise "Can not modify kernel on a template"
155- end
156- def os_initrd = ( value )
157- raise "Can not modify initrd on a template"
158- end
159- def os_arch = ( value )
160- raise "Can not modify arch on a template"
161- end
162- def os_root = ( value )
163- raise "Can not modify root device on a template"
164- end
165- def os_kernel_cmd = ( value )
166- raise "Can not modify kernel cmd on a template"
167- end
168- def os_bootloader = ( value )
169- raise "Can not modify booloader options on a template"
170- end
171- def os_boot = ( value )
172- raise "Can not modify boot device on a template"
173- end
174- def acpi = ( value )
175- raise "Can not modify acpi on a template"
176- end
177- def pae = ( value )
178- raise "Can not modify pae on a template"
179- end
180- def pci_bridge = ( value )
181- raise "Can not modify pci_bridge on a template"
182- end
183- def disks = ( value )
184- raise "Can not yet modify disks on a template"
185- end
186- def nics = ( value )
187- #raise "Can not yet modify networks on a template"
188- end
189- def nic_model = ( value )
190- raise "Can not modify network model on a template"
191- end
192- def graphics_type = ( value )
193- raise "Can not modify graphics type on a template"
194- end
195- def graphics_listen = ( value )
196- raise "Can not yet modify graphics listen port on a template"
197- end
198- def graphics_port = ( value )
199- raise "Can not modify graphics_port on a template"
200- end
201- def grahics_passwd = ( value )
202- raise "Can not yet modify graphics password on a template"
203- end
204- def graphics_keymap = ( value )
205- raise "Can not yet modify graphics keymap on a template"
206- end
207- def context = ( value )
208- #raise "Can not yet modify context hashes on a template"
209- end
210- def context_ssh = ( value )
211- raise "Can not yet modify ssh context on a template"
212- end
213- def context_ssh_pubkey = ( value )
214- raise "Can not yet modify root ssh pub key context on a template"
215- end
216- def context_network = ( value )
217- raise "Can not yet modify network context on a template"
218- end
219- def context_onegate = ( value )
220- raise "Can not modify onegate context on a template"
221- end
222- def context_files = ( value )
223- #raise "Can not yet modify context files on a template"
224- end
225- def context_variables = ( value )
226- raise "Can not yet modify context variables on a template"
227- end
228- def context_placement_host = ( value )
229- raise "Can not yet modify host placement context on a template"
230- end
231- def context_placement_cluster = ( value )
232- raise "Can not yet modify cluster placement context on a template"
233- end
234- def context_policy = ( value )
235- raise "Can not yet modify placement policy context on a template"
128+ def flush
129+ file = Tempfile . new ( 'onevnet' )
130+ file << @property_hash . map { |k , v |
131+ unless resource [ k ] . nil? or resource [ k ] . to_s . empty? or [ :name , :provider , :ensure ] . include? ( k )
132+ [ k . to_s . upcase , v ]
133+ end
134+ } . map { |a | "#{ a [ 0 ] } = #{ a [ 1 ] } " unless a . nil? } . join ( "\n " )
135+ file . close
136+ self . debug ( IO . read file . path )
137+ onetemplate ( 'update' , resource [ :name ] , file . path , '--append' ) unless @property_hash . empty?
138+ file . delete
236139 end
140+
237141end
0 commit comments