-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial support for migration plan and request
- Loading branch information
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class MigrationPlanProvisionRequest < ServiceTemplateProvisionRequest | ||
TASK_DESCRIPTION = 'VM Migrations'.freeze | ||
|
||
def requested_task_idx | ||
vm_requests.where(:status => 'Approved') | ||
end | ||
|
||
def customize_request_task_attributes(req_task_attrs, vm_request) | ||
req_task_attrs[:source] = vm_request.resource | ||
end | ||
|
||
def infra_mapping | ||
source.service_resources.find_by(:resource_type => 'TransformationMapping') | ||
end | ||
|
||
def source_vms | ||
vm_requests.where(:status => %w(Queued Failed)).pluck(:resource_id) | ||
end | ||
|
||
def validate_vm(vm_id) | ||
true | ||
end | ||
|
||
def approve_vm(vm_id) | ||
vm_requests.find_by(:resource_id => vm_id).update_attributes!(:status => 'Approved') | ||
end | ||
|
||
private | ||
|
||
def vm_requests | ||
source.service_resources.where(:resource_type => 'VmOrTemplate') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class MigrationPlanProvisionTask < ServiceTemplateProvisionTask | ||
def self.base_model | ||
MigrationPlanProvisionTask | ||
end | ||
|
||
def after_request_task_create | ||
update_attributes(:description => "Migrating VM #{source.name}") | ||
end | ||
|
||
def resource_action | ||
miq_request.source.resource_actions.detect { |ra| ra.action == 'Provision' } | ||
end | ||
|
||
def migration_destination(source_obj) | ||
miq_request.infra_mapping.find_by(:source => source_obj).destination | ||
end | ||
|
||
def update_migration_progress(progress) | ||
options[:progress] = (options[:progress]||{}).merge(progress) | ||
save | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ServiceTemplateMigrationPlan < ServiceTemplate | ||
def add_vms(vm_ids) | ||
vm_ids.each { |vm_id| add_vm(vm_id) } | ||
save! | ||
end | ||
|
||
def add_vm(vm_id) | ||
sr = service_resources.detect { |r| r.resource_type == 'VmOrTemplate' && r.resource_id == vm_id } | ||
return unless sr.nil? | ||
|
||
service_resources.new(:resource_type => 'VmOrTemplate', :resource_id => vm_id, :status => 'Queued') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters