opennebula 4.13.80.beta1 → 4.13.85.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c22ee052b29d751b16a22e9be737f1d4009a4ef
4
- data.tar.gz: b882b0d31b1096e5287b47ec799f8f6b88fbcecd
3
+ metadata.gz: 34c2819d350be1117978fe3b3f78afec44b8e940
4
+ data.tar.gz: 4e38c2f9cd5727cdbedeed755432a3ac48d4db76
5
5
  SHA512:
6
- metadata.gz: 2602b4e09ee0587d0eadd55f581209d3f5946f1bedc826a477fa2bf1b1238000df4801358ecf2042e4e769f7d9c21f01aa4da4799f81b6edca7417037ef9cecc
7
- data.tar.gz: a89f6eabb2d2f196b2c82abf5cb7facc4a04ba7edb7b002fe1ed3bd47a90a88bf046e0386022782769d847625d81817eb25711920b764897a0868561bf2c4b47
6
+ metadata.gz: 51dc60b82690e463c9e751c4cbc61511cefcd314900cd49cb0c5009bcecf48de30e7c8053c59257064324d6a7e6023d0d25eaa6980f193203a789bbe6af38507
7
+ data.tar.gz: a1a8dda4f61c98046af6fec6bd66ab2f825962cde62cd19bfc9c7bab158179f74c8fede788f239da8f200f014cf34f79b44d31c1e4f5eba244912cece753dfd8
@@ -0,0 +1,211 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
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 'rubygems'
18
+ require 'uri'
19
+
20
+ require 'digest/sha1'
21
+ require 'net/https'
22
+
23
+ require "rexml/document"
24
+
25
+ begin
26
+ require 'rexml/formatters/pretty'
27
+ REXML_FORMATTERS=true
28
+ rescue LoadError
29
+ REXML_FORMATTERS=false
30
+ end
31
+
32
+ begin
33
+ require 'curb'
34
+ CURL_LOADED=true
35
+ rescue LoadError
36
+ CURL_LOADED=false
37
+ end
38
+
39
+ begin
40
+ require 'net/http/post/multipart'
41
+ MULTIPART_LOADED=true
42
+ rescue LoadError
43
+ MULTIPART_LOADED=false
44
+ end
45
+
46
+ ###############################################################################
47
+ # The CloudClient module contains general functionality to implement a
48
+ # Cloud Client
49
+ ###############################################################################
50
+ module CloudClient
51
+
52
+ # OpenNebula version
53
+ VERSION = '4.13.85'
54
+
55
+ # #########################################################################
56
+ # Default location for the authentication file
57
+ # #########################################################################
58
+ DEFAULT_AUTH_FILE = ENV["HOME"]+"/.one/one_auth"
59
+
60
+ # #########################################################################
61
+ # Gets authorization credentials from ONE_AUTH or default
62
+ # auth file.
63
+ #
64
+ # Raises an error if authorization is not found
65
+ # #########################################################################
66
+ def self.get_one_auth
67
+ if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
68
+ File.file?(ENV["ONE_AUTH"])
69
+ one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
70
+ elsif File.file?(DEFAULT_AUTH_FILE)
71
+ one_auth=File.read(DEFAULT_AUTH_FILE).strip.split(':')
72
+ else
73
+ raise "No authorization data present"
74
+ end
75
+
76
+ raise "Authorization data malformed" if one_auth.length < 2
77
+
78
+ one_auth
79
+ end
80
+
81
+ # #########################################################################
82
+ # Starts an http connection and calls the block provided. SSL flag
83
+ # is set if needed.
84
+ # #########################################################################
85
+ def self.http_start(url, timeout, &block)
86
+ host = nil
87
+ port = nil
88
+
89
+ if ENV['http_proxy']
90
+ uri_proxy = URI.parse(ENV['http_proxy'])
91
+ host = uri_proxy.host
92
+ port = uri_proxy.port
93
+ end
94
+
95
+ http = Net::HTTP::Proxy(host, port).new(url.host, url.port)
96
+
97
+ if timeout
98
+ http.read_timeout = timeout.to_i
99
+ end
100
+
101
+ if url.scheme=='https'
102
+ http.use_ssl = true
103
+ http.verify_mode=OpenSSL::SSL::VERIFY_NONE
104
+ end
105
+
106
+ begin
107
+ res = http.start do |connection|
108
+ block.call(connection)
109
+ end
110
+ rescue Errno::ECONNREFUSED => e
111
+ str = "Error connecting to server (#{e.to_s}).\n"
112
+ str << "Server: #{url.host}:#{url.port}"
113
+
114
+ return CloudClient::Error.new(str,"503")
115
+ rescue Errno::ETIMEDOUT => e
116
+ str = "Error timeout connecting to server (#{e.to_s}).\n"
117
+ str << "Server: #{url.host}:#{url.port}"
118
+
119
+ return CloudClient::Error.new(str,"504")
120
+ rescue Timeout::Error => e
121
+ str = "Error timeout while connected to server (#{e.to_s}).\n"
122
+ str << "Server: #{url.host}:#{url.port}"
123
+
124
+ return CloudClient::Error.new(str,"504")
125
+ rescue SocketError => e
126
+ str = "Error timeout while connected to server (#{e.to_s}).\n"
127
+
128
+ return CloudClient::Error.new(str,"503")
129
+ rescue
130
+ return CloudClient::Error.new($!.to_s,"503")
131
+ end
132
+
133
+ if res.is_a?(Net::HTTPSuccess)
134
+ res
135
+ else
136
+ CloudClient::Error.new(res.body, res.code)
137
+ end
138
+ end
139
+
140
+ # #########################################################################
141
+ # The Error Class represents a generic error in the Cloud Client
142
+ # library. It contains a readable representation of the error.
143
+ # #########################################################################
144
+ class Error
145
+ attr_reader :message
146
+ attr_reader :code
147
+
148
+ # +message+ a description of the error
149
+ def initialize(message=nil, code="500")
150
+ @message=message
151
+ @code=code
152
+ end
153
+
154
+ def to_s()
155
+ @message
156
+ end
157
+ end
158
+
159
+ # #########################################################################
160
+ # Returns true if the object returned by a method of the OpenNebula
161
+ # library is an Error
162
+ # #########################################################################
163
+ def self.is_error?(value)
164
+ value.class==CloudClient::Error
165
+ end
166
+ end
167
+
168
+ # Command line help functions
169
+ module CloudCLI
170
+ def print_xml(xml_text)
171
+ begin
172
+ doc = REXML::Document.new(xml_text)
173
+ rescue REXML::ParseException => e
174
+ return e.message, -1
175
+ end
176
+
177
+ xml = doc.root
178
+
179
+ if xml.nil?
180
+ return xml_text, -1
181
+ end
182
+
183
+ str = String.new
184
+ if REXML_FORMATTERS
185
+ formatter = REXML::Formatters::Pretty.new
186
+ formatter.compact = true
187
+
188
+ formatter.write(xml,str)
189
+ else
190
+ str = xml.to_s
191
+ end
192
+
193
+ return str, 0
194
+ end
195
+
196
+ # Returns the command name
197
+ def cmd_name
198
+ File.basename($0)
199
+ end
200
+
201
+ def version_text
202
+ version=<<EOT
203
+ OpenNebula #{CloudClient::VERSION}
204
+ Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs
205
+
206
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
207
+ not use this file except in compliance with the License. You may obtain
208
+ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
209
+ EOT
210
+ end
211
+ end
@@ -60,5 +60,5 @@ require 'opennebula/system'
60
60
  module OpenNebula
