opennebula-cli 4.10.2 → 4.11.80.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/onetemplate CHANGED
@@ -171,7 +171,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
171
171
 
172
172
  instantiate_desc = <<-EOT.unindent
173
173
  Creates a new VM instance from the given Template. This VM can be
174
- managed with the 'onevm' command
174
+ managed with the 'onevm' command.
175
+
176
+ The source Template can be modified adding or replacing attributes with
177
+ the optional file argument, or with the options.
175
178
  EOT
176
179
 
177
180
  command :instantiate, instantiate_desc, :templateid, [:file, nil],
data/bin/onevcenter CHANGED
@@ -215,6 +215,87 @@ cmd=CommandParser::CmdParser.new(ARGV) do
215
215
  exit 0
216
216
  end
217
217
 
218
+ vms_desc = <<-EOT.unindent
219
+ Import vCenter running Virtual Machines into OpenNebula
220
+ EOT
221
+
222
+ command :vms, vms_desc, :options=>[ VCENTER, USER, PASS ] do
223
+ if options[:vuser].nil? ||
224
+ options[:vpass].nil? ||
225
+ options[:vcenter].nil?
226
+ STDERR.puts "vCenter connection parameters are mandatory to import"\
227
+ " VM templates:\n"\
228
+ "\t --vcenter vCenter hostname\n"\
229
+ "\t --vuser username to login in vcenter\n"\
230
+ "\t --vpass password for the user"
231
+ exit -1
232
+ end
233
+
234
+ begin
235
+ STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
236
+
237
+ vc = VCenterDriver::VIClient.new_connection(
238
+ :user => options[:vuser],
239
+ :password => options[:vpass],
240
+ :host => options[:vcenter])
241
+
242
+ STDOUT.print "done!\n\n"
243
+
244
+ STDOUT.print "Looking for running Virtual Machines..."
245
+
246
+ rs = vc.running_vms
247
+
248
+ STDOUT.print "done!\n"
249
+
250
+ rs.each {|dc, tmps|
251
+ STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
252
+
253
+ next if STDIN.gets.strip.downcase != 'y'
254
+
255
+ if tmps.empty?
256
+ STDOUT.print " No new running Virtual Machines found in"\
257
+ " #{dc}...\n\n"
258
+ next
259
+ end
260
+
261
+ tmps.each{ |v|
262
+ STDOUT.print "\n * Running Virtual Machine found:\n"\
263
+ " - Name : #{v[:name]}\n"\
264
+ " - UUID : #{v[:uuid]}\n"\
265
+ " - Cluster: #{v[:host]}\n"\
266
+ " Import this Virtual Machine [y/n]? "
267
+
268
+ next if STDIN.gets.strip.downcase != 'y'
269
+
270
+ one_v = ::OpenNebula::VirtualMachine.new(
271
+ ::OpenNebula::VirtualMachine.build_xml, vc.one)
272
+
273
+ rc = one_v.allocate(v[:one])
274
+
275
+ if ::OpenNebula.is_error?(rc)
276
+ STDOUT.puts " Error creating Virtual Machine: "\
277
+ "#{rc.message}\n"
278
+ end
279
+
280
+ rc = one_v.deploy v[:host_id]
281
+
282
+ if ::OpenNebula.is_error?(rc)
283
+ STDOUT.puts " Error creating Virtual Machine: "\
284
+ "#{rc.message}\n"
285
+ else
286
+ STDOUT.puts " OpenNebula VM #{one_v.id} "\
287
+ "created!\n"
288
+ end
289
+ }
290
+ }
291
+ rescue Exception => e
292
+ STDOUT.puts "error: #{e.message}"
293
+ exit -1
294
+ end
295
+
296
+ exit 0
297
+ end
298
+
218
299
  network_desc = <<-EOT.unindent
219
300
  Import vCenter networks into OpenNebula
220
301
  EOT
data/bin/onevdc ADDED
@@ -0,0 +1,280 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # -------------------------------------------------------------------------- #
4
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
5
+ # #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7
+ # not use this file except in compliance with the License. You may obtain #
8
+ # a copy of the License at #
9
+ # #
10
+ # http://www.apache.org/licenses/LICENSE-2.0 #
11
+ # #
12
+ # Unless required by applicable law or agreed to in writing, software #
13
+ # distributed under the License is distributed on an "AS IS" BASIS, #
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15
+ # See the License for the specific language governing permissions and #
16
+ # limitations under the License. #
17
+ #--------------------------------------------------------------------------- #
18
+
19
+ ONE_LOCATION=ENV["ONE_LOCATION"]
20
+
21
+ if !ONE_LOCATION
22
+ RUBY_LIB_LOCATION="/usr/lib/one/ruby"
23
+ else
24
+ RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
25
+ end
26
+
27
+ $: << RUBY_LIB_LOCATION
28
+ $: << RUBY_LIB_LOCATION+"/cli"
29
+
30
+ require 'command_parser'
31
+ require 'one_helper/onevdc_helper'
32
+
33
+ cmd=CommandParser::CmdParser.new(ARGV) do
34
+ usage "`onevdc` <command> [<args>] [<options>]"
35
+ version OpenNebulaHelper::ONE_VERSION
36
+
37
+ helper = OneVdcHelper.new
38
+
39
+ before_proc do
40
+ helper.set_client(options)
41
+ end
42
+
43
+ ########################################################################
44
+ # Global Options
45
+ ########################################################################
46
+ set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
47
+
48
+ list_options = CLIHelper::OPTIONS
49
+ list_options << OpenNebulaHelper::XML
50
+ list_options << OpenNebulaHelper::NUMERIC
51
+ list_options << OpenNebulaHelper::DESCRIBE
52
+
53
+ ########################################################################
54
+ # Formatters for arguments
55
+ ########################################################################
56
+ set :format, :vdcid, OneVdcHelper.to_id_desc do |arg|
57
+ helper.to_id(arg)
58
+ end
59
+
60
+ set :format, :vdcid_list, OneVdcHelper.list_to_id_desc do |arg|
61
+ helper.list_to_id(arg)
62
+ end
63
+
64
+ set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
65
+ OpenNebulaHelper.rname_to_id(arg, "GROUP")
66
+ end
67
+
68
+ set :format, :zoneid, OpenNebulaHelper.rname_to_id_desc("ZONE") do |arg|
69
+ OpenNebulaHelper.rname_to_id(arg, "ZONE")
70
+ end
71
+
72
+ set :format, :clusterid,
73
+ "#{OpenNebulaHelper.rname_to_id_desc('CLUSTER')}. Can be set to ALL" do |arg|
74
+
75
+ if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
76
+ [0, Vdc::ALL_RESOURCES]
77
+ else
78
+ OpenNebulaHelper.rname_to_id(arg, "CLUSTER")
79
+ end
80
+ end
81
+
82
+ set :format, :hostid,
83
+ "#{OpenNebulaHelper.rname_to_id_desc('HOST')}. Can be set to ALL" do |arg|
84
+
85
+ if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
86
+ [0, Vdc::ALL_RESOURCES]
87
+ else
88
+ OpenNebulaHelper.rname_to_id(arg, "HOST")
89
+ end
90
+ end
91
+
92
+ set :format, :datastoreid,
93
+ "#{OpenNebulaHelper.rname_to_id_desc('DATASTORE')}. Can be set to ALL" do |arg|
94
+
95
+ if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
96
+ [0, Vdc::ALL_RESOURCES]
97
+ else
98
+ OpenNebulaHelper.rname_to_id(arg, "DATASTORE")
99
+ end
100
+ end
101
+
102
+ set :format, :vnetid,
103
+ "#{OpenNebulaHelper.rname_to_id_desc('VNET')}. Can be set to ALL" do |arg|
104
+
105
+ if !arg.nil? and arg.class != Fixnum and arg.upcase == "ALL"
106
+ [0, Vdc::ALL_RESOURCES]
107
+ else
108
+ OpenNebulaHelper.rname_to_id(arg, "VNET")
109
+ end
110
+ end
111
+
112
+ ########################################################################
113
+ # Commands
114
+ ########################################################################
115
+
116
+ create_desc = <<-EOT.unindent
117
+ Creates a new VDC
118
+ EOT
119
+
120
+ command :create, create_desc, :name do
121
+ helper.create_resource(options) do |vdc|
122
+ template = "NAME = \"#{args[0]}\""
123
+ vdc.allocate(template)
124
+ end
125
+ end
126
+
127
+ rename_desc = <<-EOT.unindent
128
+ Renames the VDC
129
+ EOT
130
+
131
+ command :rename, rename_desc, :vdcid, :name do
132
+ helper.perform_action(args[0],options,"renamed") do |o|
133
+ o.rename(args[1])
134
+ end
135
+ end
136
+
137
+ update_desc = <<-EOT.unindent
138
+ Update the template contents. If a path is not provided the editor will
139
+ be launched to modify the current content.
140
+ EOT
141
+
142
+ command :update, update_desc, :vdcid, [:file, nil],
143
+ :options=>OpenNebulaHelper::APPEND do
144
+ helper.perform_action(args[0],options,"modified") do |obj|
145
+ if options[:append]
146
+ str = OpenNebulaHelper.append_template(args[0], obj, args[1])
147
+ else
148
+ str = OpenNebulaHelper.update_template(args[0], obj, args[1])
149
+ end
150
+
151
+ obj.update(str, options[:append])
152
+ end
153
+ end
154
+
155
+ delete_desc = <<-EOT.unindent
156
+ Deletes the given VDC
157
+ EOT
158
+
159
+ command :delete, delete_desc, [:range, :vdcid_list] do
160
+ helper.perform_actions(args[0],options,"deleted") do |obj|
161
+ obj.delete
162
+ end
163
+ end
164
+
165
+ add_group_desc = <<-EOT.unindent
166
+ Adds a Group to the given VDC
167
+ EOT
168
+
169
+ command :addgroup, add_group_desc, [:range, :vdcid_list], :groupid do
170
+ helper.perform_actions(args[0],options,"group added") do |obj|
171
+ obj.add_group(args[1].to_i)
172
+ end
173
+ end
174
+
175
+ del_group_desc = <<-EOT.unindent
176
+ Deletes a Group from the given VDC
177
+ EOT
178
+
179
+ command :delgroup, del_group_desc, [:range, :vdcid_list], :groupid do
180
+ helper.perform_actions(args[0],options,"group deleted") do |obj|
181
+ obj.del_group(args[1].to_i)
182
+ end
183
+ end
184
+
185
+ add_cluster_desc = <<-EOT.unindent
186
+ Adds a Cluster (from a specific Zone) to the given VDC
187
+ EOT
188
+
189
+ command :addcluster, add_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
190
+ helper.perform_actions(args[0],options,"cluster added") do |obj|
191
+ obj.add_cluster(args[1].to_i, args[2].to_i)
192
+ end
193
+ end
194
+
195
+ del_cluster_desc = <<-EOT.unindent
196
+ Deletes a Cluster (from a specific Zone) from the given VDC
197
+ EOT
198
+
199
+ command :delcluster, del_cluster_desc, [:range, :vdcid_list], :zoneid, :clusterid do
200
+ helper.perform_actions(args[0],options,"cluster deleted") do |obj|
201
+ obj.del_cluster(args[1].to_i, args[2].to_i)
202
+ end
203
+ end
204
+
205
+ add_host_desc = <<-EOT.unindent
206
+ Adds a Host (from a specific Zone) to the given VDC
207
+ EOT
208
+
209
+ command :addhost, add_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
210
+ helper.perform_actions(args[0],options,"host added") do |obj|
211
+ obj.add_host(args[1].to_i, args[2].to_i)
212
+ end
213
+ end
214
+
215
+ del_host_desc = <<-EOT.unindent
216
+ Deletes a Host (from a specific Zone) from the given VDC
217
+ EOT
218
+
219
+ command :delhost, del_host_desc, [:range, :vdcid_list], :zoneid, :hostid do
220
+ helper.perform_actions(args[0],options,"host deleted") do |obj|
221
+ obj.del_host(args[1].to_i, args[2].to_i)
222
+ end
223
+ end
224
+
225
+ add_datastore_desc = <<-EOT.unindent
226
+ Adds a Datastore (from a specific Zone) to the given VDC
227
+ EOT
228
+
229
+ command :adddatastore, add_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
230
+ helper.perform_actions(args[0],options,"datastore added") do |obj|
231
+ obj.add_datastore(args[1].to_i, args[2].to_i)
232
+ end
233
+ end
234
+
235
+ del_datastore_desc = <<-EOT.unindent
236
+ Deletes a Datastore (from a specific Zone) from the given VDC
237
+ EOT
238
+
239
+ command :deldatastore, del_datastore_desc, [:range, :vdcid_list], :zoneid, :datastoreid do
240
+ helper.perform_actions(args[0],options,"datastore deleted") do |obj|
241
+ obj.del_datastore(args[1].to_i, args[2].to_i)
242
+ end
243
+ end
244
+
245
+ add_vnet_desc = <<-EOT.unindent
246
+ Adds a Virtual Network (from a specific Zone) to the given VDC
247
+ EOT
248
+
249
+ command :addvnet, add_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
250
+ helper.perform_actions(args[0],options,"vnet added") do |obj|
251
+ obj.add_vnet(args[1].to_i, args[2].to_i)
252
+ end
253
+ end
254
+
255
+ del_vnet_desc = <<-EOT.unindent
256
+ Deletes a Virtual Network (from a specific Zone) from the given VDC
257
+ EOT
258
+
259
+ command :delvnet, del_vnet_desc, [:range, :vdcid_list], :zoneid, :vnetid do
260
+ helper.perform_actions(args[0],options,"vnet deleted") do |obj|
261
+ obj.del_vnet(args[1].to_i, args[2].to_i)
262
+ end
263
+ end
264
+
265
+ list_desc = <<-EOT.unindent
266
+ Lists VDCs in the pool
267
+ EOT
268
+
269
+ command :list, list_desc, :options=>list_options do
270
+ helper.list_pool(options)
271
+ end
272
+
273
+ show_desc = <<-EOT.unindent
274
+ Shows information for the given VDC
275
+ EOT
276
+
277
+ command :show, show_desc,:vdcid, :options=>OpenNebulaHelper::XML do
278
+ helper.show_resource(args[0],options)
279
+ end
280
+ end
data/bin/onevnet CHANGED
@@ -253,7 +253,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
253
253
  exit -1
