Delete/Remove fog images via API
-
Hi Fog Team,
Is it possible to delete image definitions through the fog api? My issue is that I can remote into the fog server on another site but since I don’t have access to the gui I can’t delete the image. This is mainly for remote administration of these things and to have a clean and updated image repository.
Being able to create a script for a weekly/monhtly purge of images is great as well. I understand that this won’t remove the image dir from /images and thats okay but I am hoping to delete it from the menu, if possible.
Any information is great. Thanks again.
-
@typotony Hi, I can say much of the API because I don’t use it, but it seems from the quick docs on it there is a image delete function https://news.fogproject.org/simplified-api-documentation/
/fog/image/<IDOFOBJECT>/delete
A forum member @JJ-Fullmer has more skills with the API than I do.
-
This post is deleted! -
@typotony Sorry I’m late to the party.
I haven’t built a “helper” command yet for removing fog images, but I do have Get-FogImages
https://fogapi.readthedocs.io/en/latest/commands/Get-FogImages/
If you setup the fogapi powershell module, you can use that to get a list of the current images.
You can delete the records of the fog images from the database via
i.e. this would delete ALL your images
$images = get-fogimages $images | Foreach-object { Remove-fogobject -type object -coreObject image -idofobject $_.data.id }
That little snippet is untested but should be enough to get you started.
I’m pretty sure the api command won’t remove the files from the server though.
However, I believe the path to the files, or at least the relative path is in a child property of the data property when you run Get-FogImages.
So if you set this up to run on the linux based fog server using the powershell api module, you could script something that runs in a cronjob to delete from the database and then the files.i.e. (again untested as I’m away from my test environment, so the property names are guesses, but it should point you in the right direction)
Get-FogImages | % { if ($_.data.name -eq "removeMe") { Remove-fogobject -type object -coreObject image -idofobject $_.data.id rm -fr $_.data.path } }
This, if run on the fog server where you have configured the fogapi module (see my signature for doc links), would find images named “removeMe” and then delete them from the database and then the files from the server.