Skip to content

Commit

Permalink
Merge pull request #429 from wdurairaj/auto_schedule_name_generate
Browse files Browse the repository at this point in the history
Fix duplicate schedule name when -o scheduleName is passed in SC (issue #390)
  • Loading branch information
wdurairaj authored Nov 20, 2018
2 parents 57e7129 + cf3277f commit d70e862
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/create_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down
14 changes: 14 additions & 0 deletions hpedockerplugin/hpe_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""
import json
import six
import datetime

from oslo_log import log as logging

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit d70e862

Please sign in to comment.