254
254
  end
255
255
 
256
- vn.reserve(name, size, options[:address_range], addr, args[1])
256
+ res = vn.reserve(name, size, options[:address_range], addr, args[1])
257
+
258
+ if !OpenNebula.is_error?(res)
259
+ puts "Reservation VNET ID: #{res}"
260
+ end
261
+
262
+ res
257
263
  end
258
264
  end
259
265
 
@@ -343,9 +349,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
343
349
  obj.delete_element("AR_POOL/AR[AR_ID!=#{args[1]}]")
344
350
  obj.delete_element("AR_POOL/AR/LEASES")
345
351
  obj.delete_element("AR_POOL/AR/USED_LEASES")
352
+ obj.delete_element("AR_POOL/AR/MAC_END")
353
+ obj.delete_element("AR_POOL/AR/IP_END")
354
+ obj.delete_element("AR_POOL/AR/IP6_ULA")
355
+ obj.delete_element("AR_POOL/AR/IP6_ULA_END")
356
+ obj.delete_element("AR_POOL/AR/IP6_GLOBAL")
357
+ obj.delete_element("AR_POOL/AR/IP6_GLOBAL_END")
346
358
 
347
359
  if obj.template_like_str("AR_POOL").empty?
348
- puts "Address Range #{args[1]} does not exit for "<<
360
+ puts "Address Range #{args[1]} does not exist for "<<
349
361
  "Virtual Network #{args[0]}"
