opennebula-cli 4.14.2 → 4.90.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/NOTICE +1 -1
  3. data/bin/oneacct +1 -1
  4. data/bin/oneacl +1 -1
  5. data/bin/onecluster +4 -1
  6. data/bin/onedatastore +4 -1
  7. data/bin/oneflow +26 -1
  8. data/bin/oneflow-template +57 -1
  9. data/bin/onegroup +4 -1
  10. data/bin/onehost +24 -15
  11. data/bin/oneimage +5 -3
  12. data/bin/onemarket +178 -0
  13. data/bin/onemarketapp +282 -0
  14. data/bin/onesecgroup +18 -1
  15. data/bin/oneshowback +1 -1
  16. data/bin/onetemplate +30 -21
  17. data/bin/oneuser +12 -6
  18. data/bin/oneuser.backup +522 -0
  19. data/bin/onevcenter +287 -1
  20. data/bin/onevdc +4 -1
  21. data/bin/onevm +78 -56
  22. data/bin/onevnet +10 -4
  23. data/bin/onevrouter +305 -0
  24. data/bin/onezone +4 -1
  25. data/lib/cli_helper.rb +1 -1
  26. data/lib/command_parser.rb +1 -1
  27. data/lib/one_helper/oneacct_helper.rb +1 -1
  28. data/lib/one_helper/oneacl_helper.rb +11 -5
  29. data/lib/one_helper/onecluster_helper.rb +1 -1
  30. data/lib/one_helper/onedatastore_helper.rb +17 -7
  31. data/lib/one_helper/onegroup_helper.rb +1 -1
  32. data/lib/one_helper/onehost_helper.rb +2 -5
  33. data/lib/one_helper/oneimage_helper.rb +1 -15
  34. data/lib/one_helper/onemarket_helper.rb +152 -0
  35. data/lib/one_helper/onemarketapp_helper.rb +223 -0
  36. data/lib/one_helper/onequota_helper.rb +1 -1
  37. data/lib/one_helper/onesecgroup_helper.rb +46 -3
  38. data/lib/one_helper/onetemplate_helper.rb +146 -11
  39. data/lib/one_helper/oneuser_helper.rb +1 -1
  40. data/lib/one_helper/onevdc_helper.rb +1 -1
  41. data/lib/one_helper/onevm_helper.rb +37 -53
  42. data/lib/one_helper/onevnet_helper.rb +23 -11
  43. data/lib/one_helper/onevrouter_helper.rb +221 -0
  44. data/lib/one_helper/onezone_helper.rb +1 -1
  45. data/lib/one_helper.rb +193 -25
  46. metadata +21 -10
data/lib/one_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
2
+ # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
3
3
  # #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
5
  # not use this file except in compliance with the License. You may obtain #
@@ -28,7 +28,7 @@ include OpenNebula
28
28
  module OpenNebulaHelper
29
29
  ONE_VERSION=<<-EOT
30
30
  OpenNebula #{OpenNebula::VERSION}
31
- Copyright 2002-2015, OpenNebula Project, OpenNebula Systems
31
+ Copyright 2002-2016, OpenNebula Project, OpenNebula Systems
32
32
 
33
33
  Licensed under the Apache License, Version 2.0 (the "License"); you may
34
34
  not use this file except in compliance with the License. You may obtain
@@ -267,6 +267,12 @@ EOT
267
267
  :description => 'VNC IP where to listen for connections. '<<
268
268
  'By default is 0.0.0.0 (all interfaces).'
269
269
  },
270
+ {
271
+ :name => 'vnc_keymap',
272
+ :large => '--vnc-keymap keymap',
273
+ :format => String,
274
+ :description => 'VNC keyboard layout'
275
+ },
270
276
  {
271
277
  :name => 'spice',
272
278
  :large => '--spice',
@@ -285,12 +291,18 @@ EOT
285
291
  :description => 'spice IP where to listen for connections. '<<
286
292
  'By default is 0.0.0.0 (all interfaces).'
287
293
  },
294
+ {
295
+ :name => 'spice_keymap',
296
+ :large => '--spice-keymap keymap',
297
+ :format => String,
298
+ :description => 'spice keyboard layout'
299
+ },
288
300
  {
289
301
  :name => 'ssh',
290
302
  :large => '--ssh [file]',
291
303
  :description => "Add an ssh public key to the context. If the \n"<<
292
- (' '*31)<<"file is omited then the user variable \n"<<
293
- (' '*31)<<"SSH_PUBLIC_KEY will be used.",
304
+ (' '*31) << "file is omited then the user variable \n"<<
305
+ (' '*31) << "SSH_PUBLIC_KEY will be used.",
294
306
  :format => String,
295
307
  :proc => lambda do |o, options|
296
308
  if !o
@@ -313,8 +325,8 @@ EOT
313
325
  },
314
326
  {
315
327
  :name => 'boot',
316
- :large => '--boot device',
317
- :description => 'Select boot device (hd|fd|cdrom|network)',
328
+ :large => '--boot device_list',
329
+ :description => 'Set boot device list e.g. disk0,disk2,nic0',
318
330
  :format => String
319
331
  },
320
332
  {
@@ -329,12 +341,28 @@ EOT
329
341
  :large => '--init script1,script2',
330
342
  :format => Array,
331
343
  :description => 'Script or scripts to start in context'
344
+ },
345
+ {
346
+ :name => 'startscript',
347
+ :large => '--startscript [file]',
348
+ :format => String,
349
+ :description => 'Start script to be executed'
332
350
  }
333
351
  ]
334
352
 
335
- TEMPLATE_OPTIONS_VM=[TEMPLATE_NAME_VM]+TEMPLATE_OPTIONS+[DRY]
353
+ FORCE={
354
+ :name => 'force',
355
+ :large => '--force',
356
+ :description => 'Overwrite the file'
357
+ }
358
+
359
+ TEMPLATE_OPTIONS_VM = [TEMPLATE_NAME_VM] + TEMPLATE_OPTIONS + [DRY]
360
+
361
+ CAPACITY_OPTIONS_VM = [TEMPLATE_OPTIONS[0], TEMPLATE_OPTIONS[1],
362
+ TEMPLATE_OPTIONS[3]]
336
363
 
337
- CAPACITY_OPTIONS_VM=[TEMPLATE_OPTIONS[0],TEMPLATE_OPTIONS[1],TEMPLATE_OPTIONS[3]]
364
+ UPDATECONF_OPTIONS_VM = TEMPLATE_OPTIONS[6..15] + [TEMPLATE_OPTIONS[2],
365
+ TEMPLATE_OPTIONS[17], TEMPLATE_OPTIONS[18]]
338
366
 
339
367
  OPTIONS = XML, NUMERIC, KILOBYTES
340
368
 
@@ -665,12 +693,12 @@ EOT
665
693
  end
666
694
  end
667
695
 
668
- private
669
-
670
696
  def retrieve_resource(id)
671
697
  factory(id)
672
698
  end
673
699
 
700
+ private
701
+
674
702
  def pool_to_array(pool)
675
703
  if !pool.instance_of?(Hash)
676
704
  phash = pool.to_hash
@@ -714,16 +742,17 @@ EOT
714
742
  client=OneHelper.client
715
743
 
716
744
  pool = case poolname
