opennebula-cli 5.2.1 → 5.3.80.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/onehost +27 -6
- data/bin/onevcenter +35 -460
- data/bin/onevm +27 -0
- data/bin/onevmgroup +185 -0
- data/bin/onevnet +44 -6
- data/bin/onezone +37 -0
- data/lib/one_helper.rb +47 -0
- data/lib/one_helper/oneacct_helper.rb +1 -5
- data/lib/one_helper/oneacl_helper.rb +6 -4
- data/lib/one_helper/onehost_helper.rb +12 -7
- data/lib/one_helper/oneimage_helper.rb +27 -14
- data/lib/one_helper/onesecgroup_helper.rb +4 -0
- data/lib/one_helper/onevm_helper.rb +22 -9
- data/lib/one_helper/onevmgroup_helper.rb +170 -0
- data/lib/one_helper/onevnet_helper.rb +16 -3
- data/lib/one_helper/onezone_helper.rb +96 -0
- metadata +14 -12
data/bin/onevm
CHANGED
@@ -177,6 +177,10 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
177
177
|
format_int(arg)
|
178
178
|
end
|
179
179
|
|
180
|
+
set :format, :size, "Disk size in MiB" do |arg|
|
181
|
+
OpenNebulaHelper.size_in_mb(arg)
|
182
|
+
end
|
183
|
+
|
180
184
|
########################################################################
|
181
185
|
# Commands
|
182
186
|
########################################################################
|
@@ -843,6 +847,29 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
843
847
|
end
|
844
848
|
end
|
845
849
|
|
850
|
+
disk_resize_desc = <<-EOT.unindent
|
851
|
+
Resizes a VM disk. The new size should be larger than the old one.
|
852
|
+
|
853
|
+
States: RUNNING, POWEROFF
|
854
|
+
EOT
|
855
|
+
|
856
|
+
command :"disk-resize", disk_resize_desc,
|
857
|
+
:vmid, :diskid, :size do
|
858
|
+
helper.perform_action(args[0],options,"disk resized") do |o|
|
859
|
+
o.info
|
860
|
+
size = o["/VM/TEMPLATE/DISK[DISK_ID='#{args[1]}']/SIZE"].to_i
|
861
|
+
|
862
|
+
new_size = args[2]
|
863
|
+
|
864
|
+
if size < new_size
|
865
|
+
o.disk_resize(args[1].to_i, args[2])
|
866
|
+
else
|
867
|
+
OpenNebula::Error.new("New size '#{new_size}' must be larger " \
|
868
|
+
"than current size '#{size}'")
|
869
|
+
end
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
846
873
|
list_desc = <<-EOT.unindent
|
847
874
|
Lists VMs in the pool
|
848
875
|
EOT
|
data/bin/onevmgroup
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# -------------------------------------------------------------------------- #
|
4
|
+
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
|
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/onevmgroup_helper'
|
32
|
+
|
33
|
+
cmd=CommandParser::CmdParser.new(ARGV) do
|
34
|
+
usage "`onevmgroup` <command> [<args>] [<options>]"
|
35
|
+
version OpenNebulaHelper::ONE_VERSION
|
36
|
+
|
37
|
+
helper = OneVMGroupHelper.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, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
57
|
+
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
58
|
+
end
|
59
|
+
|
60
|
+
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
61
|
+
OpenNebulaHelper.rname_to_id(arg, "USER")
|
62
|
+
end
|
63
|
+
|
64
|
+
set :format, :vmgroupid, OneVMGroupHelper.to_id_desc do |arg|
|
65
|
+
helper.to_id(arg)
|
66
|
+
end
|
67
|
+
|
68
|
+
set :format, :vmgroupid_list, OneVMGroupHelper.list_to_id_desc do |arg|
|
69
|
+
helper.list_to_id(arg)
|
70
|
+
end
|
71
|
+
|
72
|
+
set :format, :filterflag, OneVMGroupHelper.filterflag_to_i_desc do |arg|
|
73
|
+
helper.filterflag_to_i(arg)
|
74
|
+
end
|
75
|
+
|
76
|
+
########################################################################
|
77
|
+
# Commands
|
78
|
+
########################################################################
|
79
|
+
|
80
|
+
create_desc = <<-EOT.unindent
|
81
|
+
Creates a new VM Group from the given description
|
82
|
+
EOT
|
83
|
+
|
84
|
+
command :create, create_desc, :file do
|
85
|
+
helper.create_resource(options) do |obj|
|
86
|
+
begin
|
87
|
+
template = File.read(args[0])
|
88
|
+
|
89
|
+
obj.allocate(template)
|
90
|
+
rescue => e
|
91
|
+
STDERR.puts e.messsage
|
92
|
+
exit -1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
delete_desc = <<-EOT.unindent
|
98
|
+
Deletes the VM Group
|
99
|
+
EOT
|
100
|
+
|
101
|
+
command :delete, delete_desc, [:range, :vmgroupid_list] do
|
102
|
+
helper.perform_actions(args[0],options,"deleted") do |obj|
|
103
|
+
obj.delete
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
list_desc = <<-EOT.unindent
|
108
|
+
Lists VM Group in the pool
|
109
|
+
EOT
|
110
|
+
|
111
|
+
command :list, list_desc, [:filterflag, nil], :options=>list_options do
|
112
|
+
helper.list_pool(options, false, args[0])
|
113
|
+
end
|
114
|
+
|
115
|
+
show_desc = <<-EOT.unindent
|
116
|
+
Shows information for the given VM Group
|
117
|
+
EOT
|
118
|
+
|
119
|
+
command :show, show_desc, :vmgroupid, :options=>OpenNebulaHelper::XML do
|
120
|
+
helper.show_resource(args[0],options)
|
121
|
+
end
|
122
|
+
|
123
|
+
chgrp_desc = <<-EOT.unindent
|
124
|
+
Changes the VM Group's group
|
125
|
+
EOT
|
126
|
+
|
127
|
+
command :chgrp, chgrp_desc,[:range, :vmgroupid_list], :groupid do
|
128
|
+
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
129
|
+
obj.chown(-1, args[1].to_i)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
chown_desc = <<-EOT.unindent
|
134
|
+
Changes the VM Group's owner and group
|
135
|
+
EOT
|
136
|
+
|
137
|
+
command :chown, chown_desc, [:range, :vmgroupid_list], :userid,
|
138
|
+
[:groupid,nil] do
|
139
|
+
gid = args[2].nil? ? -1 : args[2].to_i
|
140
|
+
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
141
|
+
obj.chown(args[1].to_i, gid)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
chmod_desc = <<-EOT.unindent
|
146
|
+
Changes the VM Group permissions
|
147
|
+
EOT
|
148
|
+
|
149
|
+
command :chmod, chmod_desc, [:range, :vmgroupid_list], :octet do
|
150
|
+
helper.perform_actions(args[0],options, "Permissions changed") do |t|
|
151
|
+
t.chmod_octet(args[1])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
update_desc = <<-EOT.unindent
|
156
|
+
Update the template contents. If a path is not provided the editor will
|
157
|
+
be launched to modify the current content.
|
158
|
+
EOT
|
159
|
+
|
160
|
+
command :update, update_desc, :vmgroupid, [:file, nil],
|
161
|
+
:options=>OpenNebulaHelper::APPEND do
|
162
|
+
helper.perform_action(args[0],options,"modified") do |obj|
|
163
|
+
if options[:append]
|
164
|
+
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
165
|
+
else
|
166
|
+
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
|
167
|
+
end
|
168
|
+
|
169
|
+
helper.set_client(options)
|
170
|
+
obj = helper.retrieve_resource(obj.id)
|
171
|
+
|
172
|
+
obj.update(str, options[:append])
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
rename_desc = <<-EOT.unindent
|
177
|
+
Renames the VM Group
|
178
|
+
EOT
|
179
|
+
|
180
|
+
command :rename, rename_desc, :vmgroupid, :name do
|
181
|
+
helper.perform_action(args[0],options,"renamed") do |o|
|
182
|
+
o.rename(args[1])
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
data/bin/onevnet
CHANGED
@@ -123,15 +123,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
123
123
|
if options[:ip]
|
124
124
|
if options[:ip6_global] || options[:ip6_ula]
|
125
125
|
ar << "TYPE=\"IP4_6\""
|
126
|
+
elsif options[:ip6]
|
127
|
+
ar << "TYPE=\"IP4_6_STATIC\""
|
126
128
|
else
|
127
129
|
ar << "TYPE=\"IP4\""
|
128
130
|
end
|
131
|
+
elsif options[:ip6]
|
132
|
+
ar << "TYPE=\"IP6_STATIC\""
|
133
|
+
elsif options[:ip6_global] || options[:ip6_ula]
|
134
|
+
ar << "TYPE=\"IP6\""
|
129
135
|
else
|
130
|
-
|
131
|
-
ar << "TYPE=\"IP6\""
|
132
|
-
else
|
133
|
-
ar << "TYPE=\"ETHER\""
|
134
|
-
end
|
136
|
+
ar << "TYPE=\"ETHER\""
|
135
137
|
end
|
136
138
|
|
137
139
|
if options[:size]
|
@@ -141,7 +143,41 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
141
143
|
exit -1
|
142
144
|
end
|
143
145
|
|
146
|
+
if options[:ip6]
|
147
|
+
m = /([\h:]*)\/(\d.*)$/.match(options[:ip6])
|
148
|
+
|
149
|
+
if m.nil? || m[1].nil?
|
150
|
+
STDERR.puts "Missing or wrong IP6"
|
151
|
+
exit -1
|
152
|
+
else
|
153
|
+
begin
|
154
|
+
require 'ipaddr'
|
155
|
+
|
156
|
+
ip = IPAddr.new(m[1])
|
157
|
+
|
158
|
+
if !ip.ipv6?
|
159
|
+
STDERR.puts "Wrong IP6 format address"
|
160
|
+
exit -1
|
161
|
+
end
|
162
|
+
rescue
|
163
|
+
STDERR.puts "Wrong IP6 format address"
|
164
|
+
exit -1
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
if m[2].nil?
|
170
|
+
STDERR.puts "IP6 address need to set the prefix length"
|
171
|
+
exit -1
|
172
|
+
end
|
173
|
+
|
174
|
+
ar << ", PREFIX_LENGTH=\"#{m[2]}\""
|
175
|
+
|
176
|
+
options[:ip6] = m[1]
|
177
|
+
end
|
178
|
+
|
144
179
|
ar << ", IP = " << options[:ip] if options[:ip]
|
180
|
+
ar << ", IP6 = " << options[:ip6] if options[:ip6]
|
145
181
|
ar << ", MAC = " << options[:mac] if options[:mac]
|
146
182
|
ar << ", GLOBAL_PREFIX = " <<
|
147
183
|
options[:ip6_global] if options[:ip6_global]
|
@@ -234,7 +270,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
234
270
|
|
235
271
|
command :reserve, reserve_desc, :vnetid, [:vnetid, nil],
|
236
272
|
:options=>STD_OPTIONS + [OneVNetHelper::AR, OneVNetHelper::NAME,
|
237
|
-
OneVNetHelper::SIZE, OneVNetHelper::MAC, OneVNetHelper::IP
|
273
|
+
OneVNetHelper::SIZE, OneVNetHelper::MAC, OneVNetHelper::IP,
|
274
|
+
OneVNetHelper::IP6 ] do
|
238
275
|
helper.perform_action(args[0],options,"reservation made") do |vn|
|
239
276
|
size = options[:size] || -1
|
240
277
|
name = options[:name] || -1
|
@@ -242,6 +279,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
242
279
|
addr = nil
|
243
280
|
addr = options[:mac] if options[:mac]
|
244
281
|
addr = options[:ip] if options[:ip]
|
282
|
+
addr = options[:ip6] if options[:ip6]
|
245
283
|
|
246
284
|
if size == -1
|
247
285
|
STDERR.puts "Specify a size (-s size) for the reservation"
|
data/bin/onezone
CHANGED
@@ -91,6 +91,43 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
addserver_desc = <<-EOT.unindent
|
95
|
+
Add an OpenNebula server to this zone.
|
96
|
+
EOT
|
97
|
+
|
98
|
+
command :"server-add", addserver_desc, :zoneid, :options =>
|
99
|
+
[ OneZoneHelper::SERVER_NAME, OneZoneHelper::SERVER_ENDPOINT] do
|
100
|
+
|
101
|
+
if options[:server_name].nil? || options[:server_rpc].nil?
|
102
|
+
STDERR.puts "To add a server set:"
|
103
|
+
STDERR.puts "\t-n <server name>"
|
104
|
+
STDERR.puts "\t-r <RPC endpoint>"
|
105
|
+
exit -1
|
106
|
+
end
|
107
|
+
|
108
|
+
template = <<-EOT
|
109
|
+
SERVER = [
|
110
|
+
NAME="#{options[:server_name]}",
|
111
|
+
ENDPOINT="#{options[:server_rpc]}"
|
112
|
+
]
|
113
|
+
EOT
|
114
|
+
|
115
|
+
helper.perform_action(args[0], options, "server added") do |o|
|
116
|
+
o.add_servers(template)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
delserver_desc = <<-EOT.unindent
|
122
|
+
Delete an OpenNebula server from this zone.
|
123
|
+
EOT
|
124
|
+
|
125
|
+
command :"server-del", delserver_desc, :zoneid, :serverid do
|
126
|
+
helper.perform_action(args[0], options, "server deleted") do |o|
|
127
|
+
o.delete_servers(args[1].to_i)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
94
131
|
update_desc = <<-EOT.unindent
|
95
132
|
Update the template contents. If a path is not provided the editor will
|
96
133
|
be launched to modify the current content.
|
data/lib/one_helper.rb
CHANGED
@@ -37,8 +37,10 @@ EOT
|
|
37
37
|
|
38
38
|
if ONE_LOCATION
|
39
39
|
TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli"
|
40
|
+
VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION)
|
40
41
|
else
|
41
42
|
TABLE_CONF_PATH="/etc/one/cli"
|
43
|
+
VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION)
|
42
44
|
end
|
43
45
|
|
44
46
|
EDITOR_PATH='/usr/bin/vi'
|
@@ -352,6 +354,13 @@ EOT
|
|
352
354
|
:name => 'report_ready',
|
353
355
|
:large => '--report_ready',
|
354
356
|
:description => 'Sends READY=YES to OneGate, useful for OneFlow'
|
357
|
+
},
|
358
|
+
{
|
359
|
+
:name => 'vcenter_vm_folder',
|
360
|
+
:large => '--vcenter_vm_folder path',
|
361
|
+
:format => String,
|
362
|
+
:description => "In a vCenter environment sets the the VMs and Template folder where the VM will be placed in." \
|
363
|
+
" The path uses slashes to separate folders. For example: --vcenter_vm_folder \"/Management/VMs\""
|
355
364
|
}
|
356
365
|
]
|
357
366
|
|
@@ -482,6 +491,21 @@ EOT
|
|
482
491
|
end
|
483
492
|
end
|
484
493
|
|
494
|
+
|
495
|
+
# receive a object key => value format
|
496
|
+
# returns hashed values
|
497
|
+
def encrypt(opts, token)
|
498
|
+
res = {}
|
499
|
+
opts.each do |key, value|
|
500
|
+
cipher = OpenSSL::Cipher::AES.new(256,:CBC)
|
501
|
+
cipher.encrypt.key = token[0..31]
|
502
|
+
encrypted = cipher.update(value) + cipher.final
|
503
|
+
res[key] = Base64::encode64(encrypted)
|
504
|
+
end
|
505
|
+
|
506
|
+
return res
|
507
|
+
end
|
508
|
+
|
485
509
|
def list_pool(options, top=false, filter_flag=nil)
|
486
510
|
if options[:describe]
|
487
511
|
table = format_pool(options)
|
@@ -771,6 +795,27 @@ EOT
|
|
771
795
|
OneHelper.name_to_id(name, pool, poolname)
|
772
796
|
end
|
773
797
|
|
798
|
+
def OpenNebulaHelper.size_in_mb(size)
|
799
|
+
m = size.match(/^(\d+(?:\.\d+)?)(m|mb|g|gb)?$/i)
|
800
|
+
|
801
|
+
if !m
|
802
|
+
# return OpenNebula::Error.new('Size value malformed')
|
803
|
+
return -1, 'Size value malformed'
|
804
|
+
else
|
805
|
+
multiplier=case m[2]
|
806
|
+
when /(g|gb)/i
|
807
|
+
1024
|
808
|
+
else
|
809
|
+
1
|
810
|
+
end
|
811
|
+
|
812
|
+
value=m[1].to_f*multiplier
|
813
|
+
|
814
|
+
# return value.ceil
|
815
|
+
return 0, value.ceil
|
816
|
+
end
|
817
|
+
end
|
818
|
+
|
774
819
|
def OpenNebulaHelper.rname_to_id_desc(poolname)
|
775
820
|
"OpenNebula #{poolname} name or id"
|
776
821
|
end
|
@@ -1105,6 +1150,8 @@ EOT
|
|
1105
1150
|
template<<' ]' << "\n"
|
1106
1151
|
end
|
1107
1152
|
|
1153
|
+
template<<"VCENTER_VM_FOLDER=#{options[:vcenter_vm_folder]}\n" if options[:vcenter_vm_folder]
|
1154
|
+
|
1108
1155
|
context=create_context(options)
|
1109
1156
|
template<<context if context
|
1110
1157
|
|
@@ -135,10 +135,6 @@ class AcctHelper < OpenNebulaHelper::OneHelper
|
|
135
135
|
VirtualMachine.get_history_action d["ACTION"]
|
136
136
|
end
|
137
137
|
|
138
|
-
column :REASON, "VM state change reason", :left, :size=>4 do |d|
|
139
|
-
VirtualMachine.get_reason d["REASON"]
|
140
|
-
end
|
141
|
-
|
142
138
|
column :START_TIME, "Start time", :size=>14 do |d|
|
143
139
|
OpenNebulaHelper.time_to_str(d['STIME'])
|
144
140
|
end
|
@@ -187,7 +183,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
|
|
187
183
|
OpenNebulaHelper.unit_to_str(total_disk_size * 1024.0, {})
|
188
184
|
end
|
189
185
|
|
190
|
-
default :VID, :HOSTNAME, :ACTION, :
|
186
|
+
default :VID, :HOSTNAME, :ACTION, :START_TIME, :END_TIME, :MEMORY, :CPU, :NETRX, :NETTX, :DISK
|
191
187
|
end
|
192
188
|
|
193
189
|
SHOWBACK_TABLE = CLIHelper::ShowTable.new(self.table_conf("oneshowback.yaml"), nil) do
|