61
61
 
62
62
  # OpenNebula version
63
- VERSION = '4.13.80'
63
+ VERSION = '4.13.85'
64
64
  end
@@ -49,7 +49,7 @@ module OpenNebula
49
49
  # XML-RPC Methods for the Image Object
50
50
  #######################################################################
51
51
 
52
- # Retrieves all or part of the VirtualMachines in the pool.
52
+ # Retrieves all or part of the Images in the pool.
53
53
  def info(*args)
54
54
  case args.size
55
55
  when 0
@@ -65,8 +65,22 @@ module OpenNebula
65
65
  #######################################################################
66
66
 
67
67
  # Retrieves the information of the given Template.
68
- def info()
69
- super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
68
+ # @param extended [true,false] optional flag to process the template and
69
+ # include extended information, such as the SIZE for each DISK
70
+ def info(extended=false)
71
+ return Error.new('ID not defined') if !@pe_id
72
+
73
+ rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, extended)
74
+
75
+ if !OpenNebula.is_error?(rc)
76
+ initialize_xml(rc, 'VMTEMPLATE')
77
+ rc = nil
78
+
79
+ @pe_id = self['ID'].to_i if self['ID']
80
+ @name = self['NAME'] if self['NAME']
81
+ end
82
+
83
+ return rc
70
84
  end
