Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract raw_* vm operations to providers #19452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions app/models/vm/operations/guest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,42 @@ def validate_standby_guest
end

def raw_shutdown_guest
unless has_active_ems?
raise _("VM has no Provider, unable to shutdown guest OS")
end
run_command_via_parent(:vm_shutdown_guest)
raise NotImplementedError, _("must be implemented in a subclass")
end

def shutdown_guest
raise _("VM has no Provider, unable to shutdown guest OS") unless has_active_ems?

check_policy_prevent(:request_vm_shutdown_guest, :raw_shutdown_guest)
end

def raw_standby_guest
unless has_active_ems?
raise _("VM has no Provider, unable to standby guest OS")
end
run_command_via_parent(:vm_standby_guest)
raise NotImplementedError, _("must be implemented in a subclass")
end

def standby_guest
raise _("VM has no Provider, unable to standby guest OS") unless has_active_ems?

check_policy_prevent(:request_vm_standby_guest, :raw_standby_guest)
end

def raw_reboot_guest
unless has_active_ems?
raise _("VM has no Provider, unable to reboot guest OS")
end
run_command_via_parent(:vm_reboot_guest)
raise NotImplementedError, _("must be implemented in a subclass")
end

def reboot_guest
raise _("VM has no Provider, unable to reboot guest OS") unless has_active_ems?

check_policy_prevent(:request_vm_reboot_guest, :raw_reboot_guest)
end

def raw_reset
unless has_active_ems?
raise _("VM has no Provider, unable to reset VM")
end
run_command_via_parent(:vm_reset)
raise NotImplementedError, _("must be implemented in a subclass")
end

def reset
raise _("VM has no Provider, unable to reset VM") unless has_active_ems?

check_policy_prevent(:request_vm_reset, :raw_reset)
end
end
9 changes: 0 additions & 9 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ def terminated?
current_state == 'terminated'
end

def raw_set_custom_field(attribute, value)
raise _("VM has no EMS, unable to set custom attribute") unless ext_management_system
run_command_via_parent(:vm_set_custom_field, :attribute => attribute, :value => value)
end

def set_custom_field(attribute, value)
raw_set_custom_field(attribute, value)
end

def makesmart(_options = {})
self.smart = true
save
Expand Down
52 changes: 28 additions & 24 deletions app/models/vm_or_template/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,62 @@ module VmOrTemplate::Operations
alias_method :ruby_clone, :clone

def raw_clone(name, folder, pool = nil, host = nil, datastore = nil, powerOn = false, template_flag = false, transform = nil, config = nil, customization = nil, disk = nil)
raise _("VM has no EMS, unable to clone") unless ext_management_system
folder_mor = folder.ems_ref_obj if folder.respond_to?(:ems_ref_obj)
pool_mor = pool.ems_ref_obj if pool.respond_to?(:ems_ref_obj)
host_mor = host.ems_ref_obj if host.respond_to?(:ems_ref_obj)
datastore_mor = datastore.ems_ref_obj if datastore.respond_to?(:ems_ref_obj)
run_command_via_parent(:vm_clone, :name => name, :folder => folder_mor, :pool => pool_mor, :host => host_mor, :datastore => datastore_mor, :powerOn => powerOn, :template => template_flag, :transform => transform, :config => config, :customization => customization, :disk => disk)
raise NotImplementedError, _("must be implemented in a subclass")
end

def clone(name, folder, pool = nil, host = nil, datastore = nil, powerOn = false, template_flag = false, transform = nil, config = nil, customization = nil, disk = nil)
raise _("VM has no EMS, unable to clone") unless ext_management_system

raw_clone(name, folder, pool, host, datastore, powerOn, template_flag, transform, config, customization, disk)
end

def raw_mark_as_template
raise _("VM has no EMS, unable to mark as template") unless ext_management_system
run_command_via_parent(:vm_mark_as_template)
raise NotImplementedError, _("must be implemented in a subclass")
end

def mark_as_template
raise _("VM has no EMS, unable to mark as template") unless ext_management_system

raw_mark_as_template
end

