fog-ovirt 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +1 -1
  3. data/fog-ovirt.gemspec +1 -0
  4. data/lib/fog/ovirt/compute/v3.rb +1 -1
  5. data/lib/fog/ovirt/compute/v4.rb +163 -0
  6. data/lib/fog/ovirt/compute.rb +32 -11
  7. data/lib/fog/ovirt/requests/compute/v4/add_interface.rb +41 -0
  8. data/lib/fog/ovirt/requests/compute/v4/add_volume.rb +54 -0
  9. data/lib/fog/ovirt/requests/compute/v4/create_vm.rb +62 -0
  10. data/lib/fog/ovirt/requests/compute/v4/datacenters.rb +22 -0
  11. data/lib/fog/ovirt/requests/compute/v4/destroy_interface.rb +24 -0
  12. data/lib/fog/ovirt/requests/compute/v4/destroy_vm.rb +23 -0
  13. data/lib/fog/ovirt/requests/compute/v4/destroy_volume.rb +25 -0
  14. data/lib/fog/ovirt/requests/compute/v4/get_api_version.rb +18 -0
  15. data/lib/fog/ovirt/requests/compute/v4/get_cluster.rb +19 -0
  16. data/lib/fog/ovirt/requests/compute/v4/get_instance_type.rb +19 -0
  17. data/lib/fog/ovirt/requests/compute/v4/get_quota.rb +20 -0
  18. data/lib/fog/ovirt/requests/compute/v4/get_template.rb +19 -0
  19. data/lib/fog/ovirt/requests/compute/v4/get_virtual_machine.rb +19 -0
  20. data/lib/fog/ovirt/requests/compute/v4/list_clusters.rb +21 -0
  21. data/lib/fog/ovirt/requests/compute/v4/list_instance_types.rb +21 -0
  22. data/lib/fog/ovirt/requests/compute/v4/list_networks.rb +18 -0
  23. data/lib/fog/ovirt/requests/compute/v4/list_operating_systems.rb +21 -0
  24. data/lib/fog/ovirt/requests/compute/v4/list_quotas.rb +22 -0
  25. data/lib/fog/ovirt/requests/compute/v4/list_template_interfaces.rb +21 -0
  26. data/lib/fog/ovirt/requests/compute/v4/list_template_volumes.rb +27 -0
  27. data/lib/fog/ovirt/requests/compute/v4/list_templates.rb +21 -0
  28. data/lib/fog/ovirt/requests/compute/v4/list_virtual_machines.rb +28 -0
  29. data/lib/fog/ovirt/requests/compute/v4/list_vm_interfaces.rb +21 -0
  30. data/lib/fog/ovirt/requests/compute/v4/list_vm_volumes.rb +30 -0
  31. data/lib/fog/ovirt/requests/compute/v4/list_volumes.rb +21 -0
  32. data/lib/fog/ovirt/requests/compute/v4/mock_files/affinitygroup.xml +8 -0
  33. data/lib/fog/ovirt/requests/compute/v4/mock_files/affinitygroup_vms.xml +9 -0
  34. data/lib/fog/ovirt/requests/compute/v4/mock_files/affinitygroups.xml +17 -0
  35. data/lib/fog/ovirt/requests/compute/v4/mock_files/cluster.xml +27 -0
  36. data/lib/fog/ovirt/requests/compute/v4/mock_files/clusters.xml +53 -0
  37. data/lib/fog/ovirt/requests/compute/v4/mock_files/data_centers.xml +21 -0
  38. data/lib/fog/ovirt/requests/compute/v4/mock_files/disks.xml +54 -0
  39. data/lib/fog/ovirt/requests/compute/v4/mock_files/instance_type.xml +50 -0
  40. data/lib/fog/ovirt/requests/compute/v4/mock_files/instance_types.xml +233 -0
  41. data/lib/fog/ovirt/requests/compute/v4/mock_files/nics.xml +12 -0
  42. data/lib/fog/ovirt/requests/compute/v4/mock_files/operating_systems.xml +10 -0
  43. data/lib/fog/ovirt/requests/compute/v4/mock_files/quotas.xml +7 -0
  44. data/lib/fog/ovirt/requests/compute/v4/mock_files/storage_domains.xml +34 -0
  45. data/lib/fog/ovirt/requests/compute/v4/mock_files/template.xml +45 -0
  46. data/lib/fog/ovirt/requests/compute/v4/mock_files/templates.xml +128 -0
  47. data/lib/fog/ovirt/requests/compute/v4/mock_files/vm.xml +58 -0
  48. data/lib/fog/ovirt/requests/compute/v4/mock_files/vms.xml +170 -0
  49. data/lib/fog/ovirt/requests/compute/v4/mock_files/volumes.xml +36 -0
  50. data/lib/fog/ovirt/requests/compute/v4/storage_domains.rb +27 -0
  51. data/lib/fog/ovirt/requests/compute/v4/update_interface.rb +35 -0
  52. data/lib/fog/ovirt/requests/compute/v4/update_volume.rb +36 -0
  53. data/lib/fog/ovirt/requests/compute/v4/vm_action.rb +26 -0
  54. data/lib/fog/ovirt/requests/compute/v4/vm_ticket.rb +19 -0
  55. data/lib/fog/ovirt/version.rb +1 -1
  56. data/tests/ovirt/requests/compute/{client_tests.rb → v3/client_tests.rb} +0 -0
  57. data/tests/ovirt/requests/compute/{create_vm_tests.rb → v3/create_vm_tests.rb} +0 -0
  58. data/tests/ovirt/requests/compute/{destroy_vm_tests.rb → v3/destroy_vm_tests.rb} +0 -0
  59. data/tests/ovirt/requests/compute/{list_datacenters_tests.rb → v3/list_datacenters_tests.rb} +0 -0
  60. data/tests/ovirt/requests/compute/{list_quotas_tests.rb → v3/list_quotas_tests.rb} +0 -0
  61. data/tests/ovirt/requests/compute/{list_storage_domains_tests.rb → v3/list_storage_domains_tests.rb} +0 -0
  62. data/tests/ovirt/requests/compute/{update_vm_tests.rb → v3/update_vm_tests.rb} +0 -0
  63. data/tests/ovirt/requests/compute/{update_volume_tests.rb → v3/update_volume_tests.rb} +0 -0
  64. data/tests/ovirt/requests/compute/v4/client_tests.rb +31 -0
  65. data/tests/ovirt/requests/compute/v4/create_vm_tests.rb +17 -0
  66. data/tests/ovirt/requests/compute/v4/destroy_vm_tests.rb +16 -0
  67. data/tests/ovirt/requests/compute/v4/list_datacenters_tests.rb +11 -0
  68. data/tests/ovirt/requests/compute/v4/list_quotas_tests.rb +10 -0
  69. data/tests/ovirt/requests/compute/v4/list_storage_domains_tests.rb +11 -0
  70. data/tests/ovirt/requests/compute/v4/update_volume_tests.rb +17 -0
  71. metadata +96 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db39545b28114f4585da4d3a292c3657df5091df