71
85
 
72
86
  alias_method :info!, :info
@@ -49,7 +49,7 @@ module OpenNebula
49
49
  # XML-RPC Methods for the Template Object
50
50
  #######################################################################
51
51
 
52
- # Retrieves all or part of the VirtualMachines in the pool.
52
+ # Retrieves all or part of the Templates in the pool.
53
53
  def info(*args)
54
54
  case args.size
55
55
  when 0
@@ -702,6 +702,12 @@ module OpenNebula
702
702
  self['DEPLOY_ID']
703
703
  end
704
704
 
705
+ # Returns the deploy_id of the VirtualMachine (numeric value)
706
+ def keep_disks?
707
+ !self['USER_TEMPLATE/KEEP_DISKS_ON_DONE'].nil? &&
708
+ self['USER_TEMPLATE/KEEP_DISKS_ON_DONE'].downcase=="yes"
709
+ end
710
+
705
711
  # Clones the VM's source Template, replacing the disks with live snapshots
706
712
  # of the current disks. The VM capacity and NICs are also preserved
707
713
  #
@@ -710,114 +716,139 @@ module OpenNebula
710
716
  # @return [Integer, OpenNebula::Error] the new Template ID in case of
711
717
  # success, error otherwise
712
718
  def save_as_template(name)
713
- rc = info()
714
- return rc if OpenNebula.is_error?(rc)
719
+ img_ids = []
720
+ new_tid = nil
715
721
 
716
- tid = self['TEMPLATE/TEMPLATE_ID']
717
- if tid.nil? || tid.empty?
718
- return Error.new('VM has no template to be saved')
719
- end
722
+ begin
723
+ rc = info()
724
+ raise if OpenNebula.is_error?(rc)
720
725
 
721
- if state_str() != "POWEROFF"
722
- return Error.new("VM state must be POWEROFF, "<<
723
- "current state is #{state_str()}, #{lcm_state_str()}")
724
- end
726
+ tid = self['TEMPLATE/TEMPLATE_ID']
727
+ if tid.nil? || tid.empty?
728
+ rc = Error.new('VM has no template to be saved')
729
+ raise
730
+ end
725
731
 
726
- # Clone the source template
727
- new_tid = OpenNebula::Template.new_with_id(tid, @client).clone(name)
728
- return new_tid if OpenNebula.is_error?(new_tid)
732
+ if state_str() != "POWEROFF"
733
+ rc = Error.new("VM state must be POWEROFF, "<<
734
+ "current state is #{state_str()}, #{lcm_state_str()}")
735
+ raise
736
+ end
729
737
 
730
- # Replace the original template's capacity with the actual VM values
731
- replace = ""
738
+ # Clone the source template
739
+ rc = OpenNebula::Template.new_with_id(tid, @client).clone(name)
740
+ raise if OpenNebula.is_error?(rc)
732
741
 
733
- cpu = self['TEMPLATE/CPU']
734
- if !cpu.nil? && !cpu.empty?
735
- replace << "CPU = #{cpu}\n"
736
- end
742
+ new_tid = rc
737
743
 
738
- vcpu = self['TEMPLATE/VCPU']
739
- if !vcpu.nil? && !vcpu.empty?
740
- replace << "VCPU = #{vcpu}\n"
741
- end
744
+ # Replace the original template's capacity with the actual VM values
745
+ replace = ""
742
746
 
743
- mem = self['TEMPLATE/MEMORY']
744
- if !mem.nil? && !mem.empty?
745
- replace << "MEMORY = #{mem}\n"
746
- end
747
+ cpu = self['TEMPLATE/CPU']
748
+ if !cpu.nil? && !cpu.empty?
749
+ replace << "CPU = #{cpu}\n"
750
+ end
747
751
 
748
- self.each('TEMPLATE/DISK') do |disk|
749
- # While the previous snapshot is still in progress, we wait
750
- # indefinitely
751
- rc = info()
752
- return rc if OpenNebula.is_error?(rc)
752
+ vcpu = self['TEMPLATE/VCPU']
753
+ if !vcpu.nil? && !vcpu.empty?
754
+ replace << "VCPU = #{vcpu}\n"
755
+ end
753
756
 
754
- steps = 0
755
- while lcm_state_str() == "HOTPLUG_SAVEAS_POWEROFF"
756
- if steps < 30
757
- sleep 1
758
- else
759
- sleep 15
760
- end
757
+ mem = self['TEMPLATE/MEMORY']
758
+ if !mem.nil? && !mem.empty?
759
+ replace << "MEMORY = #{mem}\n"
760
+ end
761
761
 
762
+ self.each('TEMPLATE/DISK') do |disk|
763
+ # While the previous snapshot is still in progress, we wait
764
+ # indefinitely
762
765
  rc = info()
763
- return rc if OpenNebula.is_error?(rc)
766
+ raise if OpenNebula.is_error?(rc)
764
767
 
765
- steps += 1
766
- end
768
+ steps = 0
769
+ while lcm_state_str() == "HOTPLUG_SAVEAS_POWEROFF"
770
+ if steps < 30
771
+ sleep 1
772
+ else
773
+ sleep 15
774
+ end
767
775
 
768
- # If the VM is not busy with a previous disk snapshot, we wait
769
- # but this time with a timeout
770
- rc = wait_state("POWEROFF")
771
- return rc if OpenNebula.is_error?(rc)
776
+ rc = info()
777
+ raise if OpenNebula.is_error?(rc)
772
778
 
773
- disk_id = disk["DISK_ID"]
774
- if disk_id.nil? || disk_id.empty?
775
- return Error.new('The DISK_ID is missing from the VM template')
776
- end
779
+ steps += 1
780
+ end
777
781
 
778
- image_id = disk["IMAGE_ID"]
782
+ # If the VM is not busy with a previous disk snapshot, we wait
783
+ # but this time with a timeout
784
+ rc = wait_state("POWEROFF")
785
+ raise if OpenNebula.is_error?(rc)
779
786
 
780
- if !image_id.nil? && !image_id.empty?
781
- rc = disk_saveas(disk_id.to_i,"#{name}-disk-#{disk_id}","",-1)
787
+ disk_id = disk["DISK_ID"]
788
+ if disk_id.nil? || disk_id.empty?
789
+ rc = Error.new('The DISK_ID is missing from the VM template')
790
+ raise
791
+ end
782
792
 
783
- return rc if OpenNebula.is_error?(rc)
793
+ image_id = disk["IMAGE_ID"]
784
794
 
785
- replace << "DISK = [ IMAGE_ID = #{rc} ]\n"
786
- else
787
- # Volatile disks cannot be saved, so the definition is copied
788
- replace << self.template_like_str(
789
- "TEMPLATE", true, "DISK[DISK_ID=#{disk_id}]") << "\n"
790
- end
791
- end
795
+ if !image_id.nil? && !image_id.empty?
796
+ rc = disk_saveas(disk_id.to_i,"#{name}-disk-#{disk_id}","",-1)
792
797
 
793
- self.each('TEMPLATE/NIC') do |nic|
794
- nic_id = nic["NIC_ID"]
795
- if nic_id.nil? || nic_id.empty?
796
- return Error.new('The NIC_ID is missing from the VM template')
798
+ raise if OpenNebula.is_error?(rc)
799
+
800
+ img_ids << rc.to_i
801
+
802
+ replace << "DISK = [ IMAGE_ID = #{rc} ]\n"
803
+ else
804
+ # Volatile disks cannot be saved, so the definition is copied
805
+ replace << self.template_like_str(
806
+ "TEMPLATE", true, "DISK[DISK_ID=#{disk_id}]") << "\n"
807
+ end
797
808
  end
798
809
 
799
- net_id = nic["NETWORK_ID"]
810
+ self.each('TEMPLATE/NIC') do |nic|
811
+ nic_id = nic["NIC_ID"]
812
+ if nic_id.nil? || nic_id.empty?
813
+ rc = Error.new('The NIC_ID is missing from the VM template')
814
+ raise
815
+ end
800
816
 
801
- if !net_id.nil? && !net_id.empty?
802
- replace << "NIC = [ NETWORK_ID = #{net_id} ]\n"
803
- else
804
- # This NIC does not use a Virtual Network
805
- replace << self.template_like_str(
806
- "TEMPLATE", true, "NIC[NIC_ID=#{nic_id}]") << "\n"
817
+ net_id = nic["NETWORK_ID"]
818
+
819
+ if !net_id.nil? && !net_id.empty?
820
+ replace << "NIC = [ NETWORK_ID = #{net_id} ]\n"
821
+ else
822
+ # This NIC does not use a Virtual Network
823
+ replace << self.template_like_str(
824
+ "TEMPLATE", true, "NIC[NIC_ID=#{nic_id}]") << "\n"
825
+ end
807
826
  end
808
- end
809
827
 
810
- # Required by the Sunstone Cloud View
811
- replace << "SAVED_TEMPLATE_ID = #{tid}\n"
828
+ # Required by the Sunstone Cloud View
829
+ replace << "SAVED_TEMPLATE_ID = #{tid}\n"
812
830
 
813
- new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client)
831
+ new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client)
814
832
 
815
- rc = new_tmpl.update(replace, true)
816
- return rc if OpenNebula.is_error?(rc)
833
+ rc = new_tmpl.update(replace, true)
834
+ raise if OpenNebula.is_error?(rc)
817
835
 
818
- return new_tid
836
+ return new_tid
819
837
 
820
- # TODO: rollback in case of error
838
+ rescue
839
+ # Rollback. Delete the template and the images created
840
+ if !new_tid.nil?
841
+ new_tmpl = OpenNebula::Template.new_with_id(new_tid, @client)
842
+ new_tmpl.delete()
843
+ end
844
+
845
+ img_ids.each do |id|
846
+ img = OpenNebula::Image.new_with_id(id, @client)
847
+ img.delete()
848
+ end
849
+
850
+ return rc
851
+ end
821
852
  end
822
853
 
823
854
  private
@@ -49,7 +49,7 @@ module OpenNebula
49
49
  # XML-RPC Methods for the Virtual Network Object
50
50
  #######################################################################
51
51
 
52
- # Retrieves all or part of the VirtualMachines in the pool.
52
+ # Retrieves all or part of the VirtualNetworks in the pool.
53
53
  def info(*args)
54
54
  case args.size
55
55
  when 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.13.80.beta1
4
+ version: 4.13.85.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - LICENSE
62
62
  - NOTICE
63
+ - lib/cloud/CloudClient.rb
63
64
  - lib/opennebula.rb
64
65
  - lib/opennebula/acl.rb
65
66
  - lib/opennebula/acl_pool.rb
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: 1.3.1
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.4.5
130
+ rubygems_version: 2.4.5.1
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: OpenNebula Client API