Bug 1536628

Summary: [RFE][XS-2] Add possibility to unregister a VM in RHV provider
Product: Red Hat CloudForms Management Engine Reporter: Tina Fitzgerald <tfitzger>
Component: ProvidersAssignee: Moti Asayag <masayag>
Status: CLOSED CURRENTRELEASE QA Contact: Ilanit Stein <istein>
Severity: high Docs Contact:
Priority: medium    
Version: 5.8.0CC: cpelland, gblomqui, greartes, jfrey, jhardy, jocarter, masayag, mfeifer, mperina, myoder, nzunigaf, obarenbo, simaishi, tfitzger
Target Milestone: MVPKeywords: FutureFeature, RFE, TestOnly, ZStream
Target Release: 5.10.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 5.10.0.0 Doc Type: Enhancement
Doc Text:
Feature: Support unregister vm from ovirt-engine (removing the vm, but retaining its disks) Reason: Before adding that capability to CFME, the admin could only remove the VM entirely, without preserving its disks to be used later (i.e. by attaching them to a different vm ) Result: With this fix, the user will be able to remove the VM from ovirt-engine, but to preserve its disks. This feature is supported only for ovirt-engine that supports api v4 (ovirt-engine-4.0 and above).
Story Points: ---
Clone Of:
: 1552671 1589834 (view as bug list) Environment:
Last Closed: 2019-02-11 14:02:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: RHEVM Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1552671, 1555371, 1589834    
Attachments:
Description Flags
unregister_vm_copy_instance.png
none
add_method_for_unregister.png
none
automate_simulation.png none

Description Tina Fitzgerald 2018-01-19 19:07:57 UTC
Description of problem:
The Automate Retirement State Machine gives the user the option to select "unregister" instead of "remove_from_disk" as a retirement option.
This option was originally added for a VMWare customer and is seldom used. 
There is a consultant attempting to use the "unregister" option for RHEV retirement which is not currently implemented.

WMWare unregister:
https://github.com/ManageIQ/manageiq-providers-vmware/blob/master/app/models/manageiq/providers/vmware/infra_manager.rb#L199

Can we implement vm_unregister for any/all of the other infrastructure providers where it makes sense?

Comment 2 Dave Johnson 2018-01-19 19:44:46 UTC
Please assess the impact of this issue and update the severity accordingly.  Please refer to https://bugzilla.redhat.com/page.cgi?id=fields.html#bug_severity for a reminder on each severity's definition.

If it's something like a tracker bug where it doesn't matter, please set the severity to Low.

Comment 6 Tina Fitzgerald 2018-01-22 15:59:25 UTC
Hi Greg,

It came to my attention last week that someone was attempting to use the unregister retirement workflow for RHEV. I opened the ticket to find out if it's possible to support unregister for other infra providers.  We'll have to modify the retirement state machine to block/prevent the unregister workflow for unsupported providers.

Thanks,
Tina

Comment 7 Adam Grare 2018-01-23 10:32:04 UTC
Turns out it is possible to unregister a VM in RHEV, assigning to the RHEV team to implement the vm.unregister method.

Comment 8 Martin Perina 2018-02-15 17:36:14 UTC
I highly doubt we will have a capacity to deliver this RFE in 5.9.1