4
- data.tar.gz: 89cb59e5f67129a8e78401b018086aac8c986b04
3
+ metadata.gz: bd8e9f9e8c862d91460d0f89a404e63f1a9aa22d
4
+ data.tar.gz: 30b9ad6857bd86479b48ee066fa8a3c1939f9722
5
5
  SHA512:
6
- metadata.gz: 43655aca8237ef76dd2d861bcc8ae400382e283012be06509bb0e13f6449aec980c57a8111da46319d7e67e455b08064b01b5fd64153556834bc4061dc5ae38e
7
- data.tar.gz: 1aa88959254782218a7c1f9dafe5383d2d60f8772f653fdbaa6f7fc73111ce33117942108b0d81c8e54841362a30e8199bbf1668c6e88841bdece60bf183e494
6
+ metadata.gz: '09bed3bc7ff912ab77167c48e69e2339b1d91c071ef5e410f87573ef9908e81cf53e6159bcd3b89484d22fdb969fc14b97ec83b713560ab7af14b8d268f8666f'
7
+ data.tar.gz: 3da84bbfa399997f07670f183dcb6ed8c6451078735eca74bddfe9a14a5d2bfe99095fbad6a0d4dfbc7f275c63b489ad7546f2a2e003d15c7afa44babc5294c9
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: 19
17
+ Max: 20
18
18
 
