Class: Fog::Ovirt::Compute::V4::Real
- Inherits:
-
Object
- Object
- Fog::Ovirt::Compute::V4::Real
- 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/list_vnic_profiles.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
- #add_interface(id, options = {}) ⇒ Object
-
#add_options_defaults(options) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #add_volume(id, options = {}) ⇒ Object
- #api_version ⇒ Object
- #blank_template ⇒ Object
- #create_disk_attachment_from_disk(disk_to_attachment) ⇒ Object
- #create_search_by_datacenter(search:, datacenter:, page: nil) ⇒ Object
-
#create_vm(attrs) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength.
- #datacenter ⇒ Object
- #datacenter_hash ⇒ Object
- #datacenters(filter = {}) ⇒ Object
- #destroy_interface(id, options) ⇒ Object
- #destroy_vm(options = {}) ⇒ Object
- #destroy_volume(id, options) ⇒ Object
- #get_cluster(id) ⇒ Object
- #get_instance_type(id) ⇒ Object
- #get_quota(id) ⇒ Object
- #get_template(id) ⇒ Object
- #get_virtual_machine(id) ⇒ Object
- #get_volume(id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_clusters(opts = {}) ⇒ Object
- #list_instance_types(filters = {}) ⇒ Object
- #list_networks(cluster_id) ⇒ Object
- #list_operating_systems ⇒ Object
- #list_quotas(filters = {}) ⇒ Object
- #list_template_interfaces(vm_id) ⇒ Object
- #list_template_volumes(template_id) ⇒ Object
- #list_templates(filters = {}) ⇒ Object
- #list_virtual_machines(filters = {}) ⇒ Object
- #list_vm_interfaces(vm_id) ⇒ Object
- #list_vm_volumes(vm_id) ⇒ Object
- #list_vnic_profiles(_opts = {}) ⇒ Object
- #list_volumes ⇒ Object
- #ovirt_attrs(obj) ⇒ Object
- #process_vm_disks(opts) ⇒ Object
- #storage_domains(filter = {}) ⇒ Object
- #update_interface(id, options) ⇒ Object
-
#update_os_attrs(attrs) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength.
- #update_vm(attrs) ⇒ Object
- #update_volume(id, options) ⇒ Object
- #vm_action(options = {}) ⇒ Object
- #vm_start_with_cloudinit(options = {}) ⇒ Object
- #vm_ticket(id, options = {}) ⇒ Object
- #wrap_attribute(attrs, attribute, klass) ⇒ Object
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.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/fog/ovirt/compute/v4.rb', line 170 def initialize( = {}) require "ovirtsdk4" username = [:ovirt_username] password = [:ovirt_password] server = [:ovirt_server] port = [:ovirt_port] || 8080 api_path = [:ovirt_api_path] || "/api" url = [:ovirt_url] || "https://#{server}:#{port}#{api_path}" connection_opts = { :url => url, :username => username, :password => password } @datacenter = [:ovirt_datacenter] connection_opts[:ca_file] = [:ca_file] connection_opts[:ca_certs] = [OpenSSL::X509::Certificate.new([:public_key])] if [:public_key].present? @client = ExceptionWrapper.new(OvirtSDK4::Connection.new(connection_opts)) end |
Instance Method Details
#add_interface(id, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/ovirt/requests/compute/v4/add_interface.rb', line 6 def add_interface(id, = {}) raise ArgumentError, "instance id is a required parameter" unless id vm = client.system_service.vms_service.vm_service(id) nics_service = vm.nics_service = .dup = convert_string_to_bool() if [:network].present? && [:vnic_profile].nil? network = client.system_service.networks_service.network_service([:network]).get profiles = client.follow_link(network.vnic_profiles) profile = profiles.detect { |x| x.name == network.name } profile ||= profiles.min_by(&:name) [:vnic_profile] = profile.id end [:vnic_profile] = { :id => [:vnic_profile] } .delete(:network) interface = OvirtSDK4::Nic.new() 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 () = .dup = convert_string_to_bool() [:bootable] = .delete(:bootable) [:interface] ||= OvirtSDK4::DiskInterface::VIRTIO [:provisioned_size] = [:size_gb].to_i * Fog::Ovirt::Compute::DISK_SIZE_TO_GB if [:size_gb] [:sparse] = true if [:sparse].nil? [:storage_domain_id] = [:storage_domain] if [:storage_domain] # If no size is given, default to a volume size of 8GB [:provisioned_size] ||= 8 * Fog::Ovirt::Compute::DISK_SIZE_TO_GB [:type] ||= OvirtSDK4::DiskType::DATA [:format] ||= OvirtSDK4::DiskFormat::COW [:quota] = [:quota].present? ? client.system_service.data_centers_service.data_center_service(datacenter).quotas_service.quota_service([:quota]).get : nil [:disk] ||= {} [:disk][:sparse] = .delete(:sparse) if [:disk][:sparse].nil? [:disk][:storage_domains] ||= [client.system_service.storage_domains_service.storage_domain_service([:storage_domain_id]).get] if [:storage_domain_id] [:disk][:provisioned_size] ||= .delete(:provisioned_size) [:disk][:format] ||= .delete(:format) [:disk][:wipe_after_delete] = .delete(:wipe_after_delete) if [:disk][:wipe_after_delete].nil? end |
#add_volume(id, options = {}) ⇒ Object
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, = {}) raise ArgumentError, "instance id is a required parameter" unless id = () = client.system_service.vms_service.vm_service(id). disk = OvirtSDK4::DiskAttachment.new() .add(disk) end |
#api_version ⇒ Object
197 198 199 200 |
# File 'lib/fog/ovirt/compute/v4.rb', line 197 def api_version api = client.system_service.get api.product_info.version.full_version end |
#blank_template ⇒ Object
211 212 213 |
# File 'lib/fog/ovirt/compute/v4.rb', line 211 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 () storage_domain = client.system_service.storage_domains_service.storage_domain_service(["storage_domain"]).get disk = { :id => ["id"], :format => .fetch("format", OvirtSDK4::DiskFormat::COW), :sparse => .fetch("sparse", true), :storage_domains => [storage_domain] } OvirtSDK4::DiskAttachment.new(:disk => disk) end |
#create_search_by_datacenter(search:, datacenter:, page: nil) ⇒ Object
215 216 217 218 219 220 |
# File 'lib/fog/ovirt/compute/v4.rb', line 215 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 |
#datacenter ⇒ Object
202 203 204 |
# File 'lib/fog/ovirt/compute/v4.rb', line 202 def datacenter datacenter_hash[:id] end |
#datacenter_hash ⇒ Object
206 207 208 209 |
# File 'lib/fog/ovirt/compute/v4.rb', line 206 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
6 7 8 9 10 11 |
# File 'lib/fog/ovirt/requests/compute/v4/destroy_interface.rb', line 6 def destroy_interface(id, ) raise ArgumentError, "instance id is a required parameter" unless id raise ArgumentError, "interface id is a required parameter for destroy-interface" unless .key? :id vm = client.system_service.vms_service.vm_service(id) vm.nics_service.nic_service([:id]).remove end |
#destroy_vm(options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/fog/ovirt/requests/compute/v4/destroy_vm.rb', line 6 def destroy_vm( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id client.system_service.vms_service.vm_service([:id]).remove true end |
#destroy_volume(id, options) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/ovirt/requests/compute/v4/destroy_volume.rb', line 6 def destroy_volume(id, ) raise ArgumentError, "instance id is a required parameter" unless id raise ArgumentError, "volume id is a required parameter for destroy-volume" unless .key? :id disks_service = client.system_service.disks_service disks_service.disk_service([: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_systems ⇒ Object
6 7 8 |
# File 'lib/fog/ovirt/requests/compute/v4/list_operating_systems.rb', line 6 def client.system_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 = client.follow_link(template.) .map do || = client.follow_link(.disk) = client.follow_link() bootable = .bootable interface = .interface .bootable = bootable if .bootable.nil? .interface = interface if .interface.nil? .storage_domain = .storage_domains[0].id if .storage_domains[0].present? ovirt_attrs 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 20 21 22 23 24 |
# 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 = client.follow_link(vm.) .map do || = client.follow_link(.disk) = client.follow_link() bootable = .bootable interface = .interface .bootable = bootable if .bootable.nil? .interface = interface if .interface.nil? .storage_domain = begin .storage_domains.first&.id rescue StandardError => e Fog::Logger.warning("Error parsing attachment_disk.storage_domains - #{e}. Fallback to 0") 0 end ovirt_attrs end end |
#list_vnic_profiles(_opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/fog/ovirt/requests/compute/v4/list_vnic_profiles.rb', line 6 def list_vnic_profiles(_opts = {}) dc_vnics = [] profiles = client.system_service.vnic_profiles_service.list profiles.each do |profile| vnic_network = client.follow_link(profile.network) dc_vnics.append(profile) if vnic_network.data_center.id == datacenter end dc_vnics end |
#list_volumes ⇒ Object
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
191 192 193 194 195 |
# File 'lib/fog/ovirt/compute/v4.rb', line 191 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| (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? || Array(role_filter).include?(sd.type) ? 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, ) = convert_string_to_bool() check_arguments(id, ) interface_id = [:id] nic = client.system_service.vms_service.vm_service(id).nics_service.nic_service(interface_id) nic.update(nic, ) 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 => attrs[: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, ) check_arguments(id, ) = convert_string_to_bool() disk_id = [:id] = client.system_service.vms_service.vm_service(id)..(disk_id) .update(, ) true # If we come here, expect success and return true end |
#vm_action(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/fog/ovirt/requests/compute/v4/vm_action.rb', line 6 def vm_action( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id raise ArgumentError, "action is a required parameter" unless .key? :action vm_service = client.system_service.vms_service.vm_service([:id]) vm_service.public_send([:action]) vm_service.get.status end |
#vm_start_with_cloudinit(options = {}) ⇒ Object
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( = {}) raise ArgumentError, "instance id is a required parameter" unless .key? :id vm_service = client.system_service.vms_service.vm_service([:id]) vm_service.start(:use_cloud_init => true, :vm => { :initialization => [: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, = {}) = convert_string_to_bool() client.system_service.vms_service.vm_service(id).ticket().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 |