Carrying on from Part 3...
We need to get the time. Here we get the cluster time. It is important to use the cluster time, because your Python client might be in a different timezone. The snapshots use a time naming convention, with the time set by the ONTAP cluster.
(Random thought ... what happens if you have daylight savings clock change ... we'll cross that bridge later ...) (or are ONTAP snapshots names always UTC ... see below)
How to Get ONTAP Cluster Current Time in Python
Below is the input into my Python CLI, showing how to get the day, hour, minute, month and year:
from netapp_ontap import config, HostConnection
from netapp_ontap.resources import Cluster
conn = HostConnection(
host="CLUSTERNAME",
username="LOGIN_USER",
password="LOGIN_PASSWORD",
verify=False # Set to True if you have valid SSL cert
)
config.CONNECTION = conn
clus = Cluster()
clus.get()
clus.timezone
clus.statistics
clus.statistics.timestamp
clus.statistics.timestamp.day
clus.statistics.timestamp.hour
clus.statistics.timestamp.minute
clus.statistics.timestamp.month
clus.statistics.timestamp.year
The outputs are below:
datetime.datetime(2025, 4, 19, 19, 12, 25, tzinfo=datetime.timezone.utc)
19 #day
19 #hour
12 #minute
4 #month
2025 #year
Now we have time and date from the cluster.
After doing this, it crossed my mind that snapshots might use UTC, and checking, that seems to be so:
"By design OSM default snapshot name contains UTC timestamp irrespective of cluster timezone"
Which kinda makes sense. Changing timezone won't change the snapshot names. And no issues with daylight savings changes. So we could just get standard UTC time from Python. How do we do this?
How to Get UTC Time in Python
This is easy:
from datetime import datetime, timezone
datetime.now(timezone.utc)
datetime.now(timezone.utc).day
datetime.now(timezone.utc).hour
datetime.now(timezone.utc).minute
datetime.now(timezone.utc).month
datetime.now(timezone.utc).yer
But it occurred to me that we don't want to use this, we want to get the cluster time as UTC (in case there is time drift between the ONTAP cluster and our Python client.) How do we do this?
ONTAP Cluster Statistics Timestamp is UTC!
On my lab system - which was using UTC - I change the timezone to Australia/Tasmania but the statistics.timestamp still had timezone UTC. Screenshot below:
Comments
Post a Comment