fog-ovirt 1.1.4 → 1.1.5

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: c1d12e8266299180109c82336ba2fa7f37ce393e
4
- data.tar.gz: 2146dbd84ec0c8edd03d2cb229431b9105307830
3
+ metadata.gz: 60c557f87df7eed11973b2d486df972d4eb6d5e9
4
+ data.tar.gz: 012c8b79e06089c60b939780a883c8cfadaddf5a
5
5
  SHA512:
6
- metadata.gz: efe0ea08f42a1d681644340608a9090d4b3b5cf2a2a331d2e885038833ec9d3dba06dab293c8922e5f4c6158f64f965d381465a08b42016d68d7c9cf07654569
7
- data.tar.gz: deb41a6dcd13f22e4e4f970cbc93e4205535c9cf47d559878f10cf387f7f751857a7d931e6d448ddd1238587e901d0f9ebd5820acc2bfc9b31954332d31af0a0
6
+ metadata.gz: a9a46e1b06e95bb0256d8b4eb4fdc22e1e5b6431f8e2bb321f73b6a51136ff80215683aec5c7fb5b391705b47d6a16235d2e21a67f0cfbd1523daec712f89057
7
+ data.tar.gz: c33adf408dd6f3d9cc8fe2fa80a2ef9ac0039b1146b52e88fac340170968c036fc834698f1c1c30ea467a2b1343e75fb87e319bad26d83cbbced077539f66238
data/lib/fog/ovirt.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "fog/core"
2
2
  require "fog/xml"
3
+ require "fog/json"
3
4
 
4
5
  module Fog
5
6
  module Compute
@@ -76,7 +76,7 @@ module Fog
76
76
  case value
77
77
  when OvirtSDK4::List
78
78
  value.to_a
79
- when Array, Hash, DateTime, TrueClass, FalseClass
79
+ when Array, Hash, DateTime
80
80
  value
81
81
  when OvirtSDK4::HighAvailability
82
82
  opts[:ha] = value.enabled
@@ -107,6 +107,21 @@ module Fog
107
107
  end
108
108
  end
109
109
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
110
+
111
+ def convert_string_to_bool(opts)
112
+ opts.each do |key, value|
113
+ if value == "true"
114
+ opts[key] = true
115
+ elsif value == "false"
116
+ opts[key] = false
117
+ elsif value.is_a? Hash
118
+ convert_string_to_bool(value)
119
+ elsif value.is_a? Array
120
+ value.map { |item| convert_string_to_bool(item) }
121
+ end
122
+ end
123
+ opts
124
+ end
110
125
  end
111
126
 
112
127
  class Mock
@@ -9,7 +9,7 @@ module Fog
9
9
  vm = client.system_service.vms_service.vm_service(id)
10
10
  nics_service = vm.nics_service
11
11
  options = options.dup
12
-
12
+ options = convert_string_to_bool(options)
13
13
  if options[:network].present?
14
14
  network = client.system_service.networks_service.network_service(options[:network]).get
15
15
 
@@ -13,32 +13,30 @@ module Fog
13
13
  disk_attachments_service.add(disk)
14
14
  end
15
15
 
16
- # rubocop:disable Metrics/AbcSize
16
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
17
17
  def add_options_defaults(options)
18
18
  options = options.dup
19
+ options = convert_string_to_bool(options)
19
20
  search = options[:search] || format("datacenter=%<datacenter>s", :datacenter => datacenter)
20
- options[:bootable] = options.delete(:bootable) == "true"
21
+ options[:bootable] = options.delete(:bootable)
21
22
  options[:interface] ||= OvirtSDK4::DiskInterface::VIRTIO
22
23
  options[:provisioned_size] = options[:size_gb].to_i * Fog::Compute::Ovirt::DISK_SIZE_TO_GB if options[:size_gb]
23
-
24
+ options[:sparse] = true if options[:sparse].nil?
24
25
  options[:storage_domain_id] = options[:storage_domain] || storagedomains(:role => "data", :search => search).first.id
25
26
  # If no size is given, default to a volume size of 8GB
26
27
  options[:provisioned_size] ||= 8 * Fog::Compute::Ovirt::DISK_SIZE_TO_GB
27
28
  options[:type] ||= OvirtSDK4::DiskType::DATA
28
29
  options[:format] ||= OvirtSDK4::DiskFormat::COW