350
362
  exit -1
351
363
  end
data/lib/cli_helper.rb CHANGED
@@ -211,7 +211,7 @@ module CLIHelper
211
211
  pool=@data.keys.first
212
212
  return print_table(nil, options) if !pool
213
213
 
214
- element=pool.split('_').first
214
+ element=pool.split('_')[0..-2].join('_')
215
215
 
216
216
  pool_data=@data.dsearch("#{pool}/#{element}")
217
217
  pool_data=[pool_data].flatten if pool_data
data/lib/one_helper.rb CHANGED
@@ -169,15 +169,6 @@ EOT
169
169
  "Which resources can be created by group users "<<
170
170
  "(VM+NET+IMAGE+TEMPLATE by default)",
171
171
  :format => String
172
- },
173
- {
174
- :name => 'admin_resources',
175
- :large => '--admin_resources res_str',
176
- :short => "-o",
177
- :description =>
178
- "Which resources can be created by the admin user "<<
179
- "(VM+NET+IMAGE+TEMPLATE by default)",
180
- :format => String
181
172
  }
182
173
  ]
183
174
 
@@ -18,19 +18,35 @@ require 'one_helper'
18
18
  require 'optparse/time'
19
19
 
20
20
  class AcctHelper < OpenNebulaHelper::OneHelper
