fog-ovirt 1.1.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b94675a38a2f78d4700f9c3a58ff1ee8a4c3e6a
4
- data.tar.gz: 6869fa8820faaffbcbd1c512de48ff507c8dd206
3
+ metadata.gz: 0db74060b4baf3e164228414dea50eee4b190456
4
+ data.tar.gz: 37ac7fce1061b02648cf17b1650f8266ab264a0f
5
5
  SHA512:
6
- metadata.gz: 3a5ee7eeb4f70938d3d9e7573bb73a9508d437bd212fb35cbc79e0a67e1c1d754ff0e6ee3beec06c51c1a12576374683a0797b56f65a0d241634217266ad393f
7
- data.tar.gz: 44655837e13b3fffb191eddee238f160d6809ed95cba4e8205561a423610349a4e5aa1fa249b7ca40f62808f09caf079897821273975464925548290e0a9eccc
6
+ metadata.gz: cc1bdbba0adf313e68d6e2278cb8d0bbe642f6ec5b708c7ed649e028c3202867394696418a36cee09958207d24c603765e91d40ab70cb1aac40c8bc2f659acf6
7
+ data.tar.gz: 9aa2938661ac3506c0f84e85de7fe1c1ca9914d5598dc85e7d2b32e3e1f6b2854a74e1313a400abf4f262a1dcb87bb1d9fff678acad3cf71f7bcfced78fdefb2
data/.rubocop_todo.yml CHANGED
@@ -14,7 +14,7 @@ Metrics/ClassLength:
14
14
  # Offense count: 2
15
15
  # Configuration parameters: CountComments.
16
16
  Metrics/MethodLength:
17
- Max: 25
17
+ Max: 30
18
18
 
19
19
  # Offense count: 1
20
20
  Style/ClassVars:
data/README.md CHANGED
@@ -38,6 +38,47 @@ compute = Fog::Compute.new(
38
38
  )
