[pve-devel] [PATCH manager v2 05/11] fix #1465: use a combobox for the crush rule instead of the id

Dominik Csapak d.csapak at proxmox.com
Mon Jul 31 15:15:27 CEST 2017


this patch does a few things

1. we introduce a new api call /nodes/nodename/ceph/rules
   which gets us a list of crush rules

2. we introduce a new CephRuleSelector which is a simple combobox
   with the data from the api call ceph/rules

3. we use this in the create pool window

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* fix typos in commit message
* fix intendation
* load first entry in combobox by default
 PVE/API2/Ceph.pm            | 41 ++++++++++++++++++++++++++++++
 www/manager6/ceph/Pool.js   | 61 ++++++++++++++++++++++++++++++++++++++-------
 www/manager6/window/Edit.js |  4 +--
 3 files changed, 95 insertions(+), 11 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index a5ef3a86..7b520357 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -580,6 +580,7 @@ __PACKAGE__->register_method ({
 	    { name => 'log' },
 	    { name => 'disks' },
 	    { name => 'flags' },
+	    { name => 'rules' },
 	];
 
 	return $result;
@@ -1842,4 +1843,44 @@ __PACKAGE__->register_method({
 	return $lines;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'rules',
+    path => 'rules',
+    method => 'GET',
+    description => "List ceph rules.",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Audit', 'Datastore.Audit' ], any => 1],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{name}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::CephTools::check_ceph_inited();
 
+	my $rados = PVE::RADOS->new();
+
+	my $rules = $rados->mon_command({ prefix => 'osd crush rule ls' });
+
+	my $res = [];
+
+	foreach my $rule (@$rules) {
+	    push @$res, { name => $rule };
+	}
+
+	return $res;
+    }});
diff --git a/www/manager6/ceph/Pool.js b/www/manager6/ceph/Pool.js
index 0cec0dc1..7757c307 100644
--- a/www/manager6/ceph/Pool.js
+++ b/www/manager6/ceph/Pool.js
@@ -31,12 +31,9 @@ Ext.define('PVE.CephCreatePool', {
 	    allowBlank: false
 	},
 	{
-	    xtype: 'pveIntegerField',
-	    fieldLabel: 'Crush RuleSet', // do not localize
-	    name: 'crush_ruleset',
-	    value: 0,
-	    minValue: 0,
-	    maxValue: 32768,
+	    xtype: 'pveCephRuleSelector',
+	    fieldLabel: 'Crush Rule', // do not localize
+	    name: 'crush_rule',
 	    allowBlank: false
 	},
 	{
@@ -57,8 +54,11 @@ Ext.define('PVE.CephCreatePool', {
 	    throw "no node name specified";
 	}
 
-        Ext.applyIf(me, {
-	    url: "/nodes/" + me.nodename + "/ceph/pools"
+        Ext.apply(me, {
+	    url: "/nodes/" + me.nodename + "/ceph/pools",
+	    defaults: {
+		nodename: me.nodename
+	    }
         });
 
         me.callParent();
@@ -205,8 +205,51 @@ Ext.define('PVE.node.CephPoolList', {
 		  { name: 'pg_num', type: 'integer'},
 		  { name: 'bytes_used', type: 'integer'},
 		  { name: 'percent_used', type: 'number'},
-		  { name: 'crush_ruleset', type: 'integer'}
+		  { name: 'crush_rule', type: 'integer'},
 		],
 	idProperty: 'pool_name'
     });
 });
+
+Ext.define('PVE.form.CephRuleSelector', {
+    extend: 'Ext.form.field.ComboBox',
+    alias: 'widget.pveCephRuleSelector',
+
+    allowBlank: false,
+    valueField: 'name',
+    displayField: 'name',
+    editable: false,
+    queryMode: 'local',
+
+    initComponent: function() {
+	var me = this;
+
+	if (!me.nodename) {
+	    throw "no nodename given";
+	}
+
+	var store = Ext.create('Ext.data.Store', {
+	    fields: ['name'],
+	    sorters: 'name',
+	    proxy: {
+		type: 'pve',
+		url: '/api2/json/nodes/' + me.nodename + '/ceph/rules'
+	    }
+	});
+
+	Ext.apply(me, {
+	    store: store,
+	});
+
+	me.callParent();
+
+	store.load({
+	    callback: function(rec, op, success){
+		if (success && rec.length > 0) {
+		    me.select(rec[0]);
+		}
+	    }
+	});
+    }
+
+});
diff --git a/www/manager6/window/Edit.js b/www/manager6/window/Edit.js
index 972d57fb..9a026683 100644
--- a/www/manager6/window/Edit.js
+++ b/www/manager6/window/Edit.js
@@ -202,9 +202,9 @@ Ext.define('PVE.window.Edit', {
 	    trackResetOnLoad: true,
 	    bodyPadding: 10,
 	    border: false,
-	    defaults: {
+	    defaults: Ext.apply({}, me.defaults, {
 		border: false
-	    },
+	    }),
 	    fieldDefaults: Ext.apply({}, me.fieldDefaults, {
 		labelWidth: 100,
 		anchor: '100%'
-- 
2.11.0





More information about the pve-devel mailing list