I have an OpenStack cluster and I want to write a python script automatically set the retirement date for each VM.The retirement rule is to retire a VM on the 365th day since it is created.I am an admin and providing a private cloud to all faculties and students.They might create one VM and forget to turn it off, that is why I want to set the retirement date for each VM.
Here are the steps in my script:
Step One: access API/VMS to get all the VM id
Step Two: with the id, access API/VMS/id use IF statement to check whether it has retirement date or raw_power_state is “Unknown”.The second one will indicate that this VM had been created but removed.If none of them statement has met, then run curl command to post retire action on that VM with the id
I am going make this script to run every day but I think it is very low efficiency.
First, is there ways to quickly to know which VMs have not been given a retirement date?
Second, is there any way to remove VMs which had been created but removed? I found out that from API/VMS, it will display all the VMs including the one I mentioned.
Or, any good ideas to automatically set retirement date for each VMs