[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
Dear Michal, We went with your first recommendation and built two python scripts. It works very nice and I am happy to share them with you: 1. after_vm_migrate_source/60_register_migration #!/usr/bin/python2 from __future__ import print_function import hooking import os import logging logger = logging.getLogger("register_migration") if __name__ == "__main__": try: logging.basicConfig(filename="/var/log/vdsm/custom_hooks.log", level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s:%(message)s', datefmt = '%Y-%m-%d %H:%M:%S') domxml = hooking.read_domxml() vmid = domxml.getElementsByTagName('uuid')[0] vmid = vmid.firstChild.data tmp_file = os.path.join("/tmp", vmid) open(tmp_file, "a").close() logger.info("Migrating VM {vmid}, creating temp file {tmp_file}".format(vmid=vmid, tmp_file=tmp_file)) except Exception as e: logging.exception("Caught exception") 2. after_vm_destroy/60_nsupdate: / #!/usr/bin/python2 from __future__ import print_function import hooking import logging import os import subprocess from subprocess import PIPE, STDOUT logger = logging.getLogger("dns-update") if __name__ == "__main__": try: logging.basicConfig(filename="/var/log/vdsm/custom_hooks.log", level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s:%(message)s', datefmt = '%Y-%m-%d %H:%M:%S') domxml = hooking.read_domxml() name = domxml.getElementsByTagName('name')[0] name = " ".join(name.nodeValue for name in name.childNodes if name.nodeType == name.TEXT_NODE) vmid = domxml.getElementsByTagName('uuid')[0] vmid = vmid.firstChild.data tmp_file = os.path.join("/tmp", vmid) if not os.path.exists(tmp_file): nsupdate_commands = """server {server_ip} update delete {vm_name}.example.com a update delete {vm_name}. example.com update delete {vm_name}. example.com txt send """.format(server_ip="1.2.3.4", vm_name=name) logger.info("Deleting VM {name} DNS records".format(name=name)) p = subprocess.Popen(["nsupdate", "-k", "/usr/libexec/vdsm/hooks/after_vm_destroy/nsupdate.private"], stdin=PIPE, stdout=PIPE, stderr=STDOUT) result = p.communicate(input=nsupdate_commands)[0] logger.info("Output:" + result) else: os.remove(tmp_file) logger.info("Ignoring DNS records delete for VM {name}:{vmid}".format(name=name, vmid=vmid)) except Exception as e: logger.exception("Caught exception") Both scripts are writing to same log file on each server and log lines look like this: 2019-11-06 13:11:12 INFO register_migration:Migrating VM 8101da66-31a1-4818-9d82-a8602d11bcf1, creating temp file /tmp/8101da66-31a1-4818-9d82-a8602d11bcf1 2019-11-06 13:11:13 INFO dns-update:Ignoring DNS records delete for VM testhooksatt2:8101da66-31a1-4818-9d82-a8602d11bcf1 2019-11-06 13:12:13 INFO dns-update:Deleting VM testhooksatt2 DNS records 2019-11-06 13:12:13 INFO dns-update:Output: Once again , I thank you and appreciate your help. - kind regards/met vrindelijke groet Marko Vrgotic ActiveVideo On 03/10/2019, 15:28, "Vrgotic, Marko" wrote: Michal, Thank you - that certainly helps. I will give it a try, using your suggestion and see how far I get. On 03/10/2019, 13:54, "Michal Skrivanek" wrote: > On 3 Oct 2019, at 12:50, Vrgotic, Marko wrote: > > Hi Michal, > > Thank you. Would you be so kind to provide me with additional clarification? > >> you can’t just add a random tag into libvirt xml in a random place, it will be dropped by libvirt. > I understand, thank you. About persistence of added tag, it was not used/written during 1xMigration, but it was present in domxml in 2xMigration. > >> you can add it to metadata though. we use that for ovirt-specific information > Can you please provide some more HowTo/HowNotTo information? > Can we manipulate the tag in metadata section in each iteration? > I assume VM metadata shared/communicated between Hosts or read and provided to Hosts by oVirt-Engine? > In short we are trying to achive: > - start migration > - ex: 10_create_tag inserts tag into XML metadata section <= maybe we can use before_vm_migration_source hook > - migration is finished and after_vm_destroy hooks comes to turn: > - ex: 20_nsupdate reads the metadata and: > - if tag exists, do not run dns update, but remove the tag > - if tag does not exists, run dns update and remove the tag so..hmm..if IIUC you basically just need not
[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
Michal, Thank you - that certainly helps. I will give it a try, using your suggestion and see how far I get. On 03/10/2019, 13:54, "Michal Skrivanek" wrote: > On 3 Oct 2019, at 12:50, Vrgotic, Marko wrote: > > Hi Michal, > > Thank you. Would you be so kind to provide me with additional clarification? > >> you can’t just add a random tag into libvirt xml in a random place, it will be dropped by libvirt. > I understand, thank you. About persistence of added tag, it was not used/written during 1xMigration, but it was present in domxml in 2xMigration. > >> you can add it to metadata though. we use that for ovirt-specific information > Can you please provide some more HowTo/HowNotTo information? > Can we manipulate the tag in metadata section in each iteration? > I assume VM metadata shared/communicated between Hosts or read and provided to Hosts by oVirt-Engine? > In short we are trying to achive: > - start migration > - ex: 10_create_tag inserts tag into XML metadata section <= maybe we can use before_vm_migration_source hook > - migration is finished and after_vm_destroy hooks comes to turn: > - ex: 20_nsupdate reads the metadata and: > - if tag exists, do not run dns update, but remove the tag > - if tag does not exists, run dns update and remove the tag so..hmm..if IIUC you basically just need not to execute dns update(remove the entry for vm) when VM migrates away. and do execute it when it shuts down. maybe i can suggest two other approaches which could work? these would be preferable because manipulating with libvirt’s xml at the time of lifecycle changes are better to be avoided. libvirt is touching the xml at the same tie and it may run into ugly locking problems. how about - use after_vm_migrate_source and make a note of that vmid (touch a file in /tmp/ or whatever), and then check that in after_vm_destroy or - use before_vm_destroy and use vdsm-client VM getStats vmid=‘xyz’ to get the curent VM’s status from vdsm (before it goes away) and you should see if it’s “Migration Source” vs anything else(Powering Down for ordinary shutdowns or Up for crashes, I guess) Thanks, michal > > Kindly awaiting your reply. > > Marko Vrgotic > > On 03/10/2019, 12:27, "Michal Skrivanek" wrote: > > > >> On 2 Oct 2019, at 13:29, Vrgotic, Marko wrote: >> >> Any ideas >> >> From: "Vrgotic, Marko" >> Date: Friday, 27 September 2019 at 17:26 >> To: "users@ovirt.org" >> Subject: How to pass parameters between VDSM Hooks domxml in single run >> >> Dear oVIrt, >> >> A while ago we discussed on ways to change/update content of parameters of domxml in certain action. >> >> As I mentioned before, we have added the VDSMHook 60_nsupdate which removes the DNS record entries when a VM is destroyed: >> >> … >> domxml = hooking.read_domxml() >>name = domxml.getElementsByTagName('name')[0] >>name = " ".join(name.nodeValue for name in name.childNodes if name.nodeType == name.TEXT_NODE) >>nsupdate_commands = """server {server_ip} >> update delete {vm_name}.example.com a >> update delete {vm_name}. example.com >> update delete {vm_name}. example.com txt >> send >> """.format(server_ip="172.16.1.10", vm_name=name) >> … >> >> The goal: >> However, we did not want to execute remove dns records when VM is only migrated. Since its considered a “destroy” action we took following approach. >> • In state “before_vm_migrate_source add hook which will write flag “is_migration” to domxml >> • Once VM is scheduled for migration, this hook should add the flag “is_migration” to domxml >> • Once 60_nsupdate is triggered, it will check for the flag and if there, skip executing dns record action, but only remove the flag “is_migration” from domxml of the VM >> >> … >> domxml = hooking.read_domxml() >>migration = domxml.createElement("is_migration") >>domxml.getElementsByTagName("domain")[0].appendChild(migration) >>logging.info("domxml_updated {}".format(domxml.toprettyxml())) >>hooking.write_domxml(domxml) >> … >> >> When executing first time, we observed that flag “ >> >>hookiesvm >>fcfa66cb-b251-43a3-8e2b-f33b3024a749 >>http://ovirt.org/vm/tune/1.0"; xmlns:ns1="http://ovirt.org/vm/1.0";> >> >>http://ovirt.org/vm/1.0";> >> 4.3 >>False >> false >>1024 >>1024 >> ...skipping...
[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
Hi Michal, Thank you. Would you be so kind to provide me with additional clarification? > you can’t just add a random tag into libvirt xml in a random place, it will > be dropped by libvirt. I understand, thank you. About persistence of added tag, it was not used/written during 1xMigration, but it was present in domxml in 2xMigration. > you can add it to metadata though. we use that for ovirt-specific information Can you please provide some more HowTo/HowNotTo information? Can we manipulate the tag in metadata section in each iteration? I assume VM metadata shared/communicated between Hosts or read and provided to Hosts by oVirt-Engine? In short we are trying to achive: - start migration - ex: 10_create_tag inserts tag into XML metadata section <= maybe we can use before_vm_migration_source hook - migration is finished and after_vm_destroy hooks comes to turn: - ex: 20_nsupdate reads the metadata and: - if tag exists, do not run dns update, but remove the tag - if tag does not exists, run dns update and remove the tag Kindly awaiting your reply. Marko Vrgotic On 03/10/2019, 12:27, "Michal Skrivanek" wrote: > On 2 Oct 2019, at 13:29, Vrgotic, Marko wrote: > > Any ideas > > From: "Vrgotic, Marko" > Date: Friday, 27 September 2019 at 17:26 > To: "users@ovirt.org" > Subject: How to pass parameters between VDSM Hooks domxml in single run > > Dear oVIrt, > > A while ago we discussed on ways to change/update content of parameters of domxml in certain action. > > As I mentioned before, we have added the VDSMHook 60_nsupdate which removes the DNS record entries when a VM is destroyed: > > … > domxml = hooking.read_domxml() > name = domxml.getElementsByTagName('name')[0] > name = " ".join(name.nodeValue for name in name.childNodes if name.nodeType == name.TEXT_NODE) > nsupdate_commands = """server {server_ip} > update delete {vm_name}.example.com a > update delete {vm_name}. example.com > update delete {vm_name}. example.com txt > send > """.format(server_ip="172.16.1.10", vm_name=name) > … > > The goal: > However, we did not want to execute remove dns records when VM is only migrated. Since its considered a “destroy” action we took following approach. > • In state “before_vm_migrate_source add hook which will write flag “is_migration” to domxml > • Once VM is scheduled for migration, this hook should add the flag “is_migration” to domxml > • Once 60_nsupdate is triggered, it will check for the flag and if there, skip executing dns record action, but only remove the flag “is_migration” from domxml of the VM > > … > domxml = hooking.read_domxml() > migration = domxml.createElement("is_migration") > domxml.getElementsByTagName("domain")[0].appendChild(migration) > logging.info("domxml_updated {}".format(domxml.toprettyxml())) > hooking.write_domxml(domxml) > … > > When executing first time, we observed that flag “ > > hookiesvm > fcfa66cb-b251-43a3-8e2b-f33b3024a749 > http://ovirt.org/vm/tune/1.0"; xmlns:ns1="http://ovirt.org/vm/1.0";> > > http://ovirt.org/vm/1.0";> > 4.3 > False > false > 1024 > 1024 > ...skipping... > > > > > system_u:system_r:svirt_t:s0:c169,c575 > system_u:object_r:svirt_image_t:s0:c169,c575 > > > +107:+107 > +107:+107 > > you can’t just add a random tag into libvirt xml in a random place, it will be dropped by libvirt. you can add it to metadata though. we use that for ovirt-specific information > > is added to domxml, but was present once 60_nsupdate hook was executed. > > The question: How do we make sure that, when domxml is updated, that the update is visible/usable by following hook, in single run? How to pass these changes between hooks? > > Kindly awaiting your reply. > > > — — — > Met vriendelijke groet / Kind regards, > > Marko Vrgotic > > > ___ > Users mailing list -- users@ovirt.org > To unsubscribe send an email to users-le...@ovirt.org > Privacy Statement: https://www.ovirt.org/site/privacy-policy/ > oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ > List Archives:
[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
> On 3 Oct 2019, at 12:50, Vrgotic, Marko wrote: > > Hi Michal, > > Thank you. Would you be so kind to provide me with additional clarification? > >> you can’t just add a random tag into libvirt xml in a random place, it will >> be dropped by libvirt. > I understand, thank you. About persistence of added tag, it was not > used/written during 1xMigration, but it was present in domxml in 2xMigration. > >> you can add it to metadata though. we use that for ovirt-specific information > Can you please provide some more HowTo/HowNotTo information? > Can we manipulate the tag in metadata section in each iteration? > I assume VM metadata shared/communicated between Hosts or read and provided > to Hosts by oVirt-Engine? > In short we are trying to achive: > - start migration > - ex: 10_create_tag inserts tag into XML > metadata section <= maybe we can use before_vm_migration_source hook > - migration is finished and after_vm_destroy hooks comes to turn: > - ex: 20_nsupdate reads the metadata and: > - if tag exists, do not run dns > update, but remove the tag > - if tag does not exists, run dns > update and remove the tag so..hmm..if IIUC you basically just need not to execute dns update(remove the entry for vm) when VM migrates away. and do execute it when it shuts down. maybe i can suggest two other approaches which could work? these would be preferable because manipulating with libvirt’s xml at the time of lifecycle changes are better to be avoided. libvirt is touching the xml at the same tie and it may run into ugly locking problems. how about - use after_vm_migrate_source and make a note of that vmid (touch a file in /tmp/ or whatever), and then check that in after_vm_destroy or - use before_vm_destroy and use vdsm-client VM getStats vmid=‘xyz’ to get the curent VM’s status from vdsm (before it goes away) and you should see if it’s “Migration Source” vs anything else(Powering Down for ordinary shutdowns or Up for crashes, I guess) Thanks, michal > > Kindly awaiting your reply. > > Marko Vrgotic > > On 03/10/2019, 12:27, "Michal Skrivanek" wrote: > > > >> On 2 Oct 2019, at 13:29, Vrgotic, Marko wrote: >> >> Any ideas >> >> From: "Vrgotic, Marko" >> Date: Friday, 27 September 2019 at 17:26 >> To: "users@ovirt.org" >> Subject: How to pass parameters between VDSM Hooks domxml in single run >> >> Dear oVIrt, >> >> A while ago we discussed on ways to change/update content of parameters of >> domxml in certain action. >> >> As I mentioned before, we have added the VDSMHook 60_nsupdate which removes >> the DNS record entries when a VM is destroyed: >> >> … >> domxml = hooking.read_domxml() >>name = domxml.getElementsByTagName('name')[0] >>name = " ".join(name.nodeValue for name in name.childNodes if >> name.nodeType == name.TEXT_NODE) >>nsupdate_commands = """server {server_ip} >> update delete {vm_name}.example.com a >> update delete {vm_name}. example.com >> update delete {vm_name}. example.com txt >> send >> """.format(server_ip="172.16.1.10", vm_name=name) >> … >> >> The goal: >> However, we did not want to execute remove dns records when VM is only >> migrated. Since its considered a “destroy” action we took following approach. >> • In state “before_vm_migrate_source add hook which will write flag >> “is_migration” to domxml >> • Once VM is scheduled for migration, this hook should add the flag >> “is_migration” to domxml >> • Once 60_nsupdate is triggered, it will check for the flag and if >> there, skip executing dns record action, but only remove the flag >> “is_migration” from domxml of the VM >> >> … >> domxml = hooking.read_domxml() >>migration = domxml.createElement("is_migration") >>domxml.getElementsByTagName("domain")[0].appendChild(migration) >>logging.info("domxml_updated {}".format(domxml.toprettyxml())) >>hooking.write_domxml(domxml) >> … >> >> When executing first time, we observed that flag “ >> >>hookiesvm >>fcfa66cb-b251-43a3-8e2b-f33b3024a749 >>http://ovirt.org/vm/tune/1.0"; >> xmlns:ns1="http://ovirt.org/vm/1.0";> >> >>http://ovirt.org/vm/1.0";> >>4.3 >>> type="bool">False >>false >>> type="int">1024 >>> type="int">1024 >> ...skipping... >>> slot="0x09" type="pci"/> >> >> >> >>system_u:system_r:svirt_t:s0:c169,c575 >> >> system_u:object_r:svirt_image_t:s0:c169,c575 >> >> >>+107:+107 >>+107:+107 >> >> > >you can’t just add a random tag into libvirt xml in a random place, it > will be dropped by libvirt. >you can add it to metadata
[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
> On 2 Oct 2019, at 13:29, Vrgotic, Marko wrote: > > Any ideas > > From: "Vrgotic, Marko" > Date: Friday, 27 September 2019 at 17:26 > To: "users@ovirt.org" > Subject: How to pass parameters between VDSM Hooks domxml in single run > > Dear oVIrt, > > A while ago we discussed on ways to change/update content of parameters of > domxml in certain action. > > As I mentioned before, we have added the VDSMHook 60_nsupdate which removes > the DNS record entries when a VM is destroyed: > > … > domxml = hooking.read_domxml() > name = domxml.getElementsByTagName('name')[0] > name = " ".join(name.nodeValue for name in name.childNodes if > name.nodeType == name.TEXT_NODE) > nsupdate_commands = """server {server_ip} > update delete {vm_name}.example.com a > update delete {vm_name}. example.com > update delete {vm_name}. example.com txt > send > """.format(server_ip="172.16.1.10", vm_name=name) > … > > The goal: > However, we did not want to execute remove dns records when VM is only > migrated. Since its considered a “destroy” action we took following approach. > • In state “before_vm_migrate_source add hook which will write flag > “is_migration” to domxml > • Once VM is scheduled for migration, this hook should add the flag > “is_migration” to domxml > • Once 60_nsupdate is triggered, it will check for the flag and if > there, skip executing dns record action, but only remove the flag > “is_migration” from domxml of the VM > > … > domxml = hooking.read_domxml() > migration = domxml.createElement("is_migration") > domxml.getElementsByTagName("domain")[0].appendChild(migration) > logging.info("domxml_updated {}".format(domxml.toprettyxml())) > hooking.write_domxml(domxml) > … > > When executing first time, we observed that flag “ > > hookiesvm > fcfa66cb-b251-43a3-8e2b-f33b3024a749 > http://ovirt.org/vm/tune/1.0"; > xmlns:ns1="http://ovirt.org/vm/1.0";> > > http://ovirt.org/vm/1.0";> > 4.3 > type="bool">False > false > type="int">1024 > type="int">1024 > ...skipping... > slot="0x09" type="pci"/> > > > > system_u:system_r:svirt_t:s0:c169,c575 > > system_u:object_r:svirt_image_t:s0:c169,c575 > > > +107:+107 > +107:+107 > > you can’t just add a random tag into libvirt xml in a random place, it will be dropped by libvirt. you can add it to metadata though. we use that for ovirt-specific information > > is added to domxml, but was present once 60_nsupdate hook was executed. > > The question: How do we make sure that, when domxml is updated, that the > update is visible/usable by following hook, in single run? How to pass these > changes between hooks? > > Kindly awaiting your reply. > > > — — — > Met vriendelijke groet / Kind regards, > > Marko Vrgotic > > > ___ > Users mailing list -- users@ovirt.org > To unsubscribe send an email to users-le...@ovirt.org > Privacy Statement: https://www.ovirt.org/site/privacy-policy/ > oVirt Code of Conduct: > https://www.ovirt.org/community/about/community-guidelines/ > List Archives: > https://lists.ovirt.org/archives/list/users@ovirt.org/message/IC4J6CAJUQOSLU3ZJPX3ZHTUM4HUCMGU/ ___ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-le...@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/MHQ4VQ4IXO6GM5MOGQSHAX74SCP2QUJD/
[ovirt-users] Re: How to pass parameters between VDSM Hooks domxml in single run
Any ideas From: "Vrgotic, Marko" Date: Friday, 27 September 2019 at 17:26 To: "users@ovirt.org" Subject: How to pass parameters between VDSM Hooks domxml in single run Dear oVIrt, A while ago we discussed on ways to change/update content of parameters of domxml in certain action. As I mentioned before, we have added the VDSMHook 60_nsupdate which removes the DNS record entries when a VM is destroyed: … domxml = hooking.read_domxml() name = domxml.getElementsByTagName('name')[0] name = " ".join(name.nodeValue for name in name.childNodes if name.nodeType == name.TEXT_NODE) nsupdate_commands = """server {server_ip} update delete {vm_name}.example.com a update delete {vm_name}. example.com update delete {vm_name}. example.com txt send """.format(server_ip="172.16.1.10", vm_name=name) … The goal: However, we did not want to execute remove dns records when VM is only migrated. Since its considered a “destroy” action we took following approach. * In state “before_vm_migrate_source add hook which will write flag “is_migration” to domxml * Once VM is scheduled for migration, this hook should add the flag “is_migration” to domxml * Once 60_nsupdate is triggered, it will check for the flag and if there, skip executing dns record action, but only remove the flag “is_migration” from domxml of the VM … domxml = hooking.read_domxml() migration = domxml.createElement("is_migration") domxml.getElementsByTagName("domain")[0].appendChild(migration) logging.info("domxml_updated {}".format(domxml.toprettyxml())) hooking.write_domxml(domxml) … When executing first time, we observed that flag “ hookiesvm fcfa66cb-b251-43a3-8e2b-f33b3024a749 http://ovirt.org/vm/tune/1.0"; xmlns:ns1="http://ovirt.org/vm/1.0";> http://ovirt.org/vm/1.0";> 4.3 False false 1024 1024 ...skipping... system_u:system_r:svirt_t:s0:c169,c575 system_u:object_r:svirt_image_t:s0:c169,c575 +107:+107 +107:+107 is added to domxml, but was present once 60_nsupdate hook was executed. The question: How do we make sure that, when domxml is updated, that the update is visible/usable by following hook, in single run? How to pass these changes between hooks? Kindly awaiting your reply. — — — Met vriendelijke groet / Kind regards, Marko Vrgotic ___ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-le...@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/message/IC4J6CAJUQOSLU3ZJPX3ZHTUM4HUCMGU/