[pve-devel] [PATCH v3 pve-manager 3/5] add sdn ipams

Alexandre Derumier aderumier at odiso.com
Mon Jul 20 18:01:19 CEST 2020


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager6/Makefile                 |   5 +
 www/manager6/Utils.js                 |  25 +++++
 www/manager6/dc/Config.js             |   8 ++
 www/manager6/form/SDNIpamSelector.js  |  52 ++++++++++
 www/manager6/sdn/IpamView.js          | 131 ++++++++++++++++++++++++++
 www/manager6/sdn/SubnetEdit.js        |   7 ++
 www/manager6/sdn/SubnetView.js        |   7 +-
 www/manager6/sdn/ipams/Base.js        |  73 ++++++++++++++
 www/manager6/sdn/ipams/NetboxEdit.js  |  47 +++++++++
 www/manager6/sdn/ipams/PhpIpamEdit.js |  53 +++++++++++
 10 files changed, 407 insertions(+), 1 deletion(-)
 create mode 100644 www/manager6/form/SDNIpamSelector.js
 create mode 100644 www/manager6/sdn/IpamView.js
 create mode 100644 www/manager6/sdn/ipams/Base.js
 create mode 100644 www/manager6/sdn/ipams/NetboxEdit.js
 create mode 100644 www/manager6/sdn/ipams/PhpIpamEdit.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 48924674..e6bf8647 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -100,6 +100,7 @@ JSSRC= 							\
 	form/QemuBiosSelector.js			\
 	form/SDNControllerSelector.js			\
 	form/SDNZoneSelector.js				\
+	form/SDNIpamSelector.js				\
 	form/ScsiHwSelector.js				\
 	form/SecurityGroupSelector.js			\
 	form/SnapshotSelector.js			\
@@ -213,6 +214,10 @@ JSSRC= 							\
 	sdn/ZoneView.js					\
 	sdn/controllers/Base.js				\
 	sdn/controllers/EvpnEdit.js			\