def raw_mark_as_vm(pool, host = nil)
raise _("VM has no EMS, unable to mark as vm") unless ext_management_system
pool_mor = pool.ems_ref_obj if pool.respond_to?(:ems_ref_obj)
host_mor = host.ems_ref_obj if host.respond_to?(:ems_ref_obj)
run_command_via_parent(:vm_mark_as_vm, :pool => pool_mor, :host => host_mor)
raise NotImplementedError, _("must be implemented in a subclass")
end

def mark_as_vm(pool, host = nil)
raise _("VM has no EMS, unable to mark as vm") unless ext_management_system

raw_mark_as_vm(pool, host)
end

def raw_unregister
unless ext_management_system
raise _("VM has no Provider, unable to unregister VM")
end
run_command_via_parent(:vm_unregister)
raise NotImplementedError, _("must be implemented in a subclass")
end

def unregister
raise _("VM has no Provider, unable to unregister VM") unless ext_management_system

check_policy_prevent(:request_vm_unregister, :raw_unregister)
end

def raw_destroy
unless ext_management_system
raise _("VM has no Provider, unable to destroy VM")
end
run_command_via_parent(:vm_destroy)
raise NotImplementedError, _("must be implemented in a subclass")
end

def vm_destroy
raise _("VM has no Provider, unable to destroy VM") unless ext_management_system

check_policy_prevent(:request_vm_destroy, :raw_destroy)
end

def raw_rename(new_name)
unless ext_management_system
raise _("VM has no Provider, unable to rename VM")
end
run_command_via_parent(:vm_rename, :new_name => new_name)
raise NotImplementedError, _("must be implemented in a subclass")
end

def rename(new_name)
raise _("VM has no Provider, unable to rename VM") unless ext_management_system

raw_rename(new_name)
end

Expand All @@ -93,6 +87,16 @@ def rename_queue(userid, new_name)
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def raw_set_custom_field(_attribute, _value)
raise NotImplementedError, _("must be implemented in a subclass")
end

def set_custom_field(attribute, value)
raise _("VM has no EMS, unable to set custom attribute") unless ext_management_system

raw_set_custom_field(attribute, value)
end

private

#
Expand Down
82 changes: 44 additions & 38 deletions app/models/vm_or_template/operations/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,126 +1,132 @@
module VmOrTemplate::Operations::Configuration
def raw_set_memory(mb)
raise _("VM has no EMS, unable to reconfigure memory") unless ext_management_system
run_command_via_parent(:vm_set_memory, :value => mb)
raise NotImplementedError, _("must be implemented in a subclass")
end

def set_memory(mb)
raise _("VM has no EMS, unable to reconfigure memory") unless ext_management_system

raw_set_memory(mb)
end

def raw_set_number_of_cpus(num)
raise _("VM has no EMS, unable to reconfigure CPUs") unless ext_management_system
run_command_via_parent(:vm_set_num_cpus, :value => num)
raise NotImplementedError, _("must be implemented in a subclass")
end

def set_number_of_cpus(num)
raise _("VM has no EMS, unable to reconfigure CPUs") unless ext_management_system

raw_set_number_of_cpus(num)
end

def raw_connect_all_devices
raise _("VM has no EMS, unable to connect all devices") unless ext_management_system
run_command_via_parent(:vm_connect_all)
raise NotImplementedError, _("must be implemented in a subclass")
end

def connect_all_devices
raise _("VM has no EMS, unable to connect all devices") unless ext_management_system

raw_connect_all_devices
end

def raw_disconnect_all_devices
raise _("VM has no EMS, unable to disconnect all devices") unless ext_management_system
run_command_via_parent(:vm_disconnect_all)
raise NotImplementedError, _("must be implemented in a subclass")
end

def disconnect_all_devices
raise _("VM has no EMS, unable to disconnect all devices") unless ext_management_system

raw_disconnect_all_devices
end

def raw_connect_cdroms
raise _("VM has no EMS, unable to connect CD-ROM devices") unless ext_management_system
run_command_via_parent(:vm_connect_cdrom)
raise NotImplementedError, _("must be implemented in a subclass")
end