717
- when "HOST" then OpenNebula::HostPool.new(client)
718
- when "GROUP" then OpenNebula::GroupPool.new(client)
719
- when "USER" then OpenNebula::UserPool.new(client)
720
- when "DATASTORE" then OpenNebula::DatastorePool.new(client)
721
- when "CLUSTER" then OpenNebula::ClusterPool.new(client)
722
- when "VNET" then OpenNebula::VirtualNetworkPool.new(client)
723
- when "IMAGE" then OpenNebula::ImagePool.new(client)
724
- when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client)
725
- when "VM" then OpenNebula::VirtualMachinePool.new(client)
726
- when "ZONE" then OpenNebula::ZonePool.new(client)
745
+ when "HOST" then OpenNebula::HostPool.new(client)
746
+ when "GROUP" then OpenNebula::GroupPool.new(client)
747
+ when "USER" then OpenNebula::UserPool.new(client)
748
+ when "DATASTORE" then OpenNebula::DatastorePool.new(client)
749
+ when "CLUSTER" then OpenNebula::ClusterPool.new(client)
750
+ when "VNET" then OpenNebula::VirtualNetworkPool.new(client)
751
+ when "IMAGE" then OpenNebula::ImagePool.new(client)
752
+ when "VMTEMPLATE" then OpenNebula::TemplatePool.new(client)
753
+ when "VM" then OpenNebula::VirtualMachinePool.new(client)
754
+ when "ZONE" then OpenNebula::ZonePool.new(client)
755
+ when "MARKETPLACE" then OpenNebula::MarketPlacePool.new(client)
727
756
  end
728
757
 
729
758
  rc = pool.info
@@ -819,6 +848,15 @@ EOT
819
848
  end
820
849
  end
821
850
 
851
+ def OpenNebulaHelper.clusters_str(clusters)
852
+ if clusters.nil?
853
+ "-"
854
+ else
855
+ [clusters].flatten.join(',')
856
+ end
857
+
858
+ end
859
+
822
860
  def OpenNebulaHelper.update_template(id, resource, path=nil, xpath='TEMPLATE')
823
861
  return update_template_helper(false, id, resource, path, xpath)
824
862
  end
@@ -915,7 +953,7 @@ EOT
915
953
  end
916
954
 
917
955
  def self.create_context(options)
918
- context_options = [:ssh, :net_context, :context, :init, :files_ds]
956
+ context_options = [:ssh, :net_context, :context, :init, :files_ds, :startscript]
919
957
  if !(options.keys & context_options).empty?
920
958
  lines=[]
921
959
 
@@ -953,8 +991,20 @@ EOT
953
991
  lines << %Q<INIT_SCRIPTS="#{options[:init].join(' ')}">
954
992
  end
955
993
 
994
+ if options[:startscript]
995
+ script = nil
996
+ begin
997
+ script = File.read(options[:startscript]).strip
998
+ rescue Exception => e
999
+ STDERR.puts e.message
1000
+ exit(-1)
1001
+ end
1002
+ script = Base64::strict_encode64(script)
1003
+ lines<<"START_SCRIPT_BASE64=\"#{script}\""
1004
+ end
1005
+
956
1006
  if !lines.empty?
957
- "CONTEXT=[\n"<<lines.map{|l| " "<<l }.join(",\n")<<"\n]\n"
1007
+ "CONTEXT=[\n" << lines.map{|l| " " << l }.join(",\n") << "\n]\n"
958
1008
  else
959
1009
  nil
960
1010
  end
@@ -963,7 +1013,7 @@ EOT
963
1013
  end
964
1014
  end
965
1015
 
966
- def self.create_template(options)
1016
+ def self.create_template(options, template_obj=nil)
967
1017
  template=''
968
1018
 
969
1019
  template<<"NAME=\"#{options[:name]}\"\n" if options[:name]
@@ -1005,7 +1055,10 @@ EOT
1005
1055
  if options[:vnc_password]
1006
1056
  template << ", PASSWD=\"#{options[:vnc_password]}\""
1007
1057
  end
1008
- template<<' ]'<<"\n"
1058
+ if options[:vnc_keymap]
1059
+ template << ", KEYMAP=\"#{options[:vnc_keymap]}\""
1060
+ end
1061
+ template<<' ]' << "\n"
1009
1062
  end
1010
1063
 
1011
1064
  if options[:spice]
@@ -1014,12 +1067,26 @@ EOT
1014
1067
  if options[:spice_password]
1015
1068
  template << ", PASSWD=\"#{options[:spice_password]}\""
1016
1069
  end