29
-
30
- options[:sparse] = true unless options[:sparse].present?
31
30
  options[:quota] = options[:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(options[:quota]).get : nil
32
-
33
31
  options[:disk] ||= {}
32
+ options[:disk][:sparse] = options.delete(:sparse) if options[:disk][:sparse].nil?
34
33
  options[:disk][:storage_domains] ||= [client.system_service.storage_domains_service.storage_domain_service(options[:storage_domain_id]).get]
35
34
  options[:disk][:provisioned_size] ||= options.delete(:provisioned_size)
36
35
  options[:disk][:format] ||= options.delete(:format)
37
- options[:disk][:sparse] ||= options.delete(:sparse)
38
- options[:disk][:wipe_after_delete] ||= options.delete(:wipe_after_delete)
36
+ options[:disk][:wipe_after_delete] = options.delete(:wipe_after_delete) if options[:disk][:wipe_after_delete].nil?
39
37
  options
40
38
  end
41
- # rubocop:enable Metrics/AbcSize
39
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
42
40
  end
43
41
 
44
42
  class Mock
@@ -3,30 +3,28 @@ module Fog
3
3
  class Ovirt
4
4
  class V4
5
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")
6
+ def create_disk_attachment_from_disk(disk_to_attachment)
7
+ storage_domain = client.system_service.storage_domains_service.storage_domain_service(disk_to_attachment["storage_domain"]).get
13
8
 
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
9
+ disk = {
10
+ :id => disk_to_attachment["id"],
11
+ :format => disk_to_attachment.fetch("format", OvirtSDK4::DiskFormat::COW),
12
+ :sparse => disk_to_attachment.fetch("sparse", true),
13
+ :storage_domains => [storage_domain]
14
+ }
17
15
 
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 }
16
+ OvirtSDK4::DiskAttachment.new(:disk => disk)
17
+ end
21
18
 
22
- # Create disks map
23
- opts[:disks] = template_disks.collect { |d| { :id => d.id, :storagedomain => storagedomain_id } }
19
+ def process_vm_disks(opts)
20
+ opts[:disk_attachments] = opts[:disks].map { |disk| create_disk_attachment_from_disk(disk) }
21
+ opts.delete(:disks)
24
22
  end
25
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
26
23
 
27
24
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
28
25
  def create_vm(attrs)
29
26
  attrs = attrs.dup
27
+ attrs = convert_string_to_bool(attrs)
30
28
 
31
29
  if attrs[:cluster].present?
32
30
  attrs[:cluster] = client.system_service.clusters_service.cluster_service(attrs[:cluster]).get
@@ -60,10 +58,10 @@ module Fog
60
58
  attrs[:memory_policy] = OvirtSDK4::MemoryPolicy.new(:guaranteed => attrs[:memory]) if attrs[:memory].to_i < Fog::Compute::Ovirt::DISK_SIZE_TO_GB
61
59
  attrs[:high_availability] = OvirtSDK4::HighAvailability.new(:enabled => attrs[:ha] == "1") if attrs[:ha].present?
62
60
 
63
- # TODO: handle cloning from template
64
- process_vm_opts(attrs)
61
+ process_vm_disks(attrs) if attrs[:clone] == true && attrs[:disks].present?
62
+
65
63
  new_vm = OvirtSDK4::Vm.new(attrs)
66
- vms_service.add(new_vm)
64
+ vms_service.add(new_vm, :clone => attrs[:clone])
67
65
  end
68
66
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
69
67
 
@@ -13,6 +13,7 @@ module Fog
13
13
  extend ::Fog::Compute::Ovirt::V4::Shared
14
14
 
15
15
  def update_interface(id, options)
16
+ options = convert_string_to_bool(options)
16
17
  check_arguments(id, options)
17
18
 
18
19
  interface_id = options[:id]
@@ -6,6 +6,7 @@ module Fog
6
6
  # rubocop:disable Metrics/AbcSize
7
7
  def update_vm(attrs)
8
8
  attrs = attrs.dup
9
+ attrs = convert_string_to_bool(attrs)
9
10
  vm_service = client.system_service.vms_service.vm_service(attrs[:id])
10
11
 
11
12
  if attrs[:cores].present?
@@ -14,7 +14,7 @@ module Fog
14
14
 
15
15
  def update_volume(id, options)
16
16
  check_arguments(id, options)
17
-
17
+ options = convert_string_to_bool(options)
18
18
  disk_id = options[:id]
19
19
  disk_attachment = client.system_service.vms_service.vm_service(id).disk_attachments_service.attachment_service(disk_id)
20
20
  disk_attachment.update(disk_attachment, options)
@@ -4,6 +4,7 @@ module Fog
4
4
  class V4
5
5
  class Real
6
6
  def vm_ticket(id, options = {})
7
+ options = convert_string_to_bool(options)
7
8
  client.system_service.vms_service.vm_service(id).ticket(options).value
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Ovirt
3
- VERSION = "1.1.4".freeze
3
+ VERSION = "1.1.5".freeze
4
4
  end
5
5
  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.4
4
+ version: 1.1.5
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-12-09 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core