def connect_cdroms
raise _("VM has no EMS, unable to connect CD-ROM devices") unless ext_management_system

raw_connect_cdroms
end

def raw_disconnect_cdroms
raise _("VM has no EMS, unable to disconnect CD-ROM devices") unless ext_management_system
run_command_via_parent(:vm_disconnect_cdrom)
raise NotImplementedError, _("must be implemented in a subclass")
end

def disconnect_cdroms
raise _("VM has no EMS, unable to disconnect CD-ROM devices") unless ext_management_system

raw_disconnect_cdroms
end

def raw_connect_floppies
raise _("VM has no EMS, unable to connect Floppy devices") unless ext_management_system
run_command_via_parent(:vm_connect_floppy)
raise NotImplementedError, _("must be implemented in a subclass")
end

def connect_floppies
raise _("VM has no EMS, unable to connect Floppy devices") unless ext_management_system

raw_connect_floppies
end

def raw_disconnect_floppies
raise _("VM has no EMS, unable to disconnect Floppy devices") unless ext_management_system
run_command_via_parent(:vm_disconnect_floppy)
raise NotImplementedError, _("must be implemented in a subclass")
end

def disconnect_floppies
raise _("VM has no EMS, unable to disconnect Floppy devices") unless ext_management_system

raw_disconnect_floppies
end

def raw_add_disk(disk_name, disk_size_mb, options = {})
raise _("VM has no EMS, unable to add disk") unless ext_management_system
if options[:datastore]
datastore = ext_management_system.hosts.collect do |h|
h.writable_accessible_storages.find_by(:name => options[:datastore])
end.uniq.compact.first
raise _("Datastore does not exist or cannot be accessed, unable to add disk") unless datastore
end

run_command_via_parent(:vm_add_disk, :diskName => disk_name, :diskSize => disk_size_mb,
:thinProvisioned => options[:thin_provisioned], :dependent => options[:dependent],
:persistent => options[:persistent], :bootable => options[:bootable], :datastore => datastore,
:interface => options[:interface])
raise NotImplementedError, _("must be implemented in a subclass")
end

def add_disk(disk_name, disk_size_mb, options = {})
raise _("VM has no EMS, unable to add disk") unless ext_management_system

raw_add_disk(disk_name, disk_size_mb, options)
end

def raw_remove_disk(disk_name, options = {})
raise _("VM has no EMS, unable to remove disk") unless ext_management_system

options[:delete_backing] = true if options[:delete_backing].nil?
run_command_via_parent(:vm_remove_disk, :diskName => disk_name, :delete_backing => options[:delete_backing])
raise NotImplementedError, _("must be implemented in a subclass")
end

def remove_disk(disk_name, options = {})
raise _("VM has no EMS, unable to remove disk") unless ext_management_system

raw_remove_disk(disk_name, options)
end

def raw_attach_volume(volume_id, device = nil)
raise _("VM has no EMS, unable to attach volume") unless ext_management_system
run_command_via_parent(:vm_attach_volume, :volume_id => volume_id, :device => device)
raise NotImplementedError, _("must be implemented in a subclass")
end

def attach_volume(volume_id, device = nil)
raise _("VM has no EMS, unable to attach volume") unless ext_management_system

raw_attach_volume(volume_id, device)
end

def raw_detach_volume(volume_id)
raise _("VM has no EMS, unable to detach volume") unless ext_management_system
run_command_via_parent(:vm_detach_volume, :volume_id => volume_id)
raise NotImplementedError, _("must be implemented in a subclass")
end

def detach_volume(volume_id, device = nil)
raise _("VM has no EMS, unable to detach volume") unless ext_management_system

raw_detach_volume(volume_id)
end

def spec_reconfigure(spec)
def raw_reconfigure
raise NotImplementedError, _("must be implemented in a subclass")
end

def reconfigure(spec)
raise _("VM has no EMS, unable to apply reconfigure spec") unless ext_management_system
run_command_via_parent(:vm_reconfigure, :spec => spec)

raw_reconfigure(spec)
end
alias spec_reconfigure reconfigure
end
Loading