Skip to content

Commit

Permalink
initial commit of resize pool - add disk - disk role filter rockstor#…
Browse files Browse the repository at this point in the history
…1494

By examining the role of a disk we can rule it out as
a prospective pool member, or include it in the case of
an openLUKS device. These changes enable this for the
resize pool, add disk mechanism.
  • Loading branch information
phillxnet committed Nov 14, 2016
1 parent 8cb7563 commit dc4144f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/rockstor/storageadmin/static/storageadmin/js/models/models.js
Expand Up @@ -49,6 +49,40 @@ var Disk = Backbone.Model.extend({
return false;
}
return true;
},
// Using the disk.role system we can filter drives on their usability.
// Roles for inclusion: openLUKS containers
// Roles to dismiss: LUKS containers, mdraid members, the 'root' role,
// and partitioned.
// Defaults to reject (return false)
isRoleUsable: function () {
// check if our role is null = db default
// A drive with no role shouldn't present a problem for use.
var role = this.get('role');
if (role == null) {
console.log("bb DISK model: ACCEPTING ROLE OF null")
return true;
}
// try json conversion and return false if it fails
// @todo not sure if this is redundant?
try {
var roleAsJson = JSON.parse(role);
} catch (e) {
// as we can't read this drives role we play save and exclude
// it's isRoleUsable status by false
return false;
}
// We have a json object, look for acceptable roles in the keys
//
// Accept use of 'openLUKS' device
if (roleAsJson.hasOwnProperty('openLUKS')) {
console.log("bb DISK model: ACCEPTING ROLE OF openLUKS json = " + role);
return true;
}
// In all other cases return false, ie:
// reject roles of for example root, mdraid, LUKS, partitioned etc
console.log("bb DISK model: REJECTING ROLE with json = " + role);
return false;
}
});

Expand Down
Expand Up @@ -63,8 +63,8 @@ AddPoolView = Backbone.View.extend({
isRoleUsable(disk.get('role'));
});

// N.B. the isSerialUsable() code below is now duplicated in the
// Backbone Disk model as the property isSerialUsable()
// N.B. isSerialUsable() and isRoleUsable() are duplicated in the
// Backbone Disk model as the property isSerialUsable() isRoleUsable()
// storageadmin/static/storageadmin/js/models/models.js
// It would be better not to have this duplication if possible.
function isSerialUsable(diskSerialNumber) {
Expand Down
Expand Up @@ -50,7 +50,7 @@ PoolAddDisks = RockstorWizardPage.extend({

renderDisks: function () {
var disks = this.disks.filter(function (disk) {
return disk.available() && disk.isSerialUsable();
return disk.available() && disk.isSerialUsable() && disk.isRoleUsable();
}, this);
//convert the array elements which are backbone models/collections to JSON object
for (var i = 0; i < disks.length; i++) {
Expand Down

0 comments on commit dc4144f

Please sign in to comment.