• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Delete/Remove fog images via API

    Scheduled Pinned Locked Moved Unsolved
    FOG Problems
    3
    4
    491
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      typotony
      last edited by

      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.

      george1421G JJ FullmerJ 2 Replies Last reply Reply Quote 0
      • george1421G
        george1421 Moderator @typotony
        last edited by

        @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.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!

        T 1 Reply Last reply Reply Quote 0
        • T
          typotony @george1421
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • JJ FullmerJ
            JJ Fullmer Testers @typotony
            last edited by

            @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

            Remove-FogObject

            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.

            Have you tried the FogApi powershell module? It's pretty cool IMHO
            https://github.com/darksidemilk/FogApi
            https://fogapi.readthedocs.io/en/latest/
            https://www.powershellgallery.com/packages/FogApi
            https://forums.fogproject.org/topic/12026/powershell-api-module

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            144

            Online

            12.0k

            Users

            17.3k

            Topics

            155.2k

            Posts
            Copyright © 2012-2024 FOG Project