Comment 9 Martin Perina 2018-03-01 12:21:36 UTC
(In reply to Martin Perina from comment #8)
> I highly doubt we will have a capacity to deliver this RFE in 5.9.1

We have reconsidered and will try to deliver in 5.9.1

Comment 11 Ilanit Stein 2018-03-05 12:42:44 UTC
Moti,

Can you please provide validation steps for this RFE?

Thanks.

Comment 12 Moti Asayag 2018-03-05 13:15:06 UTC
(In reply to Ilanit Stein from comment #11)
> Moti,
> 
> Can you please provide validation steps for this RFE?
> 
> Thanks.

The details of selecting the 'unregister' method of retiring a vm can be found here:

https://pemcg.gitbooks.io/introduction-to-cloudforms-automation/content/chapter18/retirement.html

Comment 13 CFME Bot 2018-03-05 15:35:26 UTC
New commit detected on ManageIQ/manageiq-providers-ovirt/master:
https://github.com/ManageIQ/manageiq-providers-ovirt/commit/a8de7023ccd8388b17cf8edb87dae295565dbe2d

commit a8de7023ccd8388b17cf8edb87dae295565dbe2d
Author:     Moti Asayag <masayag>
AuthorDate: Sun Mar 4 17:20:26 2018 +0200
Commit:     Moti Asayag <masayag>
CommitDate: Mon Mar 5 15:19:19 2018 +0200

    Support Unregister VM
    
    Unregister VM allows the user to remove the VM without deleting its
    disks.
    For that purpose, the request to remove VM to ovirt-engine includes the
    'detach_only=true' parameter.
    
    This action will succeed if the VM isn't originated from a template, or
    if the VM has no snapshots.
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536628

 .../infra_manager/ovirt_services/strategies/v4.rb    |  4 ++++
 .../providers/redhat/infra_manager/vm/operations.rb  |  4 ++++
 .../providers/redhat/infra_manager/vm_spec.rb        | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+)

Comment 14 Moti Asayag 2018-03-06 12:35:08 UTC
(In reply to Moti Asayag from comment #12)
> (In reply to Ilanit Stein from comment #11)
> > Moti,
> > 
> > Can you please provide validation steps for this RFE?
> > 
> > Thanks.
> 
> The details of selecting the 'unregister' method of retiring a vm can be
> found here:
> 
> https://pemcg.gitbooks.io/introduction-to-cloudforms-automation/content/
> chapter18/retirement.html

In addition to the link above, a simple automation method with code as bellow will be sufficient to invoke the vm.unregister method:

------------- 8< ------------------------
#
# Description: This method is used to unregister a vm
#
# Inputs: vm_name
#

# Get vm object
vm_name = $evm.root['vm_name']
$evm.log("info", "-------->>>> Trying to add disk to VM: <#{vm_name}>")

$evm.root['vm'] = $evm.vmdb('vm').find_by_name(vm_name)
vm = $evm.root['vm']
raise "Missing $evm.root['vm'] object" unless vm

vm.unregister

------------- >8 ------------------------

Comment 21 CFME Bot 2018-06-11 14:56:39 UTC
New commit detected on ManageIQ/manageiq/fine:

https://github.com/ManageIQ/manageiq/commit/5193ee99d81be65b07b096202dcc74af373bf49d
commit 5193ee99d81be65b07b096202dcc74af373bf49d
Author:     Moti Asayag <masayag>
AuthorDate: Wed Jun  6 07:09:52 2018 -0400
Commit:     Moti Asayag <masayag>
CommitDate: Wed Jun  6 07:09:52 2018 -0400

    Support Unregister VM

    Unregister VM allows the user to remove the VM without deleting its
    disks.
    For that purpose, the request to remove VM to ovirt-engine includes the
    'detach_only=true' parameter.

    This action will succeed if the VM isn't originated from a template, or
    if the VM has no snapshots.

    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536628

 app/models/manageiq/providers/redhat/infra_manager/ovirt_services/strategies/v4.rb | 4 +
 app/models/manageiq/providers/redhat/infra_manager/vm/operations.rb | 4 +
 spec/models/manageiq/providers/redhat/infra_manager/vm_spec.rb | 20 +
 3 files changed, 28 insertions(+)

Comment 23 Ilanit Stein 2018-07-15 09:19:24 UTC
Verified on CFME-5.10.0.4/RHV-4.2.5:

Steps done under Automation:
===========================

1) In Automate->Explorer added a new domain and a namespace.
(As a reference, this link can be used to create the domain/namespace:
https://pemcg.gitbooks.io/introduction-to-cloudforms-automation/content/chapter1/methods.html ,
See the "hello world" method creation flow).

2) Copy instance Redhat-> Integration->VMware->VimApi->"VMware_HotAdd_Disk"
to the created namespace path.
(See 'unregister_vm_copy_instance.png' attached).

3) Edit the Instance name from "VMware_HotAdd_Disk" into "Unregister_vm".

4) Add method named "unregister_vm" (See 'add_method_for_unregister.png' attached)
Set the method type as inline, and add this content:

#
# Description: This method is used to unregister a vm
#
# Inputs: vm_name
#

# Get vm object
vm_name = $evm.root['vm_name']
$evm.log("info", "-------->>>> Trying to unregister VM: <#{vm_name}>")

$evm.root['vm'] = $evm.vmdb('vm').find_by_name(vm_name)
vm = $evm.root['vm']
raise "Missing $evm.root['vm'] object" unless vm

vm.unregister

5) In the "Unregister_vm" instance update it should call the method "unregister_vm".

6) Then run Automate->Simulation, with vm_name of VM that we want to unregister.
This VM should have a disk that is not of an existing template, and should be in state down for the unregister succeed.
(See automate_simulation.png)

Results:
=======
Once the simulation operation was complete, the VM was removed, 
and it's disk was not removed.

Comment 24 Ilanit Stein 2018-07-15 09:24:06 UTC
Created attachment 1458978 [details]
unregister_vm_copy_instance.png

Comment 25 Ilanit Stein 2018-07-15 09:26:03 UTC
Created attachment 1458979 [details]
add_method_for_unregister.png

Comment 26 Ilanit Stein 2018-07-15 09:27:14 UTC
Created attachment 1458980 [details]
automate_simulation.png