Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding funtionality for setting "writable" for a snapshot scheduler in the GUI. #1434

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/rockstor/fs/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ def remove_snap(pool, share_name, snap_name):
return run_command([BTRFS, 'subvolume', 'delete', snap], log=True)


def add_snap_helper(orig, snap, readonly=False):
def add_snap_helper(orig, snap, writable):
cmd = [BTRFS, 'subvolume', 'snapshot', orig, snap]
if (readonly):
if (not writable):
cmd.insert(3, '-r')
try:
return run_command(cmd)
Expand All @@ -524,10 +524,10 @@ def add_clone(pool, share, clone, snapshot=None):
else:
orig_path = ('%s/%s' % (orig_path, share))
clone_path = ('%s/%s' % (pool_mnt, clone))
return add_snap_helper(orig_path, clone_path)
return add_snap_helper(orig_path, clone_path, True)


def add_snap(pool, share_name, snap_name, readonly=False):
def add_snap(pool, share_name, snap_name, writable):
"""
create a snapshot
"""
Expand All @@ -536,7 +536,7 @@ def add_snap(pool, share_name, snap_name, readonly=False):
snap_dir = ('%s/.snapshots/%s' % (root_pool_mnt, share_name))
create_tmp_dir(snap_dir)
snap_full_path = ('%s/%s' % (snap_dir, snap_name))
return add_snap_helper(share_full_path, snap_full_path, readonly)
return add_snap_helper(share_full_path, snap_full_path, writable)


def rollback_snap(snap_name, sname, subvol_name, pool):
Expand Down
5 changes: 4 additions & 1 deletion src/rockstor/scripts/scheduled_tasks/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def validate_snap_meta(meta):
raise Exception('max_count must atleast be 1, not %d' % max_count)
if ('visible' not in meta or type(meta['visible']) != bool):
meta['visible'] = False
if ('writable' not in meta or type(meta['writable']) != bool):
meta['writable'] = False
return meta


Expand Down Expand Up @@ -100,7 +102,8 @@ def main():
#runaway snapshot creation beyond max_count+1.
if(delete(aw, share, stype, prefix, max_count)):
data = {'snap_type': stype,
'uvisible': meta['visible'], }
'uvisible': meta['visible'],
'writable': meta['writable'], }
headers = {'content-type': 'application/json'}
aw.api_call(url, data=data, calltype='post', headers=headers, save_error=False)
logger.debug('created snapshot at %s' % url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ var TaskDef = Backbone.Model.extend({
return false;
}
},
writable: function () {
if (this.get('json_meta') != null) {
return JSON.parse(this.get('json_meta')).writable;
} else {
return false;
}
},


});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,19 @@ $(document).ready(function() {
<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<div class="checkbox">
<label>
<input class="checkbox" type="checkbox" id="visible" name="meta.visible" {{#if taskObj.visible}} checked="true" {{/if}} title="Make snapshots visible to the end user"> Make snapshots visible?
</label>
<label>
<input class="checkbox" type="checkbox" id="writable" name="meta.writable" {{#if taskObj.writable}} checked="true" {{/if}} title="Make snapshots writable"> Make snapshots writable?
</label>
</div>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<div class="checkbox">
<label>
<input class="checkbox" type="checkbox" id="visible" name="meta.visible" {{#if taskObj.visible}} checked="true" {{/if}} title="Make snapshots visible to the end user"> Make snapshots visible?
</label>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<input class="form-control col-sm-4" type="text" id="max_count" name="meta.max_count" {{#unless taskDefIdNull}} value="{{taskMaxCount}}" {{/unless}} placeholder="Maximum count" title="Older snapshots beyond this number and created by this task will be deleted">
</div>
</div>
<div class="checkbox" style="clear: both">
<label>
<input type="checkbox" checked="true" id="writable" name="meta.writable" title="Make snapshots writable.">
Make snapshots writable?
</label>
</div>
<div class="checkbox" style="clear: both">
<label>
<input type="checkbox" checked="true" id="visible" name="meta.visible" title="Make snapshots visible to the end user.">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
</div>

<div class="form-group">
<label class="col-xs-4 control-label" for=writable">Writable<span class="required"> *</span></label>
<label class="col-xs-4 control-label" for="snapshot-writable"> </label>
<div class="col-sm-4">
{{display_writeable_options}}
<input type="checkbox" name="writable" id="snapshot-writable" title="Snapshots can be made writable by selecting this checkbox"> Writable?
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ AddScheduledTaskView = RockstorLayoutView.extend({
pool: this.taskDef.pool(),
maxCount: this.taskDef.max_count(),
visible: this.taskDef.visible(),
writable: this.taskDef.writable(),
enabled: this.taskDef.get('enabled'),
};
var isSnapshot = false;
Expand Down
3 changes: 1 addition & 2 deletions src/rockstor/storageadmin/views/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def _create(self, share, snap_name, request, uvisible, snap_type, writable):
qgroup_id = '0/na'
if (snap_type == 'replication'):
writable = False
add_snap(share.pool, share.subvol_name, snap_name, readonly=not
writable)
add_snap(share.pool, share.subvol_name, snap_name, writable)
snap_id = share_id(share.pool, snap_name)
qgroup_id = ('0/%s' % snap_id)
qgroup_assign(qgroup_id, share.pqgroup, ('%s/%s' % (settings.MNT_PT, share.pool.name)))
Expand Down