diff --git a/config/create_help.txt b/config/create_help.txt index 6efb6e1c..ec343ce2 100644 --- a/config/create_help.txt +++ b/config/create_help.txt @@ -119,6 +119,9 @@ Create Snapshot Schedule: 3. To create snapshot every quarter, specify x as "0 * * 3,6,9,12 *" 4. To create snapshot on Monday, Wednesday and Friday, specify x as "0 * * * 1,3,5" -o scheduleName=x This option is mandatory. x is a string which indicates name for the schedule on 3PAR. + Note: When this parameter is passed with string 'auto' , then the scheduleName is + auto generated with a timestamp. This is to support kubernetes environment where + this parameter can be used as a storage class option. -o snapshotPrefix=x This option is mandatory. x is prefix string for the scheduled snapshots which will get created on 3PAR. It is recommended to use 3 letter string. If prefix is abc then name of the snapshot which gets created on the 3PAR will be in the format abc.@y@@m@@d@@H@@M@@S@ diff --git a/hpedockerplugin/hpe_storage_api.py b/hpedockerplugin/hpe_storage_api.py index 21493589..36ff5e3c 100644 --- a/hpedockerplugin/hpe_storage_api.py +++ b/hpedockerplugin/hpe_storage_api.py @@ -19,6 +19,7 @@ """ import json import six +import datetime from oslo_log import log as logging @@ -608,6 +609,9 @@ def volumedriver_create_snapshot(self, name, mount_conflict_delay, response = json.dumps({'Err': msg}) return response schedName = str(contents['Opts']['scheduleName']) + if schedName == "auto": + schedName = self.generate_schedule_with_timestamp() + snapPrefix = str(contents['Opts']['snapshotPrefix']) schedNameLength = len(schedName) @@ -635,6 +639,16 @@ def volumedriver_create_snapshot(self, name, mount_conflict_delay, has_schedule, schedFrequency) + def generate_schedule_with_timestamp(self): + current_time = datetime.datetime.now() + current_time_str = str(current_time) + space_replaced = current_time_str.replace(' ', '_') + colon_replaced = space_replaced.replace(':', '_') + hypen_replaced = colon_replaced.replace('-', '_') + scheduleNameGenerated = hypen_replaced + LOG.info(' Schedule Name auto generated is %s' % scheduleNameGenerated) + return scheduleNameGenerated + @app.route("/VolumeDriver.Mount", methods=["POST"]) def volumedriver_mount(self, name): """