Class: Fog::Ovirt::Compute::V4::Real

Inherits:
Object
  • Object
show all
Extended by:
Shared
Includes:
Shared
Defined in:
lib/fog/ovirt/compute/v4.rb,
lib/fog/ovirt/requests/compute/v4/create_vm.rb,
lib/fog/ovirt/requests/compute/v4/get_quota.rb,
lib/fog/ovirt/requests/compute/v4/update_vm.rb,
lib/fog/ovirt/requests/compute/v4/vm_action.rb,
lib/fog/ovirt/requests/compute/v4/vm_ticket.rb,
lib/fog/ovirt/requests/compute/v4/add_volume.rb,
lib/fog/ovirt/requests/compute/v4/destroy_vm.rb,
lib/fog/ovirt/requests/compute/v4/get_volume.rb,
lib/fog/ovirt/requests/compute/v4/datacenters.rb,
lib/fog/ovirt/requests/compute/v4/get_cluster.rb,
lib/fog/ovirt/requests/compute/v4/list_quotas.rb,
lib/fog/ovirt/requests/compute/v4/get_template.rb,
lib/fog/ovirt/requests/compute/v4/list_volumes.rb,
lib/fog/ovirt/requests/compute/v4/add_interface.rb,
lib/fog/ovirt/requests/compute/v4/list_clusters.rb,
lib/fog/ovirt/requests/compute/v4/list_networks.rb,
lib/fog/ovirt/requests/compute/v4/update_volume.rb,
lib/fog/ovirt/requests/compute/v4/destroy_volume.rb,
lib/fog/ovirt/requests/compute/v4/list_templates.rb,
lib/fog/ovirt/requests/compute/v4/get_api_version.rb,
lib/fog/ovirt/requests/compute/v4/list_vm_volumes.rb,
lib/fog/ovirt/requests/compute/v4/storage_domains.rb,
lib/fog/ovirt/requests/compute/v4/update_interface.rb,
lib/fog/ovirt/requests/compute/v4/destroy_interface.rb,
lib/fog/ovirt/requests/compute/v4/get_instance_type.rb,
lib/fog/ovirt/requests/compute/v4/list_vm_interfaces.rb,
lib/fog/ovirt/requests/compute/v4/get_virtual_machine.rb,
lib/fog/ovirt/requests/compute/v4/list_instance_types.rb,
lib/fog/ovirt/requests/compute/v4/list_template_volumes.rb,
lib/fog/ovirt/requests/compute/v4/list_virtual_machines.rb,
lib/fog/ovirt/requests/compute/v4/list_operating_systems.rb,
lib/fog/ovirt/requests/compute/v4/vm_start_with_cloudinit.rb,
lib/fog/ovirt/requests/compute/v4/list_template_interfaces.rb

Instance Method Summary collapse

Methods included from Shared

check_arguments, convert_string_to_bool, get_attr_value, shared_ovirt_attrs

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/fog/ovirt/compute/v4.rb', line 168

def initialize(options = {})
  require "ovirtsdk4"
  username   = options[:ovirt_username]
  password   = options[:ovirt_password]
  server     = options[:ovirt_server]
  port       = options[:ovirt_port]       || 8080
  api_path   = options[:ovirt_api_path]   || "/api"
  url        = options[:ovirt_url]        || "https://#{server}:#{port}#{api_path}"

  connection_opts = {
    :url => url,
    :username => username,
    :password => password
  }
  @datacenter = options[:ovirt_datacenter]
  connection_opts[:ca_file]  = options[:ca_file]
  connection_opts[:ca_certs] = [OpenSSL::X509::Certificate.new(options[:public_key])] if options[:public_key].present?

  @client = ExceptionWrapper.new(OvirtSDK4::Connection.new(connection_opts))
end

Instance Method Details

#add_interface(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/ovirt/requests/compute/v4/add_interface.rb', line 6

