Le 22/12/2021 à 15:49, Nathanaël Blanchet a écrit :


Le 22/12/2021 à 14:56, John Taylor a écrit :
Maybe use the events api and search for the shutdown and reason in there?

api/events;from={event_id}?search={query}" rel="events/search"/>

-John

Exact! that's precisely the workaround I already tested this morning as well :)

and it works because the event contains the stop_reason in the description field before vm is in the stopped status!

Unfortunately, after some additionnal tests, I am in the same situation as initially with stop_reason element in api/vm, i.e. the new event containing the stop reason is writed to the API only after the hook script has exited.

So I  am never able to test this variable to determine the action to do...

P.S: For those who are interested: to make that case work, I proceeded at the opposite: rather than testing the variable condition in the hook itsself, I only use the hook to curl a job_template in AWX. By this way, the hook exits, and the ovirt_vm_info returns the expected stop_reason value and so on for following actions...


On Tue, Dec 21, 2021 at 9:00 AM Nathanaël Blanchet <blanc...@abes.fr <mailto:blanc...@abes.fr>> wrote:

    Thanks for responding,

    Le 20/12/2021 à 21:42, Nir Soffer a écrit :
    On Mon, Dec 20, 2021 at 9:59 PM Nathanaël Blanchet<blanc...@abes.fr>  
<mailto:blanc...@abes.fr>  wrote:

    Adding the devel list since question is more about extending oVirt
    ...
    The idea is to use the stop_reason element into the vm xml definition. But 
after hours, I realized that this element is writed to the vm definition file 
only after the VM has been destroyed.
    So you want to run the clean hook only if stop reason == "clean"?

    I think the way to integrate hooks is to define a custom property
    in the vm, and check if the property was defined in the hook.

    For example how the localdisk hook is triggered:

    def main():
         backend = os.environ.get('localdisk')
         if backend is None:
             return
         if backend not in [BACKEND_LVM, BACKEND_LVM_THIN]:
             hooking.log("localdisk-hook: unsupported backend: %r" % backend)
             return
         ...

    The hook runs only if the environment variable "localdisk" is defined
    and configured properly.

    vdsm defines the custom properties as environment variables.

    On the engine side, you need to add a user defined property:

          engine-config -s UserDefinedVMProperties='localdisk=^(lvm|lvmthin)$'

    And configure a custom property with one of the allowed values, like:

         localdisk=lvm

    See vdsm_hooks/localdisk/README for more info.

    If you want to control the cleanup, by adding a "clean" stop reason only 
when
    needed, this will not help, and vdsm hook is probably not the right way
    to integrate this.
    Sure
    If your intent is to clean a vm in some special events, but you want
    to integrate
    this in engine, maybe you should write an engine ui plugin?

    The plugin can show the running vms, and provide a clean button that will
    shut down the vm and run your custom code.
    too complex for doing what I want
    But maybe you don't need to integrate this in engine, and having a simple
    script using ovirt engine API/SDK to shutdown the vm and run the cleanup
    code.
    My playbook/scripts work already fine, but this is not my goal.
    Nir

    I will sum up my initial question: *Is there any way to get the
    value of "stop_reason" (value of the field in the UI) so as to
    reuse this variable into a vdsm hook?*

    Thank you


-- Nathanaël Blanchet

    Supervision réseau
    SIRE
    227 avenue Professeur-Jean-Louis-Viala
    34193 MONTPELLIER CEDEX 5   
    Tél. 33 (0)4 67 54 84 55
    Fax  33 (0)4 67 54 84 14
    blanc...@abes.fr  <mailto:blanc...@abes.fr>

    _______________________________________________
    Users mailing list -- users@ovirt.org <mailto:users@ovirt.org>
    To unsubscribe send an email to users-le...@ovirt.org
    <mailto:users-le...@ovirt.org>
    Privacy Statement: https://www.ovirt.org/privacy-policy.html
    <https://www.ovirt.org/privacy-policy.html>
    oVirt Code of Conduct:
    https://www.ovirt.org/community/about/community-guidelines/
    <https://www.ovirt.org/community/about/community-guidelines/>
    List Archives:
    
https://lists.ovirt.org/archives/list/users@ovirt.org/message/OSM572SLKKAFOWZWT6OTNSFZED5JX5RC/
    
<https://lists.ovirt.org/archives/list/users@ovirt.org/message/OSM572SLKKAFOWZWT6OTNSFZED5JX5RC/>

--
Nathanaël Blanchet

Supervision réseau
SIRE
227 avenue Professeur-Jean-Louis-Viala
34193 MONTPELLIER CEDEX 5       
Tél. 33 (0)4 67 54 84 55
Fax  33 (0)4 67 54 84 14
blanc...@abes.fr

_______________________________________________
Users mailing list -- users@ovirt.org
To unsubscribe send an email to users-le...@ovirt.org
Privacy Statement: https://www.ovirt.org/privacy-policy.html
oVirt Code of Conduct: 
https://www.ovirt.org/community/about/community-guidelines/
List Archives: 
https://lists.ovirt.org/archives/list/users@ovirt.org/message/3O3BKLSJ5PTHFWFZWSVGQ5PJ5EPVPUC5/

--
Nathanaël Blanchet

Supervision réseau
SIRE
227 avenue Professeur-Jean-Louis-Viala
34193 MONTPELLIER CEDEX 5       
Tél. 33 (0)4 67 54 84 55
Fax  33 (0)4 67 54 84 14
blanc...@abes.fr

_______________________________________________
Users mailing list -- users@ovirt.org
To unsubscribe send an email to users-le...@ovirt.org
Privacy Statement: https://www.ovirt.org/privacy-policy.html
oVirt Code of Conduct: 
https://www.ovirt.org/community/about/community-guidelines/
List Archives: 
https://lists.ovirt.org/archives/list/users@ovirt.org/message/XJ62Y5LC7H4JAJFLIM73SSBEX5B7SQI5/

Reply via email to