Skip to content

Commit

Permalink
Merge pull request #11366 from jelkosz/add-migrate-to-rhev-provider
Browse files Browse the repository at this point in the history
Add Migrate support to RHEV provider
  • Loading branch information
gmcculloug committed Nov 3, 2016
2 parents 364609e + bc4c103 commit 99adc9d
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 23 deletions.
18 changes: 18 additions & 0 deletions app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,22 @@ def remove_disks(disks, vm)
disks.each { |disk_id| service.attachment_service(disk_id).remove }
end
end

def vm_migrate(vm, options = {})
host_id = URI(options[:host]).path.split('/').last

migration_options = {
:host => {
:id => host_id
}
}

with_version4_vm_service(vm) do |service|
service.migrate(migration_options)
end
end

def unsupported_migration_options
[:storage, :respool, :folder, :datacenter, :host_filter]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,15 @@ def version_3_0?

# Adding disks is supported only by API version 4.0
def with_disk_attachments_service(vm)
with_version4_vm_service(vm) do |service|
disk_service = service.disk_attachments_service
yield disk_service
end
end

def with_version4_vm_service(vm)
connection = connect(:version => 4)
service = connection.system_service.vms_service.vm_service(vm.uid_ems).disk_attachments_service
service = connection.system_service.vms_service.vm_service(vm.uid_ems)
yield service
ensure
connection.close
Expand All @@ -211,7 +218,7 @@ def api3_supported_features
end

def api4_supported_features
[:quick_stats, :snapshots]
[:quick_stats, :snapshots, :migrate]
end

def api_features
Expand Down
6 changes: 5 additions & 1 deletion app/models/manageiq/providers/redhat/infra_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class ManageIQ::Providers::Redhat::InfraManager::Vm < ManageIQ::Providers::Infra
include_concern 'Reconfigure'
include_concern 'ManageIQ::Providers::Redhat::InfraManager::VmOrTemplateShared'

supports_not :migrate, :reason => _("Migrate operation is not supported.")
supports :migrate do
unless ext_management_system.supports_migrate?
unsupported_reason_add(:migrate, 'RHV API version does not support migrate')
end
end

POWER_STATES = {
'up' => 'on',
Expand Down
11 changes: 11 additions & 0 deletions app/models/vm_migrate_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def get_source_and_targets(refresh = false)
return @target_resource = {} if ems.length != 1

result = {:ems => ci_to_hash_struct(ems.first)}
@manager = ems.first

add_target(:placement_host_name, :host, Host, result)
add_target(:placement_ds_name, :storage, Storage, result)
add_target(:placement_cluster_name, :cluster, EmsCluster, result)
Expand All @@ -38,6 +40,15 @@ def get_source_and_targets(refresh = false)
@target_resource = result
end

def add_target(dialog_key, key, klass, result)
super if field_supported(key)
end

def field_supported(key)
!(@manager.respond_to?(:unsupported_migration_options) &&
@manager.unsupported_migration_options.include?(key))
end

private

def allowed_ci(ci, relats, filtered_ids = nil)
Expand Down
44 changes: 24 additions & 20 deletions app/views/miq_request/_prov_vm_migrate_dialog.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
:label => _("Manager"),
:keys => keys})
- when :environment
- keys = [:placement_dc_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Datacenter"),
:keys => keys})
- if wf.field_supported(:datacenter)
- keys = [:placement_dc_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Datacenter"),
:keys => keys})

- keys = [:cluster_filter, :placement_cluster_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
Expand All @@ -35,28 +36,31 @@
:label => title_for_cluster,
:keys => keys})

- keys = [:rp_filter, :placement_rp_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Resource Pool"),
:keys => keys})
- if wf.field_supported(:respool)
- keys = [:rp_filter, :placement_rp_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Resource Pool"),
:keys => keys})

- keys = [:host_filter, :placement_host_name]
- keys = [wf.field_supported(:host_filter) ? :host_filter : nil, :placement_host_name].compact
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => title_for_host,
:keys => keys,
:extra_table_attributes => "width=100%"})

- keys = [:ds_filter, :placement_ds_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Datastore"),
:keys => keys,
:extra_table_attributes => "width=100%"})
- if wf.field_supported(:storage)
- keys = [:ds_filter, :placement_ds_name]
= render(:partial => "/miq_request/prov_dialog_fieldset",
:locals => {:workflow => wf,
:dialog => dialog,
:label => _("Datastore"),
:keys => keys,
:extra_table_attributes => "width=100%"})

- when :hardware
- keys = [:disk_format]
= render(:partial => "/miq_request/prov_dialog_fieldset",
Expand Down
30 changes: 30 additions & 0 deletions spec/models/vm_migrate_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
let(:ems) { FactoryGirl.create(:ems_vmware) }
let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'My VM', :ext_management_system => ems) }

let(:redhat_ems) { FactoryGirl.create(:ems_redhat) }
let(:redhat_vm) { FactoryGirl.create(:vm_redhat, :name => 'My RHV VM', :ext_management_system => redhat_ems) }

context "With a Valid Template," do
context "#allowed_hosts" do
let(:workflow) { VmMigrateWorkflow.new({:src_ids => [vm.id]}, admin) }
Expand All @@ -26,6 +29,33 @@
end
end

describe "Configuring targets" do
context "redhat VM" do
let(:workflow) { VmMigrateWorkflow.new({:src_ids => [redhat_vm.id]}, admin) }

it "excludes some properties in" do
stub_dialog
workflow.get_source_and_targets
target_resource = workflow.instance_variable_get(:@target_resource)
expect(target_resource).not_to include(:storage_id, :respool_id, :folder_id,
:datacenter_id)
expect(target_resource).to include(:host_id, :cluster_id)
end
end

context "vmware VM" do
let(:workflow) { VmMigrateWorkflow.new({:src_ids => [vm.id]}, admin) }

it "includes all properties in" do
stub_dialog
workflow.get_source_and_targets
target_resource = workflow.instance_variable_get(:@target_resource)
expect(target_resource).to include(:host_id, :cluster_id, :storage_id, :respool_id,
:folder_id, :datacenter_id)
end
end
end

describe "#make_request" do
let(:alt_user) { FactoryGirl.create(:user_with_group) }

Expand Down

0 comments on commit 99adc9d

Please sign in to comment.