def add_interface(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id
  vm = client.system_service.vms_service.vm_service(id)
  nics_service = vm.nics_service
  options = options.dup
  options = convert_string_to_bool(options)
  if options[:network].present?
    network = client.system_service.networks_service.network_service(options[:network]).get

    profiles = client.follow_link(network.vnic_profiles)

    profile = profiles.detect { |x| x.name == network.name }

    profile ||= profiles.min_by(&:name)

    options.delete(:network)
    options[:vnic_profile] = { :id => profile.id }
  end

  interface = OvirtSDK4::Nic.new(options)
  nics_service.add(interface)
end

#add_options_defaults(options) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/ovirt/requests/compute/v4/add_volume.rb', line 17

def add_options_defaults(options)
  options = options.dup
  options = convert_string_to_bool(options)
  options[:bootable] = options.delete(:bootable)
  options[:interface] ||= OvirtSDK4::DiskInterface::VIRTIO
  options[:provisioned_size] = options[:size_gb].to_i * Fog::Ovirt::Compute::DISK_SIZE_TO_GB if options[:size_gb]
  options[:sparse] = true if options[:sparse].nil?
  options[:storage_domain_id] = options[:storage_domain] if options[:storage_domain]
  # If no size is given, default to a volume size of 8GB
  options[:provisioned_size] ||= 8 * Fog::Ovirt::Compute::DISK_SIZE_TO_GB
  options[:type] ||= OvirtSDK4::DiskType::DATA
  options[:format] ||= OvirtSDK4::DiskFormat::COW
  options[:quota] = options[:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(options[:quota]).get : nil
  options[:disk] ||= {}
  options[:disk][:sparse] = options.delete(:sparse) if options[:disk][:sparse].nil?
  options[:disk][:storage_domains] ||= [client.system_service.storage_domains_service.storage_domain_service(options[:storage_domain_id]).get] if options[:storage_domain_id]
  options[:disk][:provisioned_size] ||= options.delete(:provisioned_size)
  options[:disk][:format] ||= options.delete(:format)
  options[:disk][:wipe_after_delete] = options.delete(:wipe_after_delete) if options[:disk][:wipe_after_delete].nil?
  options
end

#add_volume(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/fog/ovirt/requests/compute/v4/add_volume.rb', line 6

def add_volume(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id

  options = add_options_defaults(options)

  disk_attachments_service = client.system_service.vms_service.vm_service(id).disk_attachments_service
  disk = OvirtSDK4::DiskAttachment.new(options)
  disk_attachments_service.add(disk)
end

#api_versionObject



195
196
197
198
# File 'lib/fog/ovirt/compute/v4.rb', line 195

def api_version
  api = client.system_service.get
  api.product_info.version.full_version
end

#blank_templateObject



209
210
211
# File 'lib/fog/ovirt/compute/v4.rb', line 209

def blank_template
  @blank_template ||= client.system_service.get.special_objects.blank_template
end

#create_disk_attachment_from_disk(disk_to_attachment) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/ovirt/requests/compute/v4/create_vm.rb', line 6

def create_disk_attachment_from_disk(disk_to_attachment)
  storage_domain = client.system_service.storage_domains_service.storage_domain_service(disk_to_attachment["storage_domain"]).get

  disk = {
    :id => disk_to_attachment["id"],
    :format => disk_to_attachment.fetch("format", OvirtSDK4::DiskFormat::COW),
    :sparse => disk_to_attachment.fetch("sparse", true),
    :storage_domains => [storage_domain]
  }

  OvirtSDK4::DiskAttachment.new(:disk => disk)
end

#create_search_by_datacenter(search:, datacenter:, page: nil) ⇒ Object



213
214
215
216
217
218
# File 'lib/fog/ovirt/compute/v4.rb', line 213

def create_search_by_datacenter(search:, datacenter:, page: nil)
  search ||= ""
  search += " datacenter=#{datacenter}" if datacenter
  search += " page #{page}" if page
  search
end

#create_vm(attrs) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/ovirt/requests/compute/v4/create_vm.rb', line 25

def create_vm(attrs)
  attrs = attrs.dup
  attrs = convert_string_to_bool(attrs)

  if attrs[:cluster].present?
    attrs[:cluster] = client.system_service.clusters_service.cluster_service(attrs[:cluster]).get
  else
    if attrs[:cluster_name].present?
      cluster = client.system_service.clusters_service.list(:search => "name=#{attrs[:cluster_name]}").first
    else
      cluster = client.system_service.clusters_service.list(:search => "datacenter=#{datacenter_hash[:name]}").first
      attrs[:cluster_name] = cluster.name
    end

    attrs[:cluster] = cluster
  end

  vms_service = client.system_service.vms_service

  attrs[:type] = attrs.fetch(:type, OvirtSDK4::VmType::SERVER)
  attrs[:instance_type] = attrs[:instance_type].present? ? client.system_service.instance_types_service.instance_type_service(attrs[:instance_type]).get : nil

  if attrs[:template].present?
    attrs[:template] = client.system_service.templates_service.template_service(attrs[:template]).get
  else
    attrs[:template] = client.system_service.get.special_objects.blank_template
    update_os_attrs(attrs)
  end

  attrs[:comment] ||= ""
  attrs[:quota] = attrs[:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(attrs[:quota]).get : nil
  if attrs[:cores].present? || attrs[:sockets].present?
    cpu_topology = OvirtSDK4::CpuTopology.new(:cores => attrs.fetch(:cores, "1"), :sockets => attrs.fetch(:sockets, "1"))
    attrs[:cpu] = OvirtSDK4::Cpu.new(:topology => cpu_topology)
  end
  attrs[:memory_policy] = OvirtSDK4::MemoryPolicy.new(:guaranteed => attrs[:memory]) if attrs[:memory].to_i < Fog::Ovirt::Compute::DISK_SIZE_TO_GB
  attrs[:high_availability] = OvirtSDK4::HighAvailability.new(:enabled => attrs[:ha] == "1") if attrs[:ha].present?

  process_vm_disks(attrs) if attrs[:clone] == true && attrs[:disks].present?

  new_vm = OvirtSDK4::Vm.new(attrs)
  vms_service.add(new_vm, :clone => attrs[:clone])
end

#datacenterObject



200
201
202
# File 'lib/fog/ovirt/compute/v4.rb', line 200

def datacenter
  datacenter_hash[:id]
end

#datacenter_hashObject



204
205
206
207
# File 'lib/fog/ovirt/compute/v4.rb', line 204

def datacenter_hash
  @datacenter_hash ||= datacenters.find { |x| x[:id] == @datacenter } || datacenters.find { |x| x[:name] == @datacenter } if @datacenter
  @datacenter_hash ||= datacenters.first
end

#datacenters(filter = {}) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/datacenters.rb', line 6

def datacenters(filter = {})
  client.system_service.data_centers_service.list(filter).map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#destroy_interface(id, options) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/fog/ovirt/requests/compute/v4/destroy_interface.rb', line 6

def destroy_interface(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.key? :id
  vm = client.system_service.vms_service.vm_service(id)
  vm.nics_service.nic_service(options[:id]).remove
end

#destroy_vm(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/fog/ovirt/requests/compute/v4/destroy_vm.rb', line 6

def destroy_vm(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id

  client.system_service.vms_service.vm_service(options[:id]).remove
  true
end

#destroy_volume(id, options) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
# File 'lib/fog/ovirt/requests/compute/v4/destroy_volume.rb', line 6

def destroy_volume(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.key? :id

  disks_service = client.system_service.disks_service
  disks_service.disk_service(options[:id]).remove
end

#get_cluster(id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/get_cluster.rb', line 6

def get_cluster(id)
  ovirt_attrs client.system_service.clusters_service.cluster_service(id).get
end

#get_instance_type(id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/get_instance_type.rb', line 6

def get_instance_type(id)
  ovirt_attrs client.system_service.instance_types_service.instance_type_service(id).get
end

#get_quota(id) ⇒ Object



6
7
8
9
# File 'lib/fog/ovirt/requests/compute/v4/get_quota.rb', line 6

def get_quota(id)
  quota = client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service(id).get
  ovirt_attrs quota
end

#get_template(id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/get_template.rb', line 6

def get_template(id)
  ovirt_attrs client.system_service.templates_service.template_service(id).get
end

#get_virtual_machine(id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/get_virtual_machine.rb', line 6

def get_virtual_machine(id)
  ovirt_attrs client.system_service.vms_service.vm_service(id).get(:all_content => true)
end

#get_volume(id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/get_volume.rb', line 6

def get_volume(id)
  ovirt_attrs client.system_service.disks_service.disk_service(id).get
end

#list_clusters(opts = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/ovirt/requests/compute/v4/list_clusters.rb', line 6

def list_clusters(opts = {})
  opts[:search] = create_search_by_datacenter(:search => opts[:search], :datacenter => datacenter_hash[:name])
  client.system_service.clusters_service.list(opts).map { |ovirt_obj| ovirt_attrs(ovirt_obj) }
end

#list_instance_types(filters = {}) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_instance_types.rb', line 6

def list_instance_types(filters = {})
  client.system_service.instance_types_service.list(filters).map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_networks(cluster_id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_networks.rb', line 6

def list_networks(cluster_id)
  client.system_service.clusters_service.cluster_service(cluster_id).networks_service.list
end

#list_operating_systemsObject



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_operating_systems.rb', line 6

def list_operating_systems
  client.system_service.operating_systems_service.list.map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_quotas(filters = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/ovirt/requests/compute/v4/list_quotas.rb', line 6

def list_quotas(filters = {})
  data_center = client.system_service.data_centers_service.data_center_service(datacenter)
  data_center.quotas_service.list(filters).map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_template_interfaces(vm_id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_template_interfaces.rb', line 6

def list_template_interfaces(vm_id)
  client.system_service.templates_service.template_service(vm_id).nics_service.list.map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_template_volumes(template_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/ovirt/requests/compute/v4/list_template_volumes.rb', line 6

def list_template_volumes(template_id)
  template = client.system_service.templates_service.template_service(template_id).get
  attachments = client.follow_link(template.disk_attachments)
  attachments.map do |attachment|
    attachment_disk = client.follow_link(attachment.disk)
    attachment = client.follow_link(attachment)
    bootable = attachment.bootable
    interface = attachment.interface
    attachment_disk.bootable = bootable if attachment_disk.bootable.nil?
    attachment_disk.interface = interface if attachment_disk.interface.nil?
    attachment_disk.storage_domain = attachment_disk.storage_domains[0].id if attachment_disk.storage_domains[0].present?
    ovirt_attrs attachment_disk
  end
end

#list_templates(filters = {}) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_templates.rb', line 6

def list_templates(filters = {})
  client.system_service.templates_service.list(filters).map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_virtual_machines(filters = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/fog/ovirt/requests/compute/v4/list_virtual_machines.rb', line 6

def list_virtual_machines(filters = {})
  filters = filters.dup
  page = filters.delete(:page)
  without_details = filters.delete(:without_details)
  filters[:all_content] = true unless without_details
  filters[:search] = create_search_by_datacenter(:search => filters[:search], :datacenter => datacenter_hash[:name], :page => page)
  client.system_service.vms_service.list(filters).map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_vm_interfaces(vm_id) ⇒ Object



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_vm_interfaces.rb', line 6

def list_vm_interfaces(vm_id)
  client.system_service.vms_service.vm_service(vm_id).nics_service.list.map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#list_vm_volumes(vm_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/ovirt/requests/compute/v4/list_vm_volumes.rb', line 6

def list_vm_volumes(vm_id)
  vm = client.system_service.vms_service.vm_service(vm_id).get
  attachments = client.follow_link(vm.disk_attachments)
  attachments.map do |attachment|
    attachment_disk = client.follow_link(attachment.disk)
    attachment = client.follow_link(attachment)
    bootable = attachment.bootable
    interface = attachment.interface
    attachment_disk.bootable = bootable if attachment_disk.bootable.nil?
    attachment_disk.interface = interface if attachment_disk.interface.nil?
    attachment_disk.storage_domain = attachment_disk.storage_domains[0].id
    ovirt_attrs attachment_disk
  end
end

#list_volumesObject



6
7
8
# File 'lib/fog/ovirt/requests/compute/v4/list_volumes.rb', line 6

def list_volumes
  client.system_service.disks_service.list.map { |ovirt_obj| ovirt_attrs ovirt_obj }
end

#ovirt_attrs(obj) ⇒ Object



189
190
191
192
193
# File 'lib/fog/ovirt/compute/v4.rb', line 189

def ovirt_attrs(obj)
  shared_ovirt_attrs(obj) do
    client.follow_link(obj.vnic_profile).network.id
  end
end

#process_vm_disks(opts) ⇒ Object



19
20
21
22
# File 'lib/fog/ovirt/requests/compute/v4/create_vm.rb', line 19

def process_vm_disks(opts)
  opts[:disk_attachments] = opts[:disks].map { |disk| create_disk_attachment_from_disk(disk) }
  opts.delete(:disks)
end

#storage_domains(filter = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/ovirt/requests/compute/v4/storage_domains.rb', line 6

def storage_domains(filter = {})
  filter = filter.dup
  role_filter = filter.delete(:role)
  filter[:search] = create_search_by_datacenter(:search => filter[:search], :datacenter => datacenter_hash[:name])
  client.system_service.storage_domains_service.list(filter).collect do |sd|
    # Filter by role is not supported by the search language. The work around is to list all, then filter.
    role_filter.nil? || sd.type == role_filter ? sd : nil
  end.compact
end

#update_interface(id, options) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/ovirt/requests/compute/v4/update_interface.rb', line 15

def update_interface(id, options)
  options = convert_string_to_bool(options)
  check_arguments(id, options)

  interface_id = options[:id]
  nic = client.system_service.vms_service.vm_service(id).nics_service.nic_service(interface_id)
  nic.update(nic, options)
end

#update_os_attrs(attrs) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength



70
71
72
73
74
75
76
77
# File 'lib/fog/ovirt/requests/compute/v4/create_vm.rb', line 70

def update_os_attrs(attrs)
  attrs[:os] ||= {}
  attrs[:os][:type] ||= "Other OS"
  attrs[:os][:boot] ||= [attrs.fetch(:boot_dev1, OvirtSDK4::BootDevice::NETWORK), attrs.fetch(:boot_dev2, OvirtSDK4::BootDevice::HD)]
  attrs[:os][:boot] = attrs[:os][:boot].without(attrs["first_boot_dev"]).prepend(attrs["first_boot_dev"]) if attrs["first_boot_dev"]

  attrs[:os] = OvirtSDK4::OperatingSystem.new(:type => attrs[:os][:type], :boot => OvirtSDK4::Boot.new(:devices => attrs[:os][:boot]))
end

#update_vm(attrs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/ovirt/requests/compute/v4/update_vm.rb', line 6

def update_vm(attrs)
  attrs = attrs.dup
  attrs = convert_string_to_bool(attrs)
  vm_service = client.system_service.vms_service.vm_service(attrs[:id])

  if attrs[:cores].present?
    cpu_topology = OvirtSDK4::CpuTopology.new(:cores => attrs[:cores], :sockets => "1")
    attrs[:cpu] = OvirtSDK4::Cpu.new(:topology => cpu_topology)
  end
  wrap_attribute(attrs, :cluster, OvirtSDK4::Cluster)
  attrs[:template] = if attrs[:template].present?
                       OvirtSDK4::Template.new(:id => attrs[:template])
                     else
                       blank_template
                     end

  wrap_attribute(attrs, :large_icon, OvirtSDK4::Icon)
  wrap_attribute(attrs, :small_icon, OvirtSDK4::Icon)
  wrap_attribute(attrs, :cpu_profile, OvirtSDK4::CpuProfile)
  wrap_attribute(attrs, :host, OvirtSDK4::Host)
  wrap_attribute(attrs, :quota, OvirtSDK4::Quota)
  wrap_attribute(attrs, :instance_type, OvirtSDK4::InstanceType)
  attrs[:high_availability] = OvirtSDK4::HighAvailability.new(:enabled => attrs[:ha] == "1") if attrs[:ha].present?
  attrs[:original_template] = if attrs[:original_template].present?
                                OvirtSDK4::Template.new(:id => attrs[:original_template])
                              else
                                blank_template
                              end
  vm_service.update(attrs)
end

#update_volume(id, options) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/ovirt/requests/compute/v4/update_volume.rb', line 15

def update_volume(id, options)
  check_arguments(id, options)
  options = convert_string_to_bool(options)
  disk_id = options[:id]
  disk_attachment = client.system_service.vms_service.vm_service(id).disk_attachments_service.attachment_service(disk_id)
  disk_attachment.update(disk_attachment, options)
  true # If we come here, expect success and return true
end

#vm_action(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
# File 'lib/fog/ovirt/requests/compute/v4/vm_action.rb', line 6

def vm_action(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  raise ArgumentError, "action is a required parameter" unless options.key? :action

  vm_service = client.system_service.vms_service.vm_service(options[:id])
  vm_service.public_send(options[:action])
  vm_service.get.status
end

#vm_start_with_cloudinit(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/fog/ovirt/requests/compute/v4/vm_start_with_cloudinit.rb', line 6

def vm_start_with_cloudinit(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id

  vm_service = client.system_service.vms_service.vm_service(options[:id])
  vm_service.start(:use_cloud_init => true, :vm => { :initialization => options[:user_data] })
end

#vm_ticket(id, options = {}) ⇒ Object



6
7
8
9
# File 'lib/fog/ovirt/requests/compute/v4/vm_ticket.rb', line 6

def vm_ticket(id, options = {})
  options = convert_string_to_bool(options)
  client.system_service.vms_service.vm_service(id).ticket(options).value
end

#wrap_attribute(attrs, attribute, klass) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/fog/ovirt/requests/compute/v4/update_vm.rb', line 37

def wrap_attribute(attrs, attribute, klass)
  if attrs[attribute].present?
    attrs[attribute] = klass.new(:id => attrs[attribute])
  else
    attrs.delete(attribute)
  end
end