Forum Discussion

Leonardo_Silva1's avatar
Leonardo_Silva1
Icon for Altostratus rankAltostratus
Jun 22, 2021

Big-IQ snapshot management

Hello community, I have an interesting situation that I want to run by you guys and hopefully somebody/someone can give me a hand.

 

We have in our environment 20 Big-IQ devices, handling nearly 500 devices (between LTMs, ASMs, DNSs and combination of them).

 

Internally we have configured Big-IQs to trigger snapshots for all of them, the only difference we have is that we only keep snapshot files storaged in the Big-IQ is for ASMs. The rest of the modules keep their snapshots locally.

 

Now, we want (need) to create a python script (basically because we make it run from a 3rd party solution that ssh into the Big-IQs and run that python script) to delete snapshots older than 30 days, for example.

 

For that purpose, I have searched for several documentation regarding API for snapshot management on Big IQ , basically there are 2 API calls relevant for me:

 

1.- Snapshot checkup: GET /cm/<module>/tasks/snapshot-config/<id>

2.- Snapshot deletion: DELETE mgmt/cm/<module>/tasks/snapshot-config/<id>

 

Now the values between <>, which are: 'module' and 'id', in our case module = asm and 'id' is for the snapshot we want to checkup and delete if meets the criteria.

 

The thing here is that, we do not have any 'id' number, because the snapshots are created by several business units outside our team, where they log into the Big-IQ's GUI and deploy the snapshot manually.

 

I have tried to send a GET request (via POSTMAN) using these variations (hoping some sort of response):

  • GET /cm/<module>/tasks/snapshot-config/
  • GET /cm/<module>/tasks/snapshot-config/*

 

But logically is expecting the 'id' value so it shoots back an error.

 

NOTE: the 'id' is provided when you try the API call for snapshot creation: POST mgmt/cm/<module>/tasks/snapshot-config.

That particular POST, only request the name of the snapshot as parameter and then provides the precious 'id' in return.

 

So you can see my dilemma and where I am missing data.

 

QUESTIONS:

1.- Is there any way to fetch the 'id' using any resource?

2.- where exactly is located the repository for these snapshots in the Big-IQ? I mean the Linux's bash prompt for each Big-IQ, I have searched and searched but I haven't found them... This would be a great peace of information.

3.- Is this the right approach? I found some information about 'restcurl' but I am not completely sure about this resource.

 

Thanks.-

3 Replies

  • With the help of the f5 support team, we were able to pinpoint and successfully execute the python script we intended to accomplish this task.

     

    For those of you that might encounter this issue (or similar) I'll post here the solution I created to run Bash commands from python script.

     

    Basically the task was to (via python) list all the ASM snapshots, select the ones older than 90 days and the delete them.

     

    Since the solution for listing ASM's snapshots was to use the following f5's Bash command:

     

    #restcurl -u admin:admin /cm/asm/tasks/snapshot-config/?\$select=endDateTime,id

     

    Of course, in a python script you cannot use the above command as it is, you need to create a command structure using subprocess library for which we figure this out:

     

  • #creating string which will be the first argument for subprocess.Popen below
    fetch_id = "restcurl -u admin:admin /cm/asm/tasks/snapshot-config/?\$select=endDateTime,id"
     
    #Running the subprocess.Popen method, will create a dictionary of all the snapshots IDs:
    snapshot_d = subprocess.Popen(fetch_id, stdout=subprocess.PIPE, shell=True).stdout.read()
  • After this, we figured which snapshots are older than 90 days and we performed the following:

    #Building up the 'restcurl' command for deletion
    restcurl_delete = "restcurl -u admin:admin -d '{'items':[" + json.dumps(ids_to_delete) + "]}' -X DELETE /cm/asm/tasks/snapshot-config/"
     
    #Here is the subprocess in action, to delete IDs one by one
    delete_command = subprocess.Popen(restcurl_delete, stdout=subprocess.PIPE, shell=True).stdout.read()

    We added a few 'prints' here and there within the .py script, to make sure the snapshot were deleted.

    Anyway, I hope this can help someone, not only for this particular case, you can use it as a guide for python scripts where you cannot use the REST API calls against the Big-IQ or Big-IP, instead you have to execute Bash commands against the boxes for some particular reason.

    Good luck!