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

Dominik Csapak d.csapak at proxmox.com
Mon Jul 31 11:28:37 CEST 2017


this patchs 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 introdcue 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>
---
 PVE/API2/Ceph.pm            | 41 +++++++++++++++++++++++++++++++++
 www/manager6/ceph/Pool.js   | 56 +++++++++++++++++++++++++++++++++++++--------
 www/manager6/window/Edit.js |  4 ++--
 3 files changed, 90 insertions(+), 11 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index c7390981..8644de85 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -578,6 +578,7 @@ __PACKAGE__->register_method ({
 	    { name => 'log' },
 	    { name => 'disks' },
 	    { name => 'flags' },
+	    { name => 'rules' },
 	];
 
 	return $result;
@@ -1840,4 +1841,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..4eedb8b5 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,46 @@ 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,
+	    autoSelect: false
+	});
+
+        me.callParent();
+
+	store.load();
+    }
+
+});
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