+        sdn/IpamView.js                                 \
+        sdn/ipams/Base.js                               \
+        sdn/ipams/NetboxEdit.js                         \
+        sdn/ipams/PhpIpamEdit.js                        \
 	sdn/zones/Base.js				\
 	sdn/zones/EvpnEdit.js				\
 	sdn/zones/QinQEdit.js				\
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index bf9ceda9..f8560584 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -801,6 +801,23 @@ Ext.define('PVE.Utils', { utilities: {
 	},
     },
 
+    sdnipamSchema: {
+	ipam: {
+	     name: 'ipam',
+	     hideAdd: true
+	},
+	netbox: {
+	    name: 'Netbox',
+	    ipanel: 'NetboxInputPanel',
+	    faIcon: 'th'
+	},
+	phpipam: {
+	    name: 'PhpIpam',
+	    ipanel: 'PhpIpamInputPanel',
+	    faIcon: 'th'
+	},
+    },
+
     format_sdnvnet_type: function(value, md, record) {
 	var schema = PVE.Utils.sdnvnetSchema[value];
 	if (schema) {
@@ -825,6 +842,14 @@ Ext.define('PVE.Utils', { utilities: {
 	return Proxmox.Utils.unknownText;
     },
 
+    format_sdnipam_type: function(value, md, record) {
+	var schema = PVE.Utils.sdnipamSchema[value];
+	if (schema) {
+	    return schema.name;
+	}
+	return Proxmox.Utils.unknownText;
+    },
+
     format_storage_type: function(value, md, record) {
 	if (value === 'rbd') {
 	    value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
diff --git a/www/manager6/dc/Config.js b/www/manager6/dc/Config.js
index 610b38db..f92bb24b 100644
--- a/www/manager6/dc/Config.js
+++ b/www/manager6/dc/Config.js
@@ -184,6 +184,14 @@ Ext.define('PVE.dc.Config', {
 		    hidden: true,
 		    iconCls: 'fa fa-network-wired',
 		    itemId: 'sdnsubnet'
+		},
+		{
+		    xtype: 'pveSDNIpamView',
+		    groups: ['sdn'],
+		    title: gettext('Ipams'),
+		    hidden: true,
+		    iconCls: 'fa fa-network-wired',
+		    itemId: 'sdnipam'
 		});
 	    }
 
diff --git a/www/manager6/form/SDNIpamSelector.js b/www/manager6/form/SDNIpamSelector.js
new file mode 100644
index 00000000..5520d0fe
--- /dev/null
+++ b/www/manager6/form/SDNIpamSelector.js
@@ -0,0 +1,52 @@
+Ext.define('PVE.form.SDNIpamSelector', {
+    extend: 'Proxmox.form.ComboGrid',
+    alias: ['widget.pveSDNIpamSelector'],
+
+    allowBlank: false,
+    valueField: 'ipam',
+    displayField: 'ipam',
+
+    initComponent: function() {
+	var me = this;
+
+	var store = new Ext.data.Store({
+	    model: 'pve-sdn-ipam',
+            sorters: {
+                property: 'ipam',
+                order: 'DESC'
+            },
+	});
+
+	Ext.apply(me, {
+	    store: store,
+	    autoSelect: false,
+            listConfig: {
+		columns: [
+		    {
+			header: gettext('Ipam'),
+			sortable: true,
+			dataIndex: 'ipam',
+			flex: 1
+		    },
+		]
+	    }
+	});
+
+        me.callParent();
+
+	store.load();
+    }
+
+}, function() {
+
+    Ext.define('pve-sdn-ipam', {
+	extend: 'Ext.data.Model',
+	fields: [ 'ipam' ],
+	proxy: {
+            type: 'proxmox',
+	    url: "/api2/json/cluster/sdn/ipams"
+	},
+	idProperty: 'ipam'
+    });
+
+});
diff --git a/www/manager6/sdn/IpamView.js b/www/manager6/sdn/IpamView.js
new file mode 100644
index 00000000..605f44c7
--- /dev/null
+++ b/www/manager6/sdn/IpamView.js
@@ -0,0 +1,131 @@
+Ext.define('PVE.sdn.IpamView', {
+    extend: 'Ext.grid.GridPanel',
+    alias: ['widget.pveSDNIpamView'],
+
+    stateful: true,
+    stateId: 'grid-sdn-ipam',
+
+    createSDNEditWindow: function(type, sid) {
+	let schema = PVE.Utils.sdnipamSchema[type];
+	if (!schema || !schema.ipanel) {
+	    throw "no editor registered for ipam type: " + type;
+	}
+
+	Ext.create('PVE.sdn.ipams.BaseEdit', {
+	    paneltype: 'PVE.sdn.ipams.' + schema.ipanel,
+	    type: type,
+	    ipam: sid,
+	    autoShow: true,
+	    listeners: {
+		destroy: this.reloadStore
+	    }
+	});
+    },
+
+    initComponent : function() {
+	let me = this;
+
+	let store = new Ext.data.Store({
+	    model: 'pve-sdn-ipam',
+	    proxy: {
+                type: 'proxmox',
+		url: "/api2/json/cluster/sdn/ipams"
+	    },
+	    sorters: {
+		property: 'ipam',
+		order: 'DESC'
+	    },
+	});
+
+	let reload = function() {
+	    store.load();
+	};
+
+	let sm = Ext.create('Ext.selection.RowModel', {});
+
+	let run_editor = function() {
+	    let rec = sm.getSelection()[0];
+	    if (!rec) {
+		return;
+	    }
+	    let type = rec.data.type,
+	        ipam = rec.data.ipam;
+
+	    me.createSDNEditWindow(type, ipam);
+	};
+
+	let edit_btn = new Proxmox.button.Button({
+	    text: gettext('Edit'),
+	    disabled: true,
+	    selModel: sm,
+	    handler: run_editor
+	});
+
+	let remove_btn = Ext.create('Proxmox.button.StdRemoveButton', {
+	    selModel: sm,
+	    baseurl: '/cluster/sdn/ipams/',
+	    callback: reload
+	});
+
+	// else we cannot dynamically generate the add menu handlers
+	let addHandleGenerator = function(type) {
+	    return function() { me.createSDNEditWindow(type); };
+	};
+	let addMenuItems = [], type;
+
+	for (type in PVE.Utils.sdnipamSchema) {
+	    let ipam = PVE.Utils.sdnipamSchema[type];
+	    if (ipam.hideAdd) {
+		continue;
+	    }
+	    addMenuItems.push({
+		text:  PVE.Utils.format_sdnipam_type(type),
+		iconCls: 'fa fa-fw fa-' + ipam.faIcon,
+		handler: addHandleGenerator(type)
+	    });
+	}
+
+	Ext.apply(me, {
+	    store: store,
+	    reloadStore: reload,
+	    selModel: sm,
+	    viewConfig: {
+		trackOver: false
+	    },
+	    tbar: [
+		{
+		    text: gettext('Add'),
+		    menu: new Ext.menu.Menu({
+			items: addMenuItems
+		    })
+		},
+		remove_btn,
+		edit_btn,
+	    ],
+	    columns: [
+		{
+		    header: 'ID',
+		    flex: 2,
+		    dataIndex: 'ipam'
+		},
+		{
+		    header: gettext('Type'),
+		    flex: 1,
+		    dataIndex: 'type',
+		    renderer: PVE.Utils.format_sdnipam_type
+		},
+		{
+		    header: 'url',
+		    flex: 1,
+		    dataIndex: 'url',
+		},
+	    ],
+	    listeners: {
+		activate: reload,
+		itemdblclick: run_editor
+	    }
+	});
+
+	me.callParent();
+    }
+});
diff --git a/www/manager6/sdn/SubnetEdit.js b/www/manager6/sdn/SubnetEdit.js
index e165ff73..c9c6475b 100644
--- a/www/manager6/sdn/SubnetEdit.js
+++ b/www/manager6/sdn/SubnetEdit.js
@@ -46,6 +46,13 @@ Ext.define('PVE.sdn.SubnetInputPanel', {
 	    checked: false,
 	    fieldLabel: 'SNAT'
 	},
+        {
+            xtype: 'pveSDNIpamSelector',
+            fieldLabel: gettext('Ipam'),
+            name: 'ipam',
+            value: '',
+            allowBlank: false,
+        },
     ]
 });
 
diff --git a/www/manager6/sdn/SubnetView.js b/www/manager6/sdn/SubnetView.js
index e5cc03b7..95a468bc 100644
--- a/www/manager6/sdn/SubnetView.js
+++ b/www/manager6/sdn/SubnetView.js
@@ -79,9 +79,14 @@ Ext.define('PVE.sdn.SubnetView', {
 		    dataIndex: 'gateway',
 		},
 		{
-		    header: gettext('Snat'),
+		    header: 'SNAT',
 		    flex: 1,
 		    dataIndex: 'snat',
+		},
+		{
+		    header: 'Ipam',
+		    flex: 1,
+		    dataIndex: 'ipam',
 		}
 	    ],
 	    listeners: {
diff --git a/www/manager6/sdn/ipams/Base.js b/www/manager6/sdn/ipams/Base.js
new file mode 100644
index 00000000..7e0bf49b
--- /dev/null
+++ b/www/manager6/sdn/ipams/Base.js
@@ -0,0 +1,73 @@
+Ext.define('PVE.panel.SDNIpamBase', {
+    extend: 'Proxmox.panel.InputPanel',
+
+    type: '',
+
+    onGetValues: function(values) {
+        var me = this;
+
+        if (me.isCreate) {
+            values.type = me.type;
+        } else {
+            delete values.ipam;
+        }
+
+        return values;
+    },
+
+    initComponent : function() {
+        var me = this;
+
+        me.callParent();
+    }
+});
+
+Ext.define('PVE.sdn.ipams.BaseEdit', {
+    extend: 'Proxmox.window.Edit',
+
+    initComponent : function() {
+	var me = this;
+
+	me.isCreate = !me.ipam;
+
+	if (me.isCreate) {
+	    me.url = '/api2/extjs/cluster/sdn/ipams';
+	    me.method = 'POST';
+	} else {
+	    me.url = '/api2/extjs/cluster/sdn/ipams/' + me.ipam;
+	    me.method = 'PUT';
+	}
+
+	var ipanel = Ext.create(me.paneltype, {
+	    type: me.type,
+	    isCreate: me.isCreate,
+	    ipam: me.ipam
+	});
+
+	Ext.apply(me, {
+            subject: PVE.Utils.format_sdnipam_type(me.type),
+	    isAdd: true,
+	    items: [ ipanel ]
+	});
+
+	me.callParent();
+
+	if (!me.isCreate) {
+	    me.load({
+		success:  function(response, options) {
+		    var values = response.result.data;
+		    var ctypes = values.content || '';
+
+		    values.content = ctypes.split(',');
+
+		    if (values.nodes) {
+			values.nodes = values.nodes.split(',');
+		    }
+		    values.enable = values.disable ? 0 : 1;
+
+		    ipanel.setValues(values);
+		}
+	    });
+	}
+    }
+});
diff --git a/www/manager6/sdn/ipams/NetboxEdit.js b/www/manager6/sdn/ipams/NetboxEdit.js
new file mode 100644
index 00000000..5a0a84c8
--- /dev/null
+++ b/www/manager6/sdn/ipams/NetboxEdit.js
@@ -0,0 +1,47 @@
+Ext.define('PVE.sdn.ipams.NetboxInputPanel', {
+    extend: 'PVE.panel.SDNIpamBase',
+
+    //onlineHelp: 'pvesdn_ipam_plugin_netbox', // FIXME uncomment once doc-gen is updated
+
+    onGetValues: function(values) {
+        var me = this;
+
+        if (me.isCreate) {
+            values.type = me.type;
+        } else {
+            delete values.ipam;
+        }
+
+        return values;
+    },
+
+    initComponent : function() {
+	var me = this;
+
+        me.items = [
+           {
+            xtype: me.isCreate ? 'textfield' : 'displayfield',
+            name: 'ipam',
+            maxLength: 10,
+            value: me.zone || '',
+            fieldLabel: 'ID',
+            allowBlank: false
+          },
+          {
+            xtype: 'textfield',
+            name: 'url',
+            fieldLabel: gettext('Url'),
+            allowBlank: false,
+          },
+          {
+            xtype: 'textfield',
+            name: 'token',
+            fieldLabel: gettext('Token'),
+            allowBlank: false,
+          },
+
+	];
+
+	me.callParent();
+    }
+});
diff --git a/www/manager6/sdn/ipams/PhpIpamEdit.js b/www/manager6/sdn/ipams/PhpIpamEdit.js
new file mode 100644
index 00000000..c8da53a6
--- /dev/null
+++ b/www/manager6/sdn/ipams/PhpIpamEdit.js
@@ -0,0 +1,53 @@
+Ext.define('PVE.sdn.ipams.PhpIpamInputPanel', {
+    extend: 'PVE.panel.SDNIpamBase',
+
+    //onlineHelp: 'pvesdn_ipam_plugin_phpipam', // FIXME uncomment once doc-gen is updated
+
+    onGetValues: function(values) {
+        var me = this;
+
+        if (me.isCreate) {
+            values.type = me.type;
+        } else {
+            delete values.ipam;
+        }
+
+        return values;
+    },
+
+    initComponent : function() {
+	var me = this;
+
+        me.items = [
+           {
+            xtype: me.isCreate ? 'textfield' : 'displayfield',
+            name: 'ipam',
+            maxLength: 10,
+            value: me.zone || '',
+            fieldLabel: 'ID',
+            allowBlank: false
+          },
+          {
+            xtype: 'textfield',
+            name: 'url',
+            fieldLabel: gettext('Url'),
+            allowBlank: false,
+          },
+          {
+            xtype: 'textfield',
+            name: 'token',
+            fieldLabel: gettext('Token'),
+            allowBlank: false,
+          },
+          {
+            xtype: 'textfield',
+            name: 'section',
+            fieldLabel: gettext('Section'),
+            allowBlank: false,
+          },
+
+	];
+
+	me.callParent();
+    }
+});
-- 
2.20.1





More information about the pve-devel mailing list