opennebula-cli 3.8.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,134 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+ require 'one_helper'
18
+ require 'one_helper/onequota_helper'
19
+
20
+ class OneGroupHelper < OpenNebulaHelper::OneHelper
21
+ def self.rname
22
+ "GROUP"
23
+ end
24
+
25
+ def self.conf_file
26
+ "onegroup.yaml"
27
+ end
28
+
29
+ def create_resource(options, &block)
30
+ group = factory
31
+
32
+ rc = block.call(group)
33
+ if OpenNebula.is_error?(rc)
34
+ return -1, rc.message
35
+ else
36
+ puts "ID: #{group.id.to_s}"
37
+ end
38
+
39
+ puts "Creating default ACL rules from #{GROUP_DEFAULT}" if options[:verbose]
40
+
41
+ exit_code , msg = group.create_acls
42
+
43
+ puts msg
44
+
45
+ exit_code
46
+ end
47
+
48
+ def format_pool(options)
49
+ config_file = self.class.table_conf
50
+
51
+ table = CLIHelper::ShowTable.new(config_file, self) do
52
+ column :ID, "ONE identifier for the Group", :size=>4 do |d|
53
+ d["ID"]
54
+ end
55
+
56
+ column :NAME, "Name of the Group", :left, :size=>29 do |d|
57
+ d["NAME"]
58
+ end
59
+
60
+ column :USERS, "Number of Users in this group", :size=>5 do |d|
61
+ if d["USERS"]["ID"].nil?
62
+ "0"
63
+ else
64
+ d["USERS"]["ID"].size
65
+ end
66
+ end
67
+
68
+ column :VMS , "Number of VMS", :size=>9 do |d|
69
+ if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
70
+ "%3d / %3d" % [d['VM_QUOTA']['VM']["VMS_USED"], d['VM_QUOTA']['VM']["VMS"]]
71
+ else
72
+ "-"
73
+ end
74
+ end
75
+
76
+ column :MEMORY, "Total memory allocated to user VMs", :size=>17 do |d|
77
+ if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
78
+ "%7s / %7s" % [OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY_USED"].to_i,{},"M"),
79
+ OpenNebulaHelper.unit_to_str(d['VM_QUOTA']['VM']["MEMORY"].to_i,{},"M")]
80
+ else
81
+ "-"
82
+ end
83
+ end
84
+
85
+ column :CPU, "Total CPU allocated to user VMs", :size=>11 do |d|
86
+ if d.has_key?('VM_QUOTA') and d['VM_QUOTA'].has_key?('VM')
87
+ "%4.0f / %4.0f" % [d['VM_QUOTA']['VM']["CPU_USED"], d['VM_QUOTA']['VM']["CPU"]]
88
+ else
89
+ "-"
90
+ end
91
+ end
92
+
93
+ default :ID, :NAME, :USERS, :VMS, :MEMORY, :CPU
94
+ end
95
+
96
+ table
97
+ end
98
+
99
+ private
100
+
101
+ def factory(id=nil)
102
+ if id
103
+ OpenNebula::Group.new_with_id(id, @client)
104
+ else
105
+ xml=OpenNebula::Group.build_xml
106
+ OpenNebula::Group.new(xml, @client)
107
+ end
108
+ end
109
+
110
+ def factory_pool(user_flag=-2)
111
+ #TBD OpenNebula::UserPool.new(@client, user_flag)
112
+ OpenNebula::GroupPool.new(@client)
113
+ end
114
+
115
+ def format_resource(group)
116
+ str="%-15s: %-20s"
117
+ str_h1="%-80s"
118
+
119
+ CLIHelper.print_header(str_h1 % "GROUP #{group['ID']} INFORMATION")
120
+ puts str % ["ID", group.id.to_s]
121
+ puts str % ["NAME", group.name]
122
+ puts
123
+
124
+ CLIHelper.print_header(str_h1 % "USERS", false)
125
+ CLIHelper.print_header("%-15s" % ["ID"])
126
+ group.user_ids.each do |uid|
127
+ puts "%-15s" % [uid]
128
+ end
129
+
130
+ group_hash = group.to_hash
131
+
132
+ OneQuotaHelper.format_quota(group_hash['GROUP'])
133
+ end
134
+ end
@@ -0,0 +1,196 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+ require 'one_helper'
18
+
19
+ class OneHostHelper < OpenNebulaHelper::OneHelper
20
+ def self.rname
21
+ "HOST"
22
+ end
23
+
24
+ def self.conf_file
25
+ "onehost.yaml"
26
+ end
27
+
28
+ def self.state_to_str(id)
29
+ id = id.to_i
30
+ state_str = Host::HOST_STATES[id]
31
+
32
+ return Host::SHORT_HOST_STATES[state_str]
33
+ end
34
+
35
+ def format_pool(options)
36
+ config_file = self.class.table_conf
37
+
38
+ table = CLIHelper::ShowTable.new(config_file, self) do
39
+ column :ID, "ONE identifier for Host", :size=>4 do |d|
40
+ d["ID"]
41
+ end
42
+
43
+ column :NAME, "Name of the Host", :left, :size=>15 do |d|
44
+ d["NAME"]
45
+ end
46
+
47
+ column :CLUSTER, "Name of the Cluster", :left, :size=>9 do |d|
48
+ OpenNebulaHelper.cluster_str(d["CLUSTER"])
49
+ end
50
+
51
+ column :RVM, "Number of Virtual Machines running", :size=>3 do |d|
52
+ d["HOST_SHARE"]["RUNNING_VMS"]
53
+ end
54
+
55
+ column :TCPU, "Total CPU percentage", :size=>4 do |d|
56
+ d["HOST_SHARE"]["MAX_CPU"]
57
+ end
58
+
59
+ column :FCPU, "Free CPU percentage", :size=>4 do |d|
60
+ d["HOST_SHARE"]["MAX_CPU"].to_i-
61
+ d["HOST_SHARE"]["USED_CPU"].to_i
62
+ end
63
+
64
+ column :ACPU, "Available cpu percentage (not reserved by VMs)",
65
+ :size=>4 do |d|
66
+ max_cpu=d["HOST_SHARE"]["MAX_CPU"].to_i
67
+ max_cpu=100 if max_cpu==0
68
+ max_cpu-d["HOST_SHARE"]["CPU_USAGE"].to_i
69
+ end
70
+
71
+ column :TMEM, "Total Memory", :size=>7 do |d|
72
+ OpenNebulaHelper.unit_to_str(
73
+ d["HOST_SHARE"]["MAX_MEM"].to_i,
74
+ options)
75
+ end
76
+
77
+ column :FMEM, "Free Memory", :size=>7 do |d|
78
+ OpenNebulaHelper.unit_to_str(
79
+ d["HOST_SHARE"]["FREE_MEM"].to_i,
80
+ options)
81
+ end
82
+
83
+ column :AMEM, "Available Memory (not reserved by VMs)",
84
+ :size=>7 do |d|
85
+ acpu=d["HOST_SHARE"]["MAX_MEM"].to_i-
86
+ d["HOST_SHARE"]["MEM_USAGE"].to_i
87
+ OpenNebulaHelper.unit_to_str(acpu,options)
88
+ end
89
+
90
+ column :REAL_CPU, "Real CPU", :size=>18 do |d|
91
+ max_cpu = d["HOST_SHARE"]["MAX_CPU"].to_i
92
+
93
+ if max_cpu != 0
94
+ used_cpu = d["HOST_SHARE"]["USED_CPU"].to_i
95
+ ratio = (used_cpu*100) / max_cpu
96
+ "#{used_cpu} / #{max_cpu} (#{ratio}%)"
97
+ else
98
+ '-'
99
+ end
100
+ end
101
+
102
+ column :ALLOCATED_CPU, "Allocated CPU)", :size=>18 do |d|
103
+ max_cpu = d["HOST_SHARE"]["MAX_CPU"].to_i
104
+
105
+ if max_cpu != 0
106
+ cpu_usage = d["HOST_SHARE"]["CPU_USAGE"].to_i
107
+ ratio = (cpu_usage*100) / max_cpu
108
+ "#{cpu_usage} / #{max_cpu} (#{ratio}%)"
109
+ else
110
+ '-'
111
+ end
112
+ end
113
+
114
+ column :REAL_MEM, "Real MEM", :size=>18 do |d|
115
+ max_mem = d["HOST_SHARE"]["MAX_MEM"].to_i
116
+
117
+ if max_mem != 0
118
+ used_mem = d["HOST_SHARE"]["USED_MEM"].to_i
119
+ ratio = (used_mem*100) / max_mem
120
+ "#{OpenNebulaHelper.unit_to_str(used_mem,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
121
+ else
122
+ '-'
123
+ end
124
+ end
125
+
126
+ column :ALLOCATED_MEM, "Allocated MEM", :size=>18 do |d|
127
+ max_mem = d["HOST_SHARE"]["MAX_MEM"].to_i
128
+
129
+ if max_mem != 0
130
+ mem_usage = d["HOST_SHARE"]["MEM_USAGE"].to_i
131
+ ratio = (mem_usage*100) / max_mem
132
+ "#{OpenNebulaHelper.unit_to_str(mem_usage,options)} / #{OpenNebulaHelper.unit_to_str(max_mem,options)} (#{ratio}%)"
133
+ else
134
+ '-'
135
+ end
136
+ end
137
+
138
+ column :STAT, "Host status", :left, :size=>6 do |d|
139
+ OneHostHelper.state_to_str(d["STATE"])
140
+ end
141
+
142
+ default :ID, :NAME, :CLUSTER, :RVM, :ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
143
+ end
144
+
145
+ table
146
+ end
147
+
148
+ private
149
+
150
+ def factory(id=nil)
151
+ if id
152
+ OpenNebula::Host.new_with_id(id, @client)
153
+ else
154
+ xml=OpenNebula::Host.build_xml
155
+ OpenNebula::Host.new(xml, @client)
156
+ end
157
+ end
158
+
159
+ def factory_pool(user_flag=-2)
160
+ #TBD OpenNebula::HostPool.new(@client, user_flag)
161
+ OpenNebula::HostPool.new(@client)
162
+ end
163
+
164
+ def format_resource(host)
165
+ str = "%-22s: %-20s"
166
+ str_h1 = "%-80s"
167
+
168
+ CLIHelper.print_header(
169
+ str_h1 % "HOST #{host.id.to_s} INFORMATION", true)
170
+
171
+ puts str % ["ID", host.id.to_s]
172
+ puts str % ["NAME", host.name]
173
+ puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(host['CLUSTER'])]
174
+ puts str % ["STATE", host.state_str]
175
+ puts str % ["IM_MAD", host['IM_MAD']]
176
+ puts str % ["VM_MAD", host['VM_MAD']]
177
+ puts str % ["VN_MAD", host['VN_MAD']]
178
+ puts str % ["LAST MONITORING TIME", OpenNebulaHelper.time_to_str(host['LAST_MON_TIME'])]
179
+ puts
180
+
181
+ CLIHelper.print_header(str_h1 % "HOST SHARES", false)
182
+
183
+ puts str % ["TOTAL MEM", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MAX_MEM'].to_i, {})]
184
+ puts str % ["USED MEM (REAL)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/USED_MEM'].to_i, {})]
185
+ puts str % ["USED MEM (ALLOCATED)", OpenNebulaHelper.unit_to_str(host['HOST_SHARE/MEM_USAGE'].to_i, {})]
186
+ puts str % ["TOTAL CPU", host['HOST_SHARE/MAX_CPU']]
187
+ puts str % ["USED CPU (REAL)", host['HOST_SHARE/USED_CPU']]
188
+ puts str % ["USED CPU (ALLOCATED)", host['HOST_SHARE/CPU_USAGE']]
189
+ puts str % ["RUNNING VMS", host['HOST_SHARE/RUNNING_VMS']]
190
+ puts
191
+
192
+ CLIHelper.print_header(str_h1 % "MONITORING INFORMATION", false)
193
+
194
+ puts host.template_str
195
+ end
196
+ end
@@ -0,0 +1,327 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+ require 'one_helper'
18
+
19
+ class OneImageHelper < OpenNebulaHelper::OneHelper
20
+ TEMPLATE_OPTIONS=[
21
+ {
22
+ :name => "name",
23
+ :large => "--name name",
24
+ :format => String,
25
+ :description => "Name of the new image"
26
+ },
27
+ {
28
+ :name => "description",
29
+ :large => "--description description",
30
+ :format => String,
31
+ :description => "Description for the new Image"
32
+ },
33
+ {
34
+ :name => "type",
35
+ :large => "--type type",
36
+ :format => String,
37
+ :description => "Type of the new Image: OS, CDROM or DATABLOCK",
38
+ :proc => lambda do |o, options|
39
+ type=o.strip.upcase
40
+
41
+ if %w{OS CDROM DATABLOCK}.include? type
42
+ [0, type]
43
+ else
44
+ [-1, "Type should be OS, CDROM or DATABLOCK"]
45
+ end
46
+ end
47
+ },
48
+ {
49
+ :name => "persistent",
50
+ :large => "--persistent",
51
+ :description => "Tells if the image will be persistent"
52
+ },
53
+ {
54
+ :name => "prefix",
55
+ :large => "--prefix prefix",
56
+ :description => "Device prefix for the disk (eg. hd, sd, xvd or vd)",
57
+ :format => String,
58
+ :proc => lambda do |o, options|
59
+ prefix=o.strip.downcase
60
+ if %w{hd sd xvd vd}.include? prefix
61
+ [0, prefix]
62
+ else
63
+ [-1, "The prefix must be hd, sd, xvd or vd"]
64
+ end
65
+ end
66
+ },
67
+ {
68
+ :name => "target",
69
+ :large => "--target target",
70
+ :description => "Device the disk will be attached to",
71
+ :format => String
72
+ },
73
+ {
74
+ :name => "path",
75
+ :large => "--path path",
76
+ :description => "Path of the image file",
77
+ :format => String,
78
+ :proc => lambda do |o, options|
79
+ if o[0,1]=='/'
80
+ path=o
81
+ else
82
+ path=Dir.pwd+"/"+o
83
+ end
84
+
85
+ if File.exist?(path)
86
+ [0, path]
87
+ else
88
+ [-1, "File '#{path}' does not exist."]
89
+ end
90
+ end
91
+ },
92
+ {
93
+ :name => "driver",
94
+ :large => "--driver driver",
95
+ :description => "Driver to use image (raw, qcow2, tap:aio:...)",
96
+ :format => String
97
+ },
98
+ {
99
+ :name => "disk_type",
100
+ :large => "--disk_type disk_type",
101
+ :description => "Type of the image (BLOCK, CDROM or FILE)",
102
+ :format => String,
103
+ :proc => lambda do |o, options|
104
+ type=o.strip.upcase
105
+ if %w{BLOCK CDROM FILE}.include? type
106
+ [0, type]
107
+ else
108
+ [-1, "Disk type must be BLOCK, CDROM or FILE"]
109
+ end
110
+ end
111
+ },
112
+ {
113
+ :name => "source",
114
+ :large => "--source source",
115
+ :description =>
116
+ "Source to be used. Useful for not file-based images",
117
+ :format => String
118
+ },
119
+ {
120
+ :name => "size",
121
+ :large => "--size size",
122
+ :description => "Size in MB. Used for DATABLOCK type",
123
+ :format => String,
124
+ :proc => lambda do |o, options|
125
+ if !options[:type] || !(options[:type].upcase=='DATABLOCK')
126
+ next [-1, "Size is only used for DATABLOCK type images"]
127
+ end
128
+
129
+ m=o.strip.match(/^(\d+(?:\.\d+)?)(m|mb|g|gb)?$/i)
130
+
131
+ if !m
132
+ [-1, 'Size value malformed']
133
+ else
134
+ multiplier=case m[2]
135
+ when /(g|gb)/i
136
+ 1024
137
+ else
138
+ 1
139
+ end
140
+
141
+ value=m[1].to_f*multiplier
142
+
143
+ [0, value.floor]
144
+ end
145
+ end
146
+ },
147
+ {
148
+ :name => "fstype",
149
+ :large => "--fstype fstype",
150
+ :description => "Type of file system to be built. This can be "<<
151
+ "any value understood by mkfs unix command.",
152
+ :format => String,
153
+ :proc => lambda do |o, options|
154
+ if !options[:type] || !(options[:type].upcase=='DATABLOCK')
155
+ [-1, "FSTYPE is only used for DATABLOCK type images"]
156
+ else
157
+ [0, o]
158
+ end
159
+ end
160
+ }
161
+ ]
162
+
163
+ def self.rname
164
+ "IMAGE"
165
+ end
166
+
167
+ def self.conf_file
168
+ "oneimage.yaml"
169
+ end
170
+
171
+ def self.state_to_str(id)
172
+ id = id.to_i
173
+ state_str = Image::IMAGE_STATES[id]
174
+ return Image::SHORT_IMAGE_STATES[state_str]
175
+ end
176
+
177
+ def self.type_to_str(id)
178
+ id = id.to_i
179
+ type_str = Image::IMAGE_TYPES[id]
180
+ return Image::SHORT_IMAGE_TYPES[type_str]
181
+ end
182
+
183
+ def format_pool(options)
184
+ config_file = self.class.table_conf
185
+
186
+ table = CLIHelper::ShowTable.new(config_file, self) do
187
+ column :ID, "ONE identifier for the Image", :size=>4 do |d|
188
+ d["ID"]
189
+ end
190
+
191
+ column :USER, "Username of the Image owner", :left,
192
+ :size=>10 do |d|
193
+ helper.user_name(d, options)
194
+ end
195
+
196
+ column :GROUP, "Group of the Image", :left,
197
+ :size=>10 do |d|
198
+ helper.group_name(d, options)
199
+ end
200
+
201
+ column :NAME, "Name of the Image", :left, :size=>15 do |d|
202
+ d["NAME"]
203
+ end
204
+
205
+ column :DATASTORE, "Name of the Datastore", :left, :size=>10 do |d|
206
+ d["DATASTORE"]
207
+ end
208
+
209
+ column :TYPE, "Type of the Image", :left, :size=>4 do |d,e|
210
+ OneImageHelper.type_to_str(d["TYPE"])
211
+ end
212
+
213
+ column :REGTIME, "Registration time of the Image",
214
+ :size=>15 do |d|
215
+ OpenNebulaHelper.time_to_str(d["REGTIME"])
216
+ end
217
+
218
+ column :PERSISTENT, "Whether the Image is persistent or not",
219
+ :size=>3 do |d|
220
+ OpenNebulaHelper.boolean_to_str(d["PERSISTENT"])
221
+ end
222
+
223
+ column :STAT, "State of the Image", :left, :size=>4 do |d|
224
+ OneImageHelper.state_to_str(d["STATE"])
225
+ end
226
+
227
+ column :RVMS, "Number of VMs currently running from this Image",
228
+ :size=>4 do |d|
229
+ d['RUNNING_VMS']
230
+ end
231
+
232
+ column :SIZE, "Size of the image",
233
+ :size=>7 do |d|
234
+ OpenNebulaHelper.unit_to_str(d['SIZE'].to_i,options,"M")
235
+ end
236
+
237
+ default :ID, :USER, :GROUP, :NAME, :DATASTORE, :SIZE, :TYPE,
238
+ :PERSISTENT , :STAT, :RVMS
239
+ end
240
+
241
+ table
242
+ end
243
+
244
+ private
245
+
246
+ def factory(id=nil)
247
+ if id
248
+ OpenNebula::Image.new_with_id(id, @client)
249
+ else
250
+ xml=OpenNebula::Image.build_xml
251
+ OpenNebula::Image.new(xml, @client)
252
+ end
253
+ end
254
+
255
+ def factory_pool(user_flag=-2)
256
+ OpenNebula::ImagePool.new(@client, user_flag)
257
+ end
258
+
259
+ def format_resource(image)
260
+ str="%-15s: %-20s"
261
+ str_h1="%-80s"
262
+
263
+ CLIHelper.print_header(str_h1 % "IMAGE #{image['ID']} INFORMATION")
264
+ puts str % ["ID", image.id.to_s]
265
+ puts str % ["NAME", image.name]
266
+ puts str % ["USER", image['UNAME']]
267
+ puts str % ["GROUP",image['GNAME']]
268
+ puts str % ["DATASTORE",image['DATASTORE']]
269
+ puts str % ["TYPE", image.type_str]
270
+ puts str % ["REGISTER TIME",
271
+ OpenNebulaHelper.time_to_str(image['REGTIME'])]
272
+ puts str % ["PERSISTENT",
273
+ OpenNebulaHelper.boolean_to_str(image["PERSISTENT"])]
274
+ puts str % ["SOURCE",image['SOURCE']]
275
+ puts str % ["PATH",image['PATH']] if image['PATH'] && !image['PATH'].empty?
276
+ puts str % ["FSTYPE",image['FSTYPE']] if image['FSTYPE'] && !image['FSTYPE'].empty?
277
+ puts str % ["SIZE", OpenNebulaHelper.unit_to_str(image['SIZE'].to_i,{},"M")]
278
+ puts str % ["STATE", image.short_state_str]
279
+ puts str % ["RUNNING_VMS", image['RUNNING_VMS']]
280
+ puts
281
+
282
+ CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
283
+
284
+ ["OWNER", "GROUP", "OTHER"].each { |e|
285
+ mask = "---"
286
+ mask[0] = "u" if image["PERMISSIONS/#{e}_U"] == "1"
287
+ mask[1] = "m" if image["PERMISSIONS/#{e}_M"] == "1"
288
+ mask[2] = "a" if image["PERMISSIONS/#{e}_A"] == "1"
289
+
290
+ puts str % [e, mask]
291
+ }
292
+ puts
293
+
294
+ CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false)
295
+ puts image.template_str
296
+ end
297
+
298
+ def self.create_image_variables(options, name)
299
+ if Array===name
300
+ names=name
301
+ else
302
+ names=[name]
303
+ end
304
+
305
+ t=''
306
+ names.each do |n|
307
+ if options[n]
308
+ t<<"#{n.to_s.upcase}=\"#{options[n]}\"\n"
309
+ end
310
+ end
311
+
312
+ t
313
+ end
314
+
315
+ def self.create_image_template(options)
316
+ template_options=TEMPLATE_OPTIONS.map do |o|
317
+ o[:name].to_sym
318
+ end
319
+
320
+ template=create_image_variables(
321
+ options, template_options-[:persistent])
322
+
323
+ template<<"PERSISTENT=YES\n" if options[:persistent]
324
+
325
+ [0, template]
326
+ end
327
+ end