diff --git a/app/models/vm.rb b/app/models/vm.rb index d928e493ef35..bda832807807 100644 --- a/app/models/vm.rb +++ b/app/models/vm.rb @@ -4,6 +4,7 @@ class Vm < VmOrTemplate has_one :container_deployment_node virtual_has_one :supported_consoles, :class_name => "Hash" + virtual_column :transformed, :type => :boolean extend InterRegionApiMethodRelay include CustomActionsMixin @@ -133,6 +134,12 @@ def validate_v2v_migration vm_as_resources.all? { |rsc| rsc.status == ServiceResource::STATUS_FAILED } ? TransformationMapping::VM_VALID : TransformationMapping::VM_IN_OTHER_PLAN end + def transformed + !ServiceResource.joins(:service_template) + .where(:service_templates => {:type => 'ServiceTemplateTransformationPlan'}) + .where(:resource => self, :status => ServiceResource::STATUS_COMPLETED).empty? + end + private def vnc_support diff --git a/product/policy/built_in_policies.yml b/product/policy/built_in_policies.yml index d10adc961fdb..05dbeff6d811 100644 --- a/product/policy/built_in_policies.yml +++ b/product/policy/built_in_policies.yml @@ -42,6 +42,19 @@ :modifier: deny :mode: control :action: vm_suspend +- :name: Prevent Transformed VM from Starting + :description: Prevent Transformed VM from starting + :towhat: Vm + :event: request_vm_start + :applies_to?: true + :active: true + :condition: + "=": + field: Vm-transformed + value: true + :modifier: deny + :mode: control + :action: prevent - :name: Stop Retired VM :description: Stop Retired VM :towhat: Vm diff --git a/spec/models/vm_spec.rb b/spec/models/vm_spec.rb index 2c26f1dc93e4..1f795f5d69cf 100644 --- a/spec/models/vm_spec.rb +++ b/spec/models/vm_spec.rb @@ -314,4 +314,21 @@ expect(vm.supported_consoles.keys).to match_array([:spice, :vnc, :vmrc, :webmks, :cockpit]) end end + + context "#transformed" do + let(:plan) { FactoryGirl.create(:service_template_transformation_plan) } + let(:vm) { FactoryGirl.create(:vm) } + let(:service_resource) { FactoryGirl.create(:service_resource, :resource => vm, :service_template => plan) } + + subject { vm.transformed } + + it 'returns true' do + service_resource.update_attributes(:status => ServiceResource::STATUS_COMPLETED) + expect(subject).to be true + end + + it 'returnes false' do + expect(subject).to be false + end + end end