1017
- template<<' ]'<<"\n"
1070
+ if options[:spice_keymap]
1071
+ template << ", KEYMAP=\"#{options[:spice_keymap]}\""
1072
+ end
1073
+ template<<' ]' << "\n"
1018
1074
  end
1019
1075
 
1020
1076
  context=create_context(options)
1021
1077
  template<<context if context
1022
1078
 
1079
+ if options[:userdata] && !template_obj.nil?
1080
+ if template_obj.has_elements?('TEMPLATE/EC2')
1081
+ template_obj.add_element(
1082
+ 'TEMPLATE/EC2',
1083
+ 'USERDATA' => options[:userdata])
1084
+
1085
+ template << template_obj.template_like_str(
1086
+ 'TEMPLATE', false, 'EC2')
1087
+ end
1088
+ end
1089
+
1023
1090
  [0, template]
1024
1091
  end
1025
1092
 
@@ -1034,4 +1101,105 @@ EOT
1034
1101
  # in options hash
1035
1102
  (template_options-options.keys)!=template_options
1036
1103
  end
1104
+
1105
+ def self.sunstone_url
1106
+ if (one_sunstone = ENV['ONE_SUNSTONE'])
1107
+ one_sunstone
1108
+ elsif (one_xmlrpc = ENV['ONE_XMLRPC'])
1109
+ uri = URI(one_xmlrpc)
1110
+ "#{uri.scheme}://#{uri.host}:9869"
1111
+ else
1112
+ "http://localhost:9869"
1113
+ end
1114
+ end
1115
+
1116
+ def self.download_resource_sunstone(kind, id, path, force)
1117
+ client = OneHelper.client
1118
+ user, password = client.one_auth.split(":", 2)
1119
+
1120
+ # Step 1: Build Session to get Cookie
1121
+ uri = URI(File.join(sunstone_url,"login"))
1122
+
1123
+ req = Net::HTTP::Post.new(uri)
1124
+ req.basic_auth user, password
1125
+
1126
+ begin
1127
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
1128
+ http.request(req)
1129
+ end
1130
+ rescue
1131
+ return OpenNebula::Error.new("Error connecting to '#{uri}'.")
1132
+ end
1133
+
1134
+ cookie = res.response['set-cookie'].split('; ')[0]
1135
+
1136
+ if cookie.nil?
1137
+ return OpenNebula::Error.new("Unable to get Cookie. Is OpenNebula running?")
1138
+ end
1139
+
1140
+ # Step 2: Open '/' to get the csrftoken
1141
+ uri = URI(sunstone_url)
1142
+
1143
+ req = Net::HTTP::Get.new(uri)
1144
+ req['Cookie'] = cookie
1145
+
1146
+ begin
1147
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
1148
+ http.request(req)
1149
+ end
1150
+ rescue
1151
+ return OpenNebula::Error.new("Error connecting to '#{uri}'.")
1152
+ end
1153
+
1154
+ m = res.body.match(/var csrftoken = '(.*)';/)
1155
+ csrftoken = m[1] rescue nil
1156
+
1157
+ if csrftoken.nil?
1158
+ return OpenNebula::Error.new("Unable to get csrftoken.")
1159
+ end
1160
+
1161
+ # Step 3: Download resource
1162
+ uri = URI(File.join(sunstone_url,
1163
+ kind.to_s,
1164
+ id.to_s,
1165
+ "download?csrftoken=#{csrftoken}"))
1166
+
1167
+ req = Net::HTTP::Get.new(uri)
1168
+
1169
+ req['Cookie'] = cookie
1170
+ req['User-Agent'] = "OpenNebula CLI"
1171
+
1172
+ begin
1173
+ File.open(path, 'wb') do |f|
1174
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
1175
+ http.request(req) do |res|
1176
+ res.read_body do |chunk|
1177
+ f.write(chunk)
1178
+ end
1179
+ end
1180
+ end
1181
+ end
1182
+ rescue Errno::EACCES
1183
+ return OpenNebula::Error.new("Target file not writable.")
1184
+ end
1185
+
1186
+ error_message = nil
1187
+
1188
+ File.open(path, 'rb') do |f|
1189
+ begin
1190
+ f.seek(-1024, IO::SEEK_END)
1191
+ rescue Errno::EINVAL
1192
+ end
1193
+
1194
+ tail = f.read
1195
+
1196
+ m = tail.match(/@\^_\^@ (.*) @\^_\^@/m)
1197
+ error_message = m[1] if m
1198
+ end
1199
+
1200
+ if error_message
1201
+ File.unlink(path)
1202
+ return OpenNebula::Error.new("Remote server error: #{error_message}")
1203
+ end
1204
+ end
1037
1205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.14.2
4
+ version: 4.90.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opennebula
@@ -16,17 +16,18 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.14.2
19
+ version: 4.90.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.14.2
26
+ version: 4.90.0.beta1
27
27
  description: Commands used to talk to OpenNebula
28
28
  email: contact@opennebula.org
29
29
  executables:
30
+ - oneuser.backup
30
31
  - oneacct
31
32
  - oneacl
32
33
  - onecluster
@@ -34,17 +35,20 @@ executables:
34
35
  - oneflow
35
36
  - oneflow-template
36
37
  - onegroup
37
- - oneimage
38
+ - onehost
39
+ - onemarket
40
+ - onemarketapp
38
41
  - onesecgroup
39
42
  - oneshowback
40
43
  - onetemplate
41
44
  - oneuser
45
+ - onevcenter
42
46
  - onevdc
43
47
  - onevnet
48
+ - onevrouter
44
49
  - onezone
45
- - onevcenter
50
+ - oneimage
46
51
  - onevm
47
- - onehost
48
52
  extensions: []
49
53
  extra_rdoc_files: []
50
54
  files:
@@ -59,14 +63,18 @@ files:
59
63
  - bin/onegroup
60
64
  - bin/onehost
61
65
  - bin/oneimage
66
+ - bin/onemarket
67
+ - bin/onemarketapp
62
68
  - bin/onesecgroup
63
69
  - bin/oneshowback
64
70
  - bin/onetemplate
65
71
  - bin/oneuser
72
+ - bin/oneuser.backup
66
73
  - bin/onevcenter
67
74
  - bin/onevdc
68
75
  - bin/onevm
69
76
  - bin/onevnet
77
+ - bin/onevrouter
70
78
  - bin/onezone
71
79
  - lib/cli_helper.rb
72
80
  - lib/command_parser.rb
@@ -78,6 +86,8 @@ files:
78
86
  - lib/one_helper/onegroup_helper.rb
79
87
  - lib/one_helper/onehost_helper.rb
80
88
  - lib/one_helper/oneimage_helper.rb
89
+ - lib/one_helper/onemarket_helper.rb
90
+ - lib/one_helper/onemarketapp_helper.rb
81
91
  - lib/one_helper/onequota_helper.rb
82
92
  - lib/one_helper/onesecgroup_helper.rb
83
93
  - lib/one_helper/onetemplate_helper.rb
@@ -85,6 +95,7 @@ files:
85
95
  - lib/one_helper/onevdc_helper.rb
86
96
  - lib/one_helper/onevm_helper.rb
87
97
  - lib/one_helper/onevnet_helper.rb
98
+ - lib/one_helper/onevrouter_helper.rb
88
99
  - lib/one_helper/onezone_helper.rb
89
100
  homepage: http://opennebula.org
90
101
  licenses:
@@ -101,12 +112,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
112
  version: '0'
102
113
  required_rubygems_version: !ruby/object:Gem::Requirement
103
114
  requirements:
104
- - - ">="
115
+ - - ">"
105
116
  - !ruby/object:Gem::Version
106
- version: '0'
117
+ version: 1.3.1
107
118
  requirements: []
108
119
  rubyforge_project:
109
- rubygems_version: 2.4.5.1
120
+ rubygems_version: 2.5.1
110
121
  signing_key:
111
122
  specification_version: 4
112
123
  summary: OpenNebula Command Line Interface