21
- START_TIME = {
21
+ START_TIME_ACCT = {
22
22
  :name => "start_time",
23
23
  :short => "-s TIME",
24
24
  :large => "--start TIME" ,
25
- :description => "Start date and time to take into account",
25
+ :description => "First day of the data to retrieve",
26
26
  :format => Time
27
27
  }
28
28
 
29
- END_TIME = {
29
+ END_TIME_ACCT = {
30
30
  :name => "end_time",
31
31
  :short => "-e TIME",
32
32
  :large => "--end TIME" ,
33
- :description => "End date and time",
33
+ :description => "Last day of the data to retrieve",
34
+ :format => Time
35
+ }
36
+
37
+ START_TIME_SHOWBACK = {
38
+ :name => "start_time",
39
+ :short => "-s TIME",
40
+ :large => "--start TIME" ,
41
+ :description => "First month of the data",
42
+ :format => Time
43
+ }
44
+
45
+ END_TIME_SHOWBACK = {
46
+ :name => "end_time",
47
+ :short => "-e TIME",
48
+ :large => "--end TIME" ,
49
+ :description => "Last month of the data",
34
50
  :format => Time
35
51
  }
36
52
 
@@ -95,8 +111,8 @@ class AcctHelper < OpenNebulaHelper::OneHelper
95
111
  :description => "Split the output in a table for each VM"
96
112
  }
97
113
 
98
- ACCT_OPTIONS = [START_TIME, END_TIME, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT]
99
-
114
+ ACCT_OPTIONS = [START_TIME_ACCT, END_TIME_ACCT, USERFILTER, GROUP, HOST, XPATH, XML, JSON, SPLIT]
115
+ SHOWBACK_OPTIONS = [START_TIME_SHOWBACK, END_TIME_SHOWBACK, USERFILTER, GROUP, XML, JSON]
100
116
 
101
117
  ACCT_TABLE = CLIHelper::ShowTable.new("oneacct.yaml", nil) do
102
118
  column :UID, "User ID", :size=>4 do |d|
@@ -152,6 +168,50 @@ class AcctHelper < OpenNebulaHelper::OneHelper
152
168
  default :VID, :HOSTNAME, :ACTION, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NET_RX, :NET_TX
153
169
  end
154
170
 
171
+ SHOWBACK_TABLE = CLIHelper::ShowTable.new("oneshowback.yaml", nil) do
172
+ column :UID, "User ID", :size=>4 do |d|
173
+ d["UID"]
174
+ end
175
+
176
+ column :USER_NAME, "User name", :left, :size=>12 do |d|
177
+ d["UNAME"]
178
+ end
179
+
180
+ column :GID, "Group ID", :size=>4 do |d|
181
+ d["GID"]
182
+ end
183
+
184
+ column :GROUP_NAME, "Group name", :left, :size=>12 do |d|
185
+ d["GNAME"]
186
+ end
187
+
188
+ column :VM_ID, "Virtual Machine ID", :size=>6 do |d|
189
+ d["VMID"]
190
+ end
191
+
192
+ column :VM_NAME, "Virtual Machine name", :left, :size=>12 do |d|
193
+ d["VMNAME"]
194
+ end
195
+
196
+ column :MONTH, "Month", :size=>5 do |d|
197
+ d["MONTH"]
198
+ end
199
+
200
+ column :YEAR, "Year", :size=>5 do |d|
201
+ d["YEAR"]
202
+ end
203
+
204
+ column :HOURS, "Hours", :size=>6 do |d|
205
+ d["HOURS"]
206
+ end
207
+
208
+ column :COST, "Cost", :size=>15 do |d|
209
+ d["TOTAL_COST"]
210
+ end
211
+
212
+ default :USER_NAME, :GROUP_NAME, :VM_ID, :VM_NAME, :MONTH, :YEAR, :HOURS, :COST
213
+ end
214
+
155
215
  def self.print_start_end_time_header(start_time, end_time)
156
216
  print "Showing active history records from "
157
217
 
@@ -184,4 +244,12 @@ class AcctHelper < OpenNebulaHelper::OneHelper
184
244
  CLIHelper.scr_restore
185
245
  puts
186
246
  end
247
+
248
+ def self.print_month_header(year, month)
249
+ CLIHelper.scr_bold
250
+ CLIHelper.scr_underline
251
+ puts "# Showback for #{month}/#{year}".ljust(80)
252
+ CLIHelper.scr_restore
253
+ puts
254
+ end
187
255
  end