Cisco HyperFlex Datastore Cleanup for Cisco HyperFlex utilizes the HyperFlex API to automatically delete any datastores that have met or exceeded a specified retention time limit. The ability to exempt any datastores from the retention time limit is provided.
This tool is intended for use on Cisco HyperFlex systems in demonstration or training environments. Do not use on production systems.
git clone https://github.com/ugo-emekauwa/hx-datastore-cleanup
python -m pip install -r requirements.txt
###################### # Required Variables # ######################
hx_admin
with the username of the credentials that will be used to access the targeted Cisco HyperFlex system. The value must be a string. For example, here is an entry that sets the username to admin:
hx_admin = "admin"
hx_password
with the password of the credentials that will be used to access the targeted Cisco HyperFlex system. The value must be a string. For example, here is an entry that sets the password to C1sco12345:
hx_password = "C1sco12345"
hx_connect_ip
with the IP address of the targeted Cisco HyperFlex system. The value must be a string. For example, here is an entry that sets the IP address to 192.168.1.100:
hx_connect_ip = "192.168.1.100"
hx_datastore_retention_time_limit_hours
with the maximum number of hours that a newly created or pre-existing datastore can be retained on the Cisco HyperFlex system before deletion. The value must be an integer. For example, here is an entry that sets the retention time limit to 24 hours:
hx_datastore_retention_time_limit_hours = 24
hx_exempted_datastores_list
by providing the names of any datastores that will be exempt from the retention time limit. The values must be strings separated by commas within the parentheses of the provided empty tuple ()
. For example, here is a sample entry that exempts three datastores from the retention time limit:
hx_exempted_datastores_list = ("datastore1", "datastore2", "datastore3")
hx_exempted_datastores_list = ("datastore1")
After fulfilling the requirements listed in the Prerequisites and Getting Started sections, run hx_datastore_cleanup.py directly from your IDE or from the command line e.g.:
python hx_datastore_cleanup.py
Here is an example of the output from hx_datastore_cleanup.py in which the datastores named datastore1 and datastore2 on the targeted HyperFlex cluster are exempt and no other datastores are present.
All of the available datastores on the targeted HyperFlex cluster are listed with information regarding the size, creation time and age. The datastore retention time limit set is 2 hours. No datastores need to be cleaned up at this time. The exemption of datastore1 and datastore2 is accomplished with the following entries in hx_exempted_datastores_list:
hx_exempted_datastores_list = ("datastore1", "datastore2")
To test hx_datastore_cleanup.py, here two test datastores named test_datastore1 and test_datastore2 have been created in HX Connect on a targeted HyperFlex cluster.
After waiting over 2 hours for the datastore retention time limit to be met or exceeded, here is an example of the output after re-running hx_datastore_cleanup.py.
As the above screenshot shows, the datastores named test_datastore1 and test_datastore2 were deleted due to their age exceeding the set datastore retention time limit of 2 hours. Also, test_datastore1 and test_datastore2 were not in the exemption list.
The datastores named datastore1 and datastore2 are not deleted, regardless of their age, due to being listed in the exemption list.
If using a task scheduler to run Cisco HyperFlex Datastore Cleanup, a version that has been modified to output to a log file is available in the logging-version folder of this repository as hx_datastore_cleanup_logging.py.
Usage instructions for hx_datastore_cleanup_logging.py are the same as hx_datastore_cleanup.py, however the log file location needs to be set. To set the log file location, go to the comment section named Required Variables and set the value of the variable named log_file
with the file path location of the log file. The value must be a string. For example, here is an entry that sets the log file location to "c:\Logs\hx_datastore_cleanup_logging.log" on a Windows file system:
log_file = "c:\\Logs\\hx_datastore_cleanup_logging.log"
The Cisco HyperFlex Datastore Cleanup tool is part of the automation solution used to support and maintain the following Cisco Data Center product demonstrations on Cisco dCloud:
Cisco dCloud is available at https://dcloud.cisco.com, where product demonstrations and labs can be found in the Catalog.
Here are similar tools to help manage Cisco HyperFlex training, demonstration and development environments.
Ugo Emekauwa
Owner
Contributors
Categories
Products
IntersightProgramming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community