opennebula-cli 3.8.0 → 3.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/oneacct +10 -5
- data/bin/oneacl +5 -1
- data/bin/onecluster +5 -1
- data/bin/onedatastore +5 -1
- data/bin/onegroup +40 -1
- data/bin/onehost +5 -1
- data/bin/oneimage +31 -2
- data/bin/onetemplate +24 -4
- data/bin/oneuser +43 -21
- data/bin/onevm +47 -9
- data/bin/onevnet +15 -1
- data/lib/cli_helper.rb +50 -9
- data/lib/command_parser.rb +79 -37
- data/lib/one_helper/oneacct_helper.rb +4 -4
- data/lib/one_helper/onedatastore_helper.rb +8 -2
- data/lib/one_helper/onegroup_helper.rb +41 -4
- data/lib/one_helper/onehost_helper.rb +9 -0
- data/lib/one_helper/oneimage_helper.rb +15 -10
- data/lib/one_helper/onequota_helper.rb +134 -72
- data/lib/one_helper/oneuser_helper.rb +50 -14
- data/lib/one_helper.rb +210 -16
- metadata +55 -29
data/lib/one_helper.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
require 'cli_helper'
|
18
18
|
|
19
|
-
require '
|
19
|
+
require 'opennebula'
|
20
20
|
include OpenNebula
|
21
21
|
|
22
22
|
module OpenNebulaHelper
|
@@ -76,14 +76,49 @@ EOT
|
|
76
76
|
:format => String
|
77
77
|
}
|
78
78
|
|
79
|
+
DRY={
|
80
|
+
:name => 'dry',
|
81
|
+
:large => '--dry',
|
82
|
+
:description => 'Just print the template'
|
83
|
+
}
|
84
|
+
|
85
|
+
CLIENT_OPTIONS=[
|
86
|
+
{
|
87
|
+
:name => 'user',
|
88
|
+
:large => '--user name',
|
89
|
+
:description => 'User name used to connect to OpenNebula',
|
90
|
+
:format => String
|
91
|
+
},
|
92
|
+
{
|
93
|
+
:name => 'password',
|
94
|
+
:large => '--password password',
|
95
|
+
:description => 'Password to authenticate with OpenNebula',
|
96
|
+
:format => String
|
97
|
+
},
|
98
|
+
{
|
99
|
+
:name => 'endpoint',
|
100
|
+
:large => '--endpoint endpoint',
|
101
|
+
:description => 'URL of OpenNebula xmlrpc frontend',
|
102
|
+
:format => String
|
103
|
+
}
|
104
|
+
]
|
105
|
+
|
79
106
|
TEMPLATE_OPTIONS=[
|
80
107
|
{
|
81
108
|
:name => 'cpu',
|
82
109
|
:large => '--cpu cpu',
|
83
110
|
:description =>
|
84
|
-
|
111
|
+
"CPU percentage reserved for the VM (1=100% one\n"<<
|
112
|
+
" "*31<<"CPU)",
|
85
113
|
:format => Float
|
86
114
|
},
|
115
|
+
{
|
116
|
+
:name => 'vcpu',
|
117
|
+
:large => '--vcpu vcpu',
|
118
|
+
:description =>
|
119
|
+
"Number of virtualized CPUs",
|
120
|
+
:format => Integer
|
121
|
+
},
|
87
122
|
{
|
88
123
|
:name => 'arch',
|
89
124
|
:large => '--arch arch',
|
@@ -118,39 +153,130 @@ EOT
|
|
118
153
|
{
|
119
154
|
:name => 'disk',
|
120
155
|
:large => '--disk disk0,disk1',
|
121
|
-
:description =>
|
156
|
+
:description => "Disks to attach. To use a disk owned by other\n"<<
|
157
|
+
" "*31<<"user use user[disk]",
|
122
158
|
:format => Array
|
123
159
|
},
|
124
160
|
{
|
125
161
|
:name => 'network',
|
126
162
|
:large => '--network network0,network1',
|
127
|
-
:description =>
|
163
|
+
:description => "Networks to attach. To use a network owned by\n"<<
|
164
|
+
" "*31<<"other user use user[network]",
|
128
165
|
:format => Array
|
129
166
|
},
|
130
167
|
{
|
131
168
|
:name => 'raw',
|
132
169
|
:large => '--raw string',
|
133
|
-
:description =>
|
170
|
+
:description => "Raw string to add to the template. Not to be\n"<<
|
171
|
+
" "*31<<"confused with the RAW attribute",
|
172
|
+
:format => String
|
173
|
+
},
|
174
|
+
{
|
175
|
+
:name => 'vnc',
|
176
|
+
:large => '--vnc',
|
177
|
+
:description => 'Add VNC server to the VM'
|
178
|
+
},
|
179
|
+
{
|
180
|
+
:name => 'ssh',
|
181
|
+
:large => '--ssh [file]',
|
182
|
+
:description => "Add an ssh public key to the context. If the \n"<<
|
183
|
+
(' '*31)<<"file is omited then the user variable \n"<<
|
184
|
+
(' '*31)<<"SSH_PUBLIC_KEY will be used.",
|
185
|
+
:format => String,
|
186
|
+
:proc => lambda do |o, options|
|
187
|
+
if !o
|
188
|
+
[0, true]
|
189
|
+
else
|
190
|
+
[0, o]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
},
|
194
|
+
{
|
195
|
+
:name => 'net_context',
|
196
|
+
:large => '--net_context',
|
197
|
+
:description => 'Add network contextualization parameters'
|
198
|
+
},
|
199
|
+
{
|
200
|
+
:name => 'context',
|
201
|
+
:large => '--context line1,line2,line3',
|
202
|
+
:format => Array,
|
203
|
+
:description => 'Lines to add to the context section'
|
204
|
+
},
|
205
|
+
{
|
206
|
+
:name => 'boot',
|
207
|
+
:large => '--boot device',
|
208
|
+
:description => 'Select boot device (hd|fd|cdrom|network)',
|
134
209
|
:format => String
|
135
210
|
}
|
136
211
|
]
|
137
212
|
|
138
|
-
TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS
|
213
|
+
TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS+[DRY]
|
139
214
|
|
140
215
|
OPTIONS = XML, NUMERIC, KILOBYTES
|
141
216
|
|
142
217
|
class OneHelper
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
218
|
+
attr_accessor :client
|
219
|
+
|
220
|
+
def self.get_client(options)
|
221
|
+
if defined?(@@client)
|
222
|
+
@@client
|
223
|
+
else
|
224
|
+
secret=nil
|
225
|
+
user=options[:user]
|
226
|
+
if user
|
227
|
+
password=options[:password]||self.get_password
|
228
|
+
secret="#{user}:#{password}"
|
229
|
+
end
|
230
|
+
|
231
|
+
endpoint=options[:endpoint]
|
232
|
+
|
233
|
+
@@client=OpenNebula::Client.new(secret, endpoint)
|
149
234
|
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.client
|
238
|
+
if defined?(@@client)
|
239
|
+
@@client
|
240
|
+
else
|
241
|
+
self.get_client({})
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
if RUBY_VERSION>="1.9.3"
|
246
|
+
require 'io/console'
|
247
|
+
def self.get_password
|
248
|
+
print "Password: "
|
249
|
+
pass=nil
|
250
|
+
STDIN.noecho {|io| pass=io.gets }
|
251
|
+
puts
|
252
|
+
|
253
|
+
pass.chop! if pass
|
254
|
+
pass
|
255
|
+
end
|
256
|
+
else
|
257
|
+
# This function is copied from ruby net/imap.rb
|
258
|
+
def self.get_password
|
259
|
+
print "Password: "
|
260
|
+
system("stty", "-echo")
|
261
|
+
begin
|
262
|
+
return gets.chop
|
263
|
+
ensure
|
264
|
+
system("stty", "echo")
|
265
|
+
print "\n"
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def initialize(secret=nil, endpoint=nil)
|
271
|
+
@client=nil
|
150
272
|
|
151
273
|
@translation_hash = nil
|
152
274
|
end
|
153
275
|
|
276
|
+
def set_client(options)
|
277
|
+
@client=OpenNebulaHelper::OneHelper.get_client(options)
|
278
|
+
end
|
279
|
+
|
154
280
|
def create_resource(options, &block)
|
155
281
|
resource = factory
|
156
282
|
|
@@ -369,7 +495,7 @@ EOT
|
|
369
495
|
end
|
370
496
|
|
371
497
|
def pool_to_array(pool)
|
372
|
-
|
498
|
+
if !pool.instance_of?(Hash)
|
373
499
|
phash = pool.to_hash
|
374
500
|
else
|
375
501
|
phash = pool
|
@@ -408,7 +534,7 @@ EOT
|
|
408
534
|
def OpenNebulaHelper.rname_to_id(name, poolname)
|
409
535
|
return 0, name.to_i if name.match(/^[0123456789]+$/)
|
410
536
|
|
411
|
-
client
|
537
|
+
client=OneHelper.client
|
412
538
|
|
413
539
|
pool = case poolname
|
414
540
|
when "HOST" then OpenNebula::HostPool.new(client)
|
@@ -557,7 +683,7 @@ EOT
|
|
557
683
|
|
558
684
|
template<<"#{section.upcase}=[\n"
|
559
685
|
template<<" #{name.upcase}_UNAME=\"#{user}\",\n" if user
|
560
|
-
if object.match(/^\d
|
686
|
+
if object.match(/^\d+$/)
|
561
687
|
template<<" #{name.upcase}_ID=#{object}\n"
|
562
688
|
else
|
563
689
|
template<<" #{name.upcase}=\"#{object}\"\n"
|
@@ -568,12 +694,74 @@ EOT
|
|
568
694
|
[0, template]
|
569
695
|
end
|
570
696
|
|
697
|
+
def self.create_context(options)
|
698
|
+
if !(options.keys & [:ssh, :net_context, :context]).empty?
|
699
|
+
lines=[]
|
700
|
+
|
701
|
+
if options[:ssh]
|
702
|
+
if options[:ssh]==true
|
703
|
+
lines<<"SSH_PUBLIC_KEY=\"$USER[SSH_PUBLIC_KEY]\""
|
704
|
+
else
|
705
|
+
begin
|
706
|
+
key=File.read(options[:ssh]).strip
|
707
|
+
rescue Exception => e
|
708
|
+
STDERR.puts e.message
|
709
|
+
exit(-1)
|
710
|
+
end
|
711
|
+
lines<<"SSH_PUBLIC_KEY=\"#{key}\""
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
if options[:net_context] && options[:network]
|
716
|
+
nets=options[:network].map {|n| parse_user_object(n).last }
|
717
|
+
|
718
|
+
if nets!=nets.uniq
|
719
|
+
STDERR.puts "Network context generation from command "<<
|
720
|
+
"line is not supported for VMs with\n"<<
|
721
|
+
"more than one network with the same name."
|
722
|
+
exit(-1)
|
723
|
+
end
|
724
|
+
|
725
|
+
nets.each_with_index do |name, index|
|
726
|
+
lines<<"ETH#{index}_IP = \"$NIC[IP, NETWORK=\\\"#{name}\\\"]\""
|
727
|
+
lines<<"ETH#{index}_NETWORK = \"$NETWORK[NETWORK_ADDRESS, NETWORK=\\\"#{name}\\\"]\""
|
728
|
+
lines<<"ETH#{index}_MASK = \"$NETWORK[NETWORK_MASK, NETWORK=\\\"#{name}\\\"]\""
|
729
|
+
lines<<"ETH#{index}_GATEWAY = \"$NETWORK[GATEWAY, NETWORK=\\\"#{name}\\\"]\""
|
730
|
+
lines<<"ETH#{index}_DNS = \"$NETWORK[DNS, NETWORK=\\\"#{name}\\\"]\""
|
731
|
+
end
|
732
|
+
end
|
733
|
+
|
734
|
+
lines+=options[:context] if options[:context]
|
735
|
+
|
736
|
+
if !lines.empty?
|
737
|
+
"CONTEXT=[\n"<<lines.map{|l| " "<<l }.join(",\n")<<"\n]\n"
|
738
|
+
else
|
739
|
+
nil
|
740
|
+
end
|
741
|
+
else
|
742
|
+
nil
|
743
|
+
end
|
744
|
+
end
|
745
|
+
|
571
746
|
def self.create_template(options)
|
572
747
|
template=''
|
573
748
|
|
574
749
|
template<<"NAME=\"#{options[:name]}\"\n" if options[:name]
|
575
|
-
|
750
|
+
|
751
|
+
if options[:arch] || options[:boot]
|
752
|
+
template<<"OS = [\n"
|
753
|
+
|
754
|
+
lines=[]
|
755
|
+
lines<<" ARCH = \"#{options[:arch]}\"" if options[:arch]
|
756
|
+
lines<<" BOOT = \"#{options[:boot]}\"" if options[:boot]
|
757
|
+
|
758
|
+
template<<lines.join(",\n")
|
759
|
+
|
760
|
+
template << " ]\n"
|
761
|
+
end
|
762
|
+
|
576
763
|
template<<"CPU=#{options[:cpu]}\n" if options[:cpu]
|
764
|
+
template<<"VCPU=#{options[:vcpu]}\n" if options[:vcpu]
|
577
765
|
template<<"MEMORY=#{options[:memory]}\n" if options[:memory]
|
578
766
|
template<<"#{options[:raw]}\n" if options[:raw]
|
579
767
|
|
@@ -591,6 +779,12 @@ EOT
|
|
591
779
|
template<<res.last
|
592
780
|
end
|
593
781
|
|
782
|
+
if options[:vnc]
|
783
|
+
template<<'GRAPHICS=[ TYPE="vnc", LISTEN="0.0.0.0" ]'<<"\n"
|
784
|
+
end
|
785
|
+
|
786
|
+
context=create_context(options)
|
787
|
+
template<<context if context
|
594
788
|
|
595
789
|
[0, template]
|
596
790
|
end
|
metadata
CHANGED
@@ -1,30 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: opennebula-cli
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1897663041
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
version: 3.9.0.beta
|
6
12
|
platform: ruby
|
7
|
-
authors:
|
13
|
+
authors:
|
8
14
|
- OpenNebula
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
18
|
+
|
19
|
+
date: 2012-12-20 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: opennebula-oca
|
16
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
19
|
-
- - =
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: -1897663041
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 9
|
33
|
+
- 0
|
34
|
+
- beta
|
35
|
+
version: 3.9.0.beta
|
22
36
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *2153025180
|
37
|
+
version_requirements: *id001
|
25
38
|
description: Commands used to talk to OpenNebula
|
26
39
|
email: contact@opennebula.org
|
27
|
-
executables:
|
40
|
+
executables:
|
28
41
|
- oneacct
|
29
42
|
- oneacl
|
30
43
|
- onecluster
|
@@ -37,8 +50,10 @@ executables:
|
|
37
50
|
- onevm
|
38
51
|
- onevnet
|
39
52
|
extensions: []
|
53
|
+
|
40
54
|
extra_rdoc_files: []
|
41
|
-
|
55
|
+
|
56
|
+
files:
|
42
57
|
- bin/oneacct
|
43
58
|
- bin/oneacl
|
44
59
|
- bin/onecluster
|
@@ -69,27 +84,38 @@ files:
|
|
69
84
|
- LICENSE
|
70
85
|
homepage: http://opennebula.org
|
71
86
|
licenses: []
|
87
|
+
|
72
88
|
post_install_message:
|
73
89
|
rdoc_options: []
|
74
|
-
|
90
|
+
|
91
|
+
require_paths:
|
75
92
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
94
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
103
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
104
|
+
requirements:
|
105
|
+
- - ">"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 25
|
108
|
+
segments:
|
109
|
+
- 1
|
110
|
+
- 3
|
111
|
+
- 1
|
112
|
+
version: 1.3.1
|
88
113
|
requirements: []
|
114
|
+
|
89
115
|
rubyforge_project:
|
90
116
|
rubygems_version: 1.8.15
|
91
117
|
signing_key:
|
92
118
|
specification_version: 3
|
93
119
|
summary: OpenNebula Client API
|
94
120
|
test_files: []
|
95
|
-
|
121
|
+
|