-
Notifications
You must be signed in to change notification settings - Fork 897
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 transformation plan and request
- Loading branch information
Showing
8 changed files
with
87 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
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 ServiceTemplateTransformationPlan < 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 |
33 changes: 33 additions & 0 deletions
33
app/models/service_template_transformation_plan_request.rb
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 ServiceTemplateTransformationPlanRequest < ServiceTemplateProvisionRequest | ||
TASK_DESCRIPTION = 'VM Transformations'.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 ServiceTemplateTransformationPlanTask < ServiceTemplateProvisionTask | ||
def self.base_model | ||
ServiceTemplateTransformationPlanTask | ||
end | ||
|
||
def after_request_task_create | ||
update_attributes(:description => "Transforming VM #{source.name}") | ||
end | ||
|
||
def resource_action | ||
miq_request.source.resource_actions.detect { |ra| ra.action == 'Provision' } | ||
end | ||
|
||
def transformation_destination(source_obj) | ||
miq_request.infra_mapping.destination(source_obj) | ||
end | ||
|
||
def update_transformation_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
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