19
19
  # Offense count: 1
20
20
  Style/ClassVars:
data/fog-ovirt.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency("fog-core", "~> 1.45")
24
24
  spec.add_dependency("fog-json")
25
25
  spec.add_dependency("fog-xml", "~> 0.1.1")
26
+ spec.add_dependency("ovirt-engine-sdk", ">= 4.1.3")
26
27
  spec.add_dependency("rbovirt", "~> 0.1.5")
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -4,7 +4,7 @@ module Fog
4
4
  class V3 < Fog::Service
5
5
  requires :ovirt_username, :ovirt_password
6
6
  recognizes :ovirt_url, :ovirt_server, :ovirt_port, :ovirt_api_path, :ovirt_datacenter,
7
- :ovirt_filtered_api,
7
+ :ovirt_filtered_api, :public_key, :api_version,
8
8
  :ovirt_ca_cert_store, :ovirt_ca_cert_file, :ovirt_ca_no_verify
9
9
  request_path "fog/ovirt/requests/compute/v3"
10
10
 
@@ -0,0 +1,163 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4 < Fog::Service
5
+ requires :ovirt_username, :ovirt_password
6
+ recognizes :ovirt_url, :ovirt_server, :ovirt_port, :ovirt_api_path, :ovirt_datacenter,
7
+ :ca_file, :public_key, :api_version, :ovirt_ca_cert_store
8
+ request_path "fog/ovirt/requests/compute/v4"
9
+
10
+ request :vm_action
11
+ request :destroy_vm
12
+ request :create_vm
13
+ request :datacenters
14
+ request :storage_domains
15
+ request :list_virtual_machines
16
+ request :get_virtual_machine
17
+ request :list_templates
18
+ request :get_template
19
+ request :list_instance_types
20
+ request :get_instance_type
21
+ request :list_clusters
22
+ request :get_cluster
23
+ request :add_interface
24
+ request :destroy_interface
25
+ request :update_interface
26
+ request :list_vm_interfaces
27
+ request :list_template_interfaces
28
+ request :list_networks
29
+ request :vm_ticket
30
+ request :list_vm_volumes
31
+ request :list_template_volumes
32
+ request :list_volumes
33
+ request :add_volume
34
+ request :destroy_volume
35
+ request :update_volume
36
+ request :get_api_version
37
+ request :list_quotas
38
+ request :get_quota
39
+ request :list_operating_systems
40
+
41
+ module Shared
42
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
43
+ # converts an OVIRT object into an hash for fog to consume.
44
+ def ovirt_attrs(obj)
45
+ opts = {}
46
+ # TODO: stop using instance_variables, they will change
47
+ obj.instance_variables.each do |v|
48
+ key = v.to_s.delete("@").to_sym
49
+ value = obj.instance_variable_get(v)
50
+
51
+ if key == :network
52
+ opts[key] = client.follow_link(obj.vnic_profile).network.id
53
+ next
54
+ end
55
+
56
+ if key == :provisioned_size
57
+ opts[:size] = value
58
+ next
59
+ end
60
+
61
+ # ignore nil values
62
+ next if value.nil?
63
+
64
+ if key != :data_center && value.respond_to?(:href) && value.href && value.respond_to?(:id)
65
+ opts[key] = value.id
66
+ end
67
+
68
+ opts[key] ||= get_attr_value(value, opts)
69
+ end
70
+ opts
71
+ end
72
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73
+
74
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
75
+ def get_attr_value(value, opts)
76
+ case value
77
+ when OvirtSDK4::TemplateVersion, Array, Hash, OvirtSDK4::List, OvirtSDK4::DataCenter
78
+ value
79
+ when OvirtSDK4::Mac
80
+ value.address
81
+ when OvirtSDK4::Cpu
82
+ opts[:cores] = value.topology.nil? ? nil : value.topology.cores
83
+ when OvirtSDK4::Display
84
+ subject = value.certificate.subject if value.certificate
85
+ {
86
+ :type => value.type,
87
+ :address => value.address,
88
+ :port => value.port,
89
+ :secure_port => value.secure_port,
90
+ :subject => subject,
91
+ :monitors => value.monitors
92
+ }
93
+ else
94
+ value.to_s.strip
95
+ end
96
+ end
97
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
98
+ end
99
+
100
+ class Mock
101
+ include Shared
102
+
103
+ def initialize(_options = {})
104
+ require "ovirtsdk4"
105
+ end
106
+
107
+ private
108
+
109
+ def client
110
+ return @client if defined?(@client)
111
+ end
112
+
113
+ # read mocks xml
114
+ def read_xml(file_name)
115
+ file_path = File.join(__dir__, "../requests", "compute/v4", "mock_files", file_name)
116
+ File.read(file_path)
117
+ end
118
+ end
119
+
120
+ class Real
121
+ include Shared
122
+
123
+ # rubocop:disable Metrics/AbcSize
124
+ def initialize(options = {})
125
+ require "ovirtsdk4"
126
+ username = options[:ovirt_username]
127
+ password = options[:ovirt_password]
128
+ server = options[:ovirt_server]
129
+ port = options[:ovirt_port] || 8080
130
+ api_path = options[:ovirt_api_path] || "/api"
131
+ url = options[:ovirt_url] || "https://#{server}:#{port}#{api_path}"
132
+
133
+ connection_opts = {
134
+ :url => url,
135
+ :username => username,
136
+ :password => password
137
+ }
138
+
139
+ @datacenter = options[:ovirt_datacenter]
140
+ connection_opts[:ca_file] = options[:ca_file]
141
+ connection_opts[:ca_certs] = [OpenSSL::X509::Certificate.new(options[:public_key])] if options[:public_key].present?
142
+
143
+ @client = ExceptionWrapper.new(OvirtSDK4::Connection.new(connection_opts))
144
+ end
145
+ # rubocop:enable Metrics/AbcSize
146
+
147
+ def api_version
148
+ api = client.system_service.get
149
+ api.product_info.version.full_version
150
+ end
151
+
152
+ def datacenter
153
+ @datacenter ||= datacenters.first.id
154
+ end
155
+
156
+ private
157
+
158
+ attr_reader :client
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -3,6 +3,9 @@ require "fog/ovirt/core"
3
3
  module Fog
4
4
  module Compute
5
5
  class Ovirt < Fog::Service
6
+ recognizes :api_version, :ovirt_username, :ovirt_password, :ovirt_url,
7
+ :ovirt_datacenter, :ovirt_ca_cert_store, :public_key
8
+
6
9
  model_path "fog/ovirt/models/compute"
7
10
  model :server
8
11
  collection :servers
@@ -31,13 +34,13 @@ module Fog
31
34
  # rubocop:disable Style/MethodMissing
32
35
  def method_missing(symbol, *args)
33
36
  if block_given?
34
- @client.send(symbol, *args) do |*block_args|
37
+ @client.__send__(symbol, *args) do |*block_args|
35
38
  yield(*block_args)
36
39
  end
37
40
  else
38
- @client.send(symbol, *args)
41
+ @client.__send__(symbol, *args)
39
42
  end
40
- rescue ::OVIRT::OvirtException => e
43
+ rescue StandardError => e
41
44
  raise ::Fog::Ovirt::Errors::OvirtEngineError, e
42
45
  end
43
46
 
@@ -48,15 +51,23 @@ module Fog
48
51
  end
49
52
 
50
53
  require "fog/ovirt/compute/v3"
54
+ require "fog/ovirt/compute/v4"
51
55
 
52
56
  def self.new(options = {})
53
- super()
54
- @client = Fog::Compute::Ovirt::V3.new(options)
57
+ super(options)
58
+
59
+ # rubocop:disable Style/ConditionalAssignment
60
+ if options[:api_version] == "v4"
61
+ @client = Fog::Compute::Ovirt::V4.new(options)
62
+ else
63
+ @client = Fog::Compute::Ovirt::V3.new(options)
64
+ end
65
+ # rubocop:enable Style/ConditionalAssignment
55
66
  end
56
67
 
57
68
  # rubocop:disable Style/MethodMissing
58
69
  def method_missing(symbol, *args)
59
- @client.send(symbol, *args)
70
+ @client.__send__(symbol, *args)
60
71
  end
61
72
 
62
73
  def respond_to?(symbol, include_all = false)
@@ -66,13 +77,18 @@ module Fog
66
77
 
67
78
  class Mock
68
79
  def initialize(options = {})
69
- Fog::Compute::Ovirt::V3::Mock.send(:include, Fog::Compute::Ovirt::Collections)
70
- @client = Fog::Compute::Ovirt::V3::Mock.new(options)
80
+ if options[:api_version] == "v4"
81
+ Fog::Compute::Ovirt::V4::Mock.send(:include, Fog::Compute::Ovirt::Collections)
82
+ @client = Fog::Compute::Ovirt::V4::Mock.new(options)
83
+ else
84
+ Fog::Compute::Ovirt::V3::Mock.send(:include, Fog::Compute::Ovirt::Collections)
85
+ @client = Fog::Compute::Ovirt::V3::Mock.new(options)
86
+ end
71
87
  end
72
88
 
73
89
  # rubocop:disable Style/MethodMissing
74
90
  def method_missing(symbol, *args)
75
- @client.send(symbol, *args)
91
+ @client.__send__(symbol, *args)
76
92
  end
77
93
 
78
94
  def respond_to?(symbol, include_all = false)
@@ -83,8 +99,13 @@ module Fog
83
99
 
84
100
  class Real
85
101
  def initialize(options = {})
86
- Fog::Compute::Ovirt::V3::Real.send(:include, Fog::Compute::Ovirt::Collections)
87
- @client = Fog::Compute::Ovirt::V3::Real.new(options)
102
+ if options[:api_version] == "v4"
103
+ Fog::Compute::Ovirt::V4::Real.send(:include, Fog::Compute::Ovirt::Collections)
104
+ @client = Fog::Compute::Ovirt::V4::Real.new(options)
105
+ else
106
+ Fog::Compute::Ovirt::V3::Real.send(:include, Fog::Compute::Ovirt::Collections)
107
+ @client = Fog::Compute::Ovirt::V3::Real.new(options)
108
+ end
88
109
  end
89
110
 
90
111
  # rubocop:disable Style/MethodMissing
@@ -0,0 +1,41 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ # rubocop:disable Metrics/AbcSize
7
+ def add_interface(id, options = {})
8
+ raise ArgumentError, "instance id is a required parameter" unless id
9
+ vm = client.system_service.vms_service.vm_service(id)
10
+ nics_service = vm.nics_service
11
+ options = options.dup
12
+
13
+ if options[:network].present?
14
+ network = client.system_service.networks_service.network_service(options[:network]).get
15
+
16
+ profiles = client.follow_link(network.vnic_profiles)
17
+
18
+ profile = profiles.detect { |x| x.name == network.name }
19
+
20
+ profile ||= profiles.sort_by(&:name).first
21
+
22
+ options.delete(:network)
23
+ options[:vnic_profile] = { :id => profile.id }
24
+ end
25
+
26
+ interface = OvirtSDK4::Nic.new(options)
27
+ nics_service.add(interface)
28
+ end
29
+ # rubocop:enable Metrics/AbcSize
30
+ end
31
+
32
+ class Mock
33
+ def add_interface(id, _options = {})
34
+ raise ArgumentError, "instance id is a required parameter" unless id
35
+ true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ DISK_SIZE_TO_GB = 1024 * 1024 * 1024
7
+
8
+ def add_volume(id, options = {})
9
+ raise ArgumentError, "instance id is a required parameter" unless id
10
+
11
+ options = add_options_defaults(options)
12
+
13
+ disk_attachments_service = client.system_service.vms_service.vm_service(id).disk_attachments_service
14
+ disk = OvirtSDK4::DiskAttachment.new(options)
15
+ disk_attachments_service.add(disk)
16
+ end
17
+
18
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
19
+ def add_options_defaults(options)
20
+ options = options.dup
21
+ search = options[:search] || format("datacenter=%<datacenter>s", :datacenter => datacenter)
22
+ options[:bootable] ||= "true"
23
+ options[:interface] ||= OvirtSDK4::DiskInterface::VIRTIO
24
+ options[:provisioned_size] = options[:size_gb].to_i * DISK_SIZE_TO_GB if options[:size_gb]
25
+
26
+ options[:storage_domain_id] = options[:storage_domain] || storagedomains(:role => "data", :search => search).first.id
27
+ # If no size is given, default to a volume size of 8GB
28
+ options[:provisioned_size] ||= 8 * DISK_SIZE_TO_GB
29
+ options[:type] ||= OvirtSDK4::DiskType::DATA
30
+ options[:format] ||= OvirtSDK4::DiskFormat::COW
31
+ options[:sparse] = true unless options[:sparse].present?
32
+ options[:quota] = options[:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(options[:quota]).get : nil
33
+
34
+ options[:disk] ||= {}
35
+ options[:disk][:storage_domains] ||= [client.system_service.storage_domains_service.storage_domain_service(options[:storage_domain_id]).get]
36
+ options[:disk][:provisioned_size] ||= options.delete(:provisioned_size)
37
+ options[:disk][:type] ||= options.delete(:type)
38
+ options[:disk][:format] ||= options.delete(:format)
39
+ options[:disk][:sparse] = options.delete(:sparse) unless options[:disk][:sparse].present?
40
+ options
41
+ end
42
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
43
+ end
44
+
45
+ class Mock
46
+ def add_volume(id, _options = {})
47
+ raise ArgumentError, "instance id is a required parameter" unless id
48
+ true
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,62 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def check_for_option(opts, name)
7
+ opts[name.to_sym] || opts[(name + "_name").to_sym]
8
+ end
9
+
10
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
11
+ def process_vm_opts(opts)
12
+ return unless check_for_option(opts, "template") && check_for_option(opts, "storagedomain")
13
+
14
+ template_id = opts[:template] || client.system_service.templates_service.search(:name => opts[:template_name]).first.id
15
+ template_disks = client.system_service.templates_service.template_service(template_id).get.disk_attachments
16
+ storagedomain_id = opts[:storagedomain] || storagedomains.select { |s| s.name == opts[:storagedomain_name] }.first.id
17
+
18
+ # Make sure the 'clone' option is set if any of the disks defined by
19
+ # the template is stored on a different storage domain than requested
20
+ opts[:clone] = true unless opts[:clone] == true || template_disks.empty? || template_disks.all? { |d| d.storage_domain == storagedomain_id }
21
+
22
+ # Create disks map
23
+ opts[:disks] = template_disks.collect { |d| { :id => d.id, :storagedomain => storagedomain_id } }
24
+ end
25
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
26
+
27
+ # rubocop:disable Metrics/AbcSize
28
+ def create_vm(attrs)
29
+ attrs = attrs.dup
30
+ attrs[:cluster_name] ||= datacenter.clusters.first.name unless attrs[:cluster]
31
+ vms_service = client.system_service.vms_service
32
+ attrs[:cluster] = client.system_service.clusters_service.cluster_service(attrs[:cluster]).get
33
+ attrs[:instance_type] = attrs[:instance_type].present? ? client.system_service.instance_types_service.instance_type_service(attrs[:instance_type]).get : nil
34
+
35
+ attrs[:template] = if attrs[:template].present?
36
+ client.system_service.templates_service.template_service(attrs[:template]).get
37
+ else
38
+ client.system_service.get.special_objects.blank_template
39
+ end
40
+
41
+ attrs[:comment] ||= ""
42
+ attrs[:quota] = attrs[:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(attrs[:quota]).get : nil
43
+
44
+ # TODO: handle cloning from template
45
+ process_vm_opts(attrs)
46
+
47
+ new_vm = OvirtSDK4::Vm.new(attrs)
48
+ vms_service.add(new_vm)
49
+ end
50
+ # rubocop:enable Metrics/AbcSize
51
+ end
52
+
53
+ class Mock
54
+ def create_vm(_attrs)
55
+ xml = read_xml("vm.xml")
56
+ OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def datacenters(filter = {})
7
+ client.system_service.data_centers_service.list(filter).map { |ovirt_obj| ovirt_attrs ovirt_obj }
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def datacenters(_filters = {})
13
+ xml = read_xml "data_centers.xml"
14
+ Nokogiri::XML(xml).xpath("/data_centers/data_center").map do |dc|
15
+ ovirt_attrs OvirtSDK4::Reader.read(dc.to_s)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def destroy_interface(id, options)
7
+ raise ArgumentError, "instance id is a required parameter" unless id
8
+ raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.key? :id
9
+ vm = client.system_service.vms_service.vm_service(id)
10
+ vm.nics_service.nic_service(options[:id]).remove
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def destroy_interface(id, options)
16
+ raise ArgumentError, "instance id is a required parameter" unless id
17
+ raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.key? :id
18
+ true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def destroy_vm(options = {})
7
+ raise ArgumentError, "instance id is a required parameter" unless options.key? :id
8
+
9
+ client.system_service.vms_service.vm_service(options[:id]).remove
10
+ true
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def destroy_vm(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
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def destroy_volume(id, options)
7
+ raise ArgumentError, "instance id is a required parameter" unless id
8
+ raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.key? :id
9
+
10
+ disks_service = client.system_service.disks_service
11
+ disks_service.disk_service(options[:id]).remove
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def destroy_volume(id, options)
17
+ raise ArgumentError, "instance id is a required parameter" unless id
18
+ raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.key? :id
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def api_version
7
+ "4.0"
8
+ end
9
+ end
10
+ class Mock
11
+ def api_version
12
+ "4.0"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def get_cluster(id)
7
+ ovirt_attrs client.system_service.clusters_service.cluster_service(id).get
8
+ end
9
+ end
10
+ class Mock
11
+ def get_cluster(_id)
12
+ xml = read_xml("cluster.xml")
13
+ ovirt_attrs OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def get_instance_type(id)
7
+ ovirt_attrs client.system_service.instance_types_service.instance_type_service(id).get
8
+ end
9
+ end
10
+ class Mock
11
+ def get_instance_type(_id)
12
+ xml = read_xml "instance_type.xml"
13
+ ovirt_attrs OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def get_quota(id)
7
+ quota = client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(id).get
8
+ ovirt_attrs quota
9
+ end
10
+ end
11
+ class Mock
12
+ def get_quota(_id)
13
+ xml = read_xml("quota.xml")
14
+ ovirt_attrs OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def get_template(id)
7
+ ovirt_attrs client.system_service.templates_service.template_service(id).get
8
+ end
9
+ end
10
+ class Mock
11
+ def get_template(_id)
12
+ xml = read_xml "template.xml"
13
+ ovirt_attrs OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Ovirt
4
+ class V4
5
+ class Real
6
+ def get_virtual_machine(id)
7
+ ovirt_attrs client.system_service.vms_service.vm_service(id).get
8
+ end
9
+ end
10
+ class Mock
11
+ def get_virtual_machine(_id)
12
+ xml = read_xml "vm.xml"
13
+ ovirt_attrs OvirtSDK4::Reader.read(Nokogiri::XML(xml).root.to_s)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end