39
39
  ```
40
40
 
41
+ ## API Support
42
+
43
+ This gem fully supports API v3 of oVirt.
44
+
45
+ Version 1.0.2 adds support API V4 as well.
46
+ The first version does not give full support.
47
+ The supported requests for API V4 are:
48
+
49
+ :vm_action, :destroy_vm, :create_vm
50
+ :datacenters
51
+ :storage_domains
52
+ :list_virtual_machines, :get_virtual_machine
53
+ :list_templates, :get_template
54
+ :list_instance_types, :get_instance_type
55
+ :list_clusters, :get_cluster
56
+ :add_interface, :destroy_interface, :update_interface, :list_vm_interfaces, :list_template_interfaces
57
+ :list_networks
58
+ :vm_ticket
59
+ :list_vm_volumes, :list_template_volumes, :list_volumes, :add_volume, :destroy_volume, :update_volume
60
+ :get_api_version
61
+ :list_quotas, :get_quota
62
+ :list_operating_systems
63
+
64
+ ### Choosing api version
65
+
66
+ This example shows the usage as a fog provider:
67
+
68
+ client = Fog::Compute.new(
69
+ :provider => "ovirt",
70
+ :ovirt_username => user,
71
+ :ovirt_password => password,
72
+ :ovirt_url => url,
73
+ :ovirt_datacenter => datacenter,
74
+ :public_key => public_key,
75
+ :api_version => 'v4'
76
+ )
77
+ The :api_version can be sent 'v3' or 'v4' to determine which API version to use.
78
+
79
+
80
+ Feedback is welcome. Please feel free to open issues for the V4 support and contribute.
81
+
41
82
  ## Contributing
42
83
 
43
84
  Please refer to [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -8,8 +8,10 @@ module Fog
8
8
  request_path "fog/ovirt/requests/compute/v4"
9
9
 
10
10
  request :vm_action
11
+ request :vm_start_with_cloudinit
11
12
  request :destroy_vm
12
13
  request :create_vm
14
+ request :update_vm
13
15
  request :datacenters
14
16
  request :storage_domains
15
17
  request :list_virtual_machines
@@ -71,11 +73,17 @@ module Fog
71
73
  end
72
74
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73
75
 
74
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
76
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
75
77
  def get_attr_value(value, opts)
76
78
  case value
77
- when OvirtSDK4::TemplateVersion, Array, Hash, OvirtSDK4::List, OvirtSDK4::DataCenter
79
+ when OvirtSDK4::List
80
+ value.to_a
81
+ when Array, Hash, DateTime
78
82
  value
83
+ when OvirtSDK4::HighAvailability
84
+ opts[:ha] = value.enabled
85
+ when OvirtSDK4::TemplateVersion
86
+ OpenStruct.new(:version_name => value.version_name, :version_number => value.version_number)
79
87
  when OvirtSDK4::Mac
80
88
  value.address
81
89
  when OvirtSDK4::Cpu
@@ -92,10 +100,14 @@ module Fog
92
100
  :monitors => value.monitors
93
101
  }
94
102
  else
95
- value.to_s.strip
103
+ if value.class.respond_to?(:parent) && value.class.parent == OvirtSDK4
104
+ value.id if value.respond_to?(:id)
105
+ else
106
+ value.to_s.strip
107
+ end
96
108
  end
97
109
  end
98
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
110
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
99
111
  end
100
112
 
101
113
  class Mock
@@ -151,7 +163,15 @@ module Fog
151
163
  end
152
164
 
153
165
  def datacenter
154
- @datacenter ||= datacenters.first[:id]
166
+ @datacenter ||= datacenter_hash[:id]
167
+ end
168
+
169
+ def datacenter_hash
170
+ @datacenter_hash ||= datacenters.first
171
+ end
172
+
173
+ def blank_template
174
+ @blank_template ||= client.system_service.get.special_objects.blank_template
155
175
  end
156
176
 
157
177
  private
@@ -31,8 +31,9 @@ module Fog
31
31
  @client = client
32
32
  end
33
33
 
34
- # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
35
34
  def method_missing(symbol, *args)
35
+ super unless @client.respond_to?(symbol)
36
+
36
37
  if block_given?
37
38
  @client.__send__(symbol, *args) do |*block_args|
38
39
  yield(*block_args)
@@ -44,10 +45,9 @@ module Fog
44
45
  raise ::Fog::Ovirt::Errors::OvirtEngineError, e
45
46
  end
46
47
 
47
- def respond_to?(symbol, include_all = false)
48
- @client.respond_to?(symbol, include_all)
48
+ def respond_to_missing?(method_name, include_private = false)
49
+ @client.respond_to?(symbol, include_all) || super
49
50
  end
50
- # rubocop:enable Style/MethodMissingSuper, Style/MissingRespondToMissing
51
51
  end
52
52
 
53
53
  require "fog/ovirt/compute/v3"
@@ -27,9 +27,21 @@ module Fog
27
27
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
28
28
  def create_vm(attrs)
29
29
  attrs = attrs.dup
30
- attrs[:cluster_name] ||= datacenter.clusters.first.name unless attrs[:cluster]
30
+
31
+ if attrs[:cluster].present?
32
+ attrs[:cluster] = client.system_service.clusters_service.cluster_service(attrs[:cluster]).get
33
+ else
34
+ if attrs[:cluster_name].present?
35
+ cluster = client.system_service.clusters_service.list(:search => "name=#{attrs[:cluster_name]}").first
36
+ else
37
+ cluster = client.system_service.clusters_service.list(:search => "datacenter=#{datacenter_hash[:name]}").first
38
+ attrs[:cluster_name] = cluster.name
39
+ end
40
+
41
+ attrs[:cluster] = cluster
42
+ end
43
+
31
44
  vms_service = client.system_service.vms_service
32
- attrs[:cluster] = client.system_service.clusters_service.cluster_service(attrs[:cluster]).get
33
45
  attrs[:instance_type] = attrs[:instance_type].present? ? client.system_service.instance_types_service.instance_type_service(attrs[:instance_type]).get : nil
34
46
 
35
47
  attrs[:template] = if attrs[:template].present?
@@ -45,9 +57,7 @@ module Fog
45
57
  attrs[:cpu] = OvirtSDK4::Cpu.new(:topology => cpu_topology)
46
58
  end
47
59
 
48
- if attrs[:memory].to_i < Fog::Compute::Ovirt::DISK_SIZE_TO_GB
49
- attrs[:memory_policy] = OvirtSDK4::MemoryPolicy.new(:guaranteed => attrs[:memory])
50
- end
60
+ attrs[:memory_policy] = OvirtSDK4::MemoryPolicy.new(:guaranteed => attrs[:memory]) if attrs[:memory].to_i < Fog::Compute::Ovirt::DISK_SIZE_TO_GB
51
61
 
52
62
  # TODO: handle cloning from template
53
63
  process_vm_opts(attrs)
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ # rubocop:disable Metrics/AbcSize
7
+ def update_vm(attrs)
8
+ attrs = attrs.dup
9
+ vm_service = client.system_service.vms_service.vm_service(attrs[:id])
10
+
11
+ if attrs[:cores].present?
12
+ cpu_topology = OvirtSDK4::CpuTopology.new(:cores => attrs[:cores], :sockets => "1")
13
+ attrs[:cpu] = OvirtSDK4::Cpu.new(:topology => cpu_topology)
14
+ end
15
+ wrap_attribute(attrs, :cluster, OvirtSDK4::Cluster)
16
+ attrs[:template] = if attrs[:template].present?
17
+ OvirtSDK4::Template.new(:id => attrs[:template])
18
+ else
19
+ blank_template
20
+ end
21
+
22
+ wrap_attribute(attrs, :large_icon, OvirtSDK4::Icon)
23
+ wrap_attribute(attrs, :small_icon, OvirtSDK4::Icon)
24
+ wrap_attribute(attrs, :cpu_profile, OvirtSDK4::CpuProfile)
25
+ wrap_attribute(attrs, :host, OvirtSDK4::Host)
26
+ wrap_attribute(attrs, :quota, OvirtSDK4::Quota)
27
+ wrap_attribute(attrs, :instance_type, OvirtSDK4::InstanceType)
28
+ attrs[:high_availability] = OvirtSDK4::HighAvailability.new(:enabled => attrs[:ha]) unless attrs[:ha].nil?
29
+ attrs[:original_template] = if attrs[:original_template].present?
30
+ OvirtSDK4::Template.new(:id => attrs[:original_template])
31
+ else
32
+ blank_template
33
+ end
34
+ vm_service.update(attrs)
35
+ end
36
+ # rubocop:enable Metrics/AbcSize
37
+
38
+ def wrap_attribute(attrs, attribute, klass)
39
+ if attrs[attribute].present?
40
+ attrs[attribute] = klass.new(:id => attrs[attribute])
41
+ else
42
+ attrs.delete(attribute)
43
+ end
44
+ end
45
+ end
46
+
47
+ class Mock
48
+ def update_vm(_attrs)
49
+ xml = read_xml("vm.xml")
50
+ OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def vm_start_with_cloudinit(options = {})
7
+ raise ArgumentError, "instance id is a required parameter" unless options.key? :id
8
+
9
+ vm_service = client.system_service.vms_service.vm_service(options[:id])
10
+ vm_service.start(:use_cloud_init => true, :vm => { :initialization => options[:user_data] })
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def vm_start_with_cloudinit(options = {})
16
+ raise ArgumentError, "instance id is a required parameter" unless options.key? :id
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Ovirt
3
- VERSION = "1.1.0".freeze
3
+ VERSION = "1.1.1".freeze
4
4
  end
5
5
  end
data/lib/fog/ovirt.rb CHANGED
@@ -3,7 +3,7 @@ require "fog/xml"
3
3
 
4
4
  module Fog
5
5
  module Compute
6
- autoload :Ovirt, File.expand_path('../ovirt/compute', __FILE__)
6
+ autoload :Ovirt, File.expand_path("ovirt/compute", __dir__)
7
7
  end
8
8
 
9
9
  module Ovirt
@@ -17,7 +17,7 @@ Shindo.tests("Fog::Compute[:ovirt]", ["ovirt"]) do
17
17
  %w[ add_interface create_vm datacenters destroy_interface destroy_vm get_cluster get_template
18
18
  get_virtual_machine list_clusters list_networks list_template_interfaces list_templates
19
19
  list_virtual_machines list_vm_interfaces storage_domains update_interface update_vm vm_action
20
- api_version update_volume].each do |collection|
20
+ vm_start_with_cloudinit api_version update_volume].each do |collection|
21
21
  test("it should respond to #{collection}") { compute.respond_to? collection }
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-ovirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ori Rabin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-22 00:00:00.000000000 Z
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -297,8 +297,10 @@ files:
297
297
  - lib/fog/ovirt/requests/compute/v4/mock_files/volumes.xml
298
298
  - lib/fog/ovirt/requests/compute/v4/storage_domains.rb
299
299
  - lib/fog/ovirt/requests/compute/v4/update_interface.rb
300
+ - lib/fog/ovirt/requests/compute/v4/update_vm.rb
300
301
  - lib/fog/ovirt/requests/compute/v4/update_volume.rb
301
302
  - lib/fog/ovirt/requests/compute/v4/vm_action.rb
303
+ - lib/fog/ovirt/requests/compute/v4/vm_start_with_cloudinit.rb
302
304
  - lib/fog/ovirt/requests/compute/v4/vm_ticket.rb
303
305
  - lib/fog/ovirt/version.rb
304
306
  - spec/fog/bin/ovirt_spec.rb
@@ -352,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
354
  version: '0'
353
355
  requirements: []
354
356
  rubyforge_project:
355
- rubygems_version: 2.6.12
357
+ rubygems_version: 2.6.14
356
358
  signing_key:
357
359
  specification_version: 4
358
360
  summary: Module for the 'fog' gem to support Ovirt.