public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v4 pve-manager 20/33] sdn: ipam: add ipam panel
Date: Fri, 17 Nov 2023 12:39:58 +0100	[thread overview]
Message-ID: <20231117114011.834002-21-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20231117114011.834002-1-s.hanreich@proxmox.com>

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 www/css/ext6-pve.css          |  22 ++-
 www/manager6/Makefile         |   1 +
 www/manager6/dc/Config.js     |  12 +-
 www/manager6/sdn/IpamEdit.js  |  78 ++++++++++
 www/manager6/tree/DhcpTree.js | 267 ++++++++++++++++++++++++++++++++++
 5 files changed, 372 insertions(+), 8 deletions(-)
 create mode 100644 www/manager6/sdn/IpamEdit.js
 create mode 100644 www/manager6/tree/DhcpTree.js

diff --git a/www/css/ext6-pve.css b/www/css/ext6-pve.css
index e18b173f5..091855356 100644
--- a/www/css/ext6-pve.css
+++ b/www/css/ext6-pve.css
@@ -510,28 +510,38 @@ div.right-aligned {
     content: ' ';
 }
 
-.fa-sdn:before {
+.x-fa-sdn-treelist:before {
     width: 14px;
     height: 14px;
     position: absolute;
     left: 1px;
     top: 4px;
+}
+
+.fa-sdn:before {
     background-image:url(../images/icon-sdn.svg);
     background-size: 14px 14px;
     content: ' ';
 }
 
 .fa-network-wired:before {
-    width: 14px;
-    height: 14px;
-    position: absolute;
-    left: 1px;
-    top: 4px;
     background-image:url(../images/icon-fa-network-wired.svg);
     background-size: 14px 14px;
     content: ' ';
 }
 
+.x-fa-treepanel:before {
+    width: 16px;
+    height: 24px;
+    display: block;
+    background-repeat: no-repeat;
+    background-position: center;
+}
+
+.x-tree-icon-none {
+    display: none;
+}
+
 .x-treelist-row-over > * > .x-treelist-item-icon,
 .x-treelist-row-over > * > .x-treelist-item-text{
     color: #000;
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 093452cd7..93b4ff155 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -108,6 +108,7 @@ JSSRC= 							\
 	tree/ResourceTree.js				\
 	tree/SnapshotTree.js				\
 	tree/ResourceMapTree.js				\
+	tree/DhcpTree.js				\
 	window/Backup.js				\
 	window/BackupConfig.js				\
 	window/BulkAction.js				\
diff --git a/www/manager6/dc/Config.js b/www/manager6/dc/Config.js
index 7d01da5fb..7c2b7b168 100644
--- a/www/manager6/dc/Config.js
+++ b/www/manager6/dc/Config.js
@@ -185,7 +185,7 @@ Ext.define('PVE.dc.Config', {
 		me.items.push({
 		    xtype: 'pveSDNStatus',
 		    title: gettext('SDN'),
-		    iconCls: 'fa fa-sdn',
+		    iconCls: 'fa fa-sdn x-fa-sdn-treelist',
 		    hidden: true,
 		    itemId: 'sdn',
 		    expandedOnInit: true,
@@ -203,7 +203,7 @@ Ext.define('PVE.dc.Config', {
 		    groups: ['sdn'],
 		    title: 'VNets',
 		    hidden: true,
-		    iconCls: 'fa fa-network-wired',
+		    iconCls: 'fa fa-network-wired x-fa-sdn-treelist',
 		    itemId: 'sdnvnet',
 		},
 		{
@@ -213,6 +213,14 @@ Ext.define('PVE.dc.Config', {
 		    hidden: true,
 		    iconCls: 'fa fa-gear',
 		    itemId: 'sdnoptions',
+		},
+		{
+		    xtype: 'pveDhcpTree',
+		    groups: ['sdn'],
+		    title: gettext('IPAM'),
+		    hidden: true,
+		    iconCls: 'fa fa-map-signs',
+		    itemId: 'sdnmappings',
 		});
 	    }
 
diff --git a/www/manager6/sdn/IpamEdit.js b/www/manager6/sdn/IpamEdit.js
new file mode 100644
index 000000000..18e22c592
--- /dev/null
+++ b/www/manager6/sdn/IpamEdit.js
@@ -0,0 +1,78 @@
+Ext.define('PVE.sdn.IpamEditInputPanel', {
+    extend: 'Proxmox.panel.InputPanel',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    isCreate: false,
+
+    onGetValues: function(values) {
+	let me = this;
+
+	if (!values.vmid) {
+	    delete values.vmid;
+	}
+
+	return values;
+    },
+
+    items: [
+	{
+	    xtype: 'pmxDisplayEditField',
+	    name: 'vmid',
+	    fieldLabel: gettext('VMID'),
+	    allowBlank: false,
+	    editable: false,
+	    cbind: {
+		hidden: '{isCreate}',
+	    },
+	},
+	{
+	    xtype: 'pmxDisplayEditField',
+	    name: 'mac',
+	    fieldLabel: gettext('MAC'),
+	    allowBlank: false,
+	    cbind: {
+		editable: '{isCreate}',
+	    },
+	},
+	{
+	    xtype: 'proxmoxtextfield',
+	    name: 'ip',
+	    fieldLabel: gettext('IP'),
+	    allowBlank: false,
+	},
+    ],
+});
+
+Ext.define('PVE.sdn.IpamEdit', {
+    extend: 'Proxmox.window.Edit',
+
+    subject: gettext('DHCP Mapping'),
+    width: 350,
+
+    isCreate: false,
+    mapping: {},
+
+    submitUrl: function(url, values) {
+	return `${url}/${values.zone}/${values.vnet}/${values.mac}`;
+    },
+
+    initComponent: function() {
+	var me = this;
+
+	me.method = me.isCreate ? 'POST' : 'PUT';
+
+	let ipanel = Ext.create('PVE.sdn.IpamEditInputPanel', {
+	    isCreate: me.isCreate,
+	});
+
+	Ext.apply(me, {
+	    items: [
+		ipanel,
+	    ],
+	});
+
+	me.callParent();
+
+	ipanel.setValues(me.mapping);
+    },
+});
diff --git a/www/manager6/tree/DhcpTree.js b/www/manager6/tree/DhcpTree.js
new file mode 100644
index 000000000..ca279c29a
--- /dev/null
+++ b/www/manager6/tree/DhcpTree.js
@@ -0,0 +1,267 @@
+Ext.define('PVE.sdn.DhcpTree', {
+    extend: 'Ext.tree.Panel',
+    xtype: 'pveDhcpTree',
+
+    layout: 'fit',
+    rootVisible: false,
+    animate: false,
+
+    store: {
+	sorters: ['ip', 'name'],
+    },
+
+    controller: {
+	xclass: 'Ext.app.ViewController',
+
+	reload: function() {
+	    let me = this;
+
+	    Proxmox.Utils.API2Request({
+		url: `/cluster/sdn/ipam`,
+		method: 'GET',
+		success: function(response, opts) {
+		    let root = {
+			name: '__root',
+			expanded: true,
+			children: [],
+		    };
+
+		    let zones = {};
+		    let vnets = {};
+		    let subnets = {};
+
+		    response.result.data.forEach((element) => {
+			element.leaf = true;
+
+			if (!(element.zone in zones)) {
+			    let zone = {
+				name: element.zone,
+				type: 'zone',
+				iconCls: 'fa fa-th',
+				expanded: true,
+				children: [],
+			    };
+
+			    zones[element.zone] = zone;
+			    root.children.push(zone);
+			}
+
+			if (!(element.vnet in vnets)) {
+			    let vnet = {
+				name: element.vnet,
+				zone: element.zone,
+				type: 'vnet',
+				iconCls: 'fa fa-network-wired x-fa-treepanel',
+				expanded: true,
+				children: [],
+			    };
+
+			    vnets[element.vnet] = vnet;
+			    zones[element.zone].children.push(vnet);
+			}
+
+			if (!(element.subnet in subnets)) {
+			    let subnet = {
+				name: element.subnet,
+				zone: element.zone,
+				vnet: element.vnet,
+				type: 'subnet',
+				iconCls: 'x-tree-icon-none',
+				expanded: true,
+				children: [],
+			    };
+
+			    subnets[element.subnet] = subnet;
+			    vnets[element.vnet].children.push(subnet);
+			}
+
+			element.type = 'mapping';
+			element.iconCls = 'x-tree-icon-none';
+			subnets[element.subnet].children.push(element);
+		    });
+
+		    me.getView().setRootNode(root);
+		},
+	    });
+	},
+
+	init: function(view) {
+	    let me = this;
+	    me.reload();
+	},
+
+	onDelete: function(table, rI, cI, item, e, { data }) {
+	    let me = this;
+	    let view = me.getView();
+
+	    Ext.Msg.show({
+		title: gettext('Confirm'),
+		icon: Ext.Msg.WARNING,
+		message: Ext.String.format(gettext('Are you sure you want to remove DHCP mapping {0}'), `${data.mac} / ${data.ip}`),
+		buttons: Ext.Msg.YESNO,
+		defaultFocus: 'no',
+		callback: function(btn) {
+		    if (btn !== 'yes') {
+		        return;
+		    }
+
+		    Proxmox.Utils.API2Request({
+			url: `/cluster/sdn/ipam/${data.zone}/${data.vnet}/${data.mac}`,
+			method: 'DELETE',
+			waitMsgTarget: view,
+			failure: function(response, opts) {
+			    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+			},
+			callback: me.reload.bind(me),
+		    });
+		},
+	    });
+	},
+
+	editAction: function(_grid, _rI, _cI, _item, _e, rec) {
+	    this.edit(rec);
+	},
+
+	editDblClick: function() {
+	    let me = this;
+
+	    let view = me.getView();
+	    let selection = view.getSelection();
+
+	    if (!selection || selection.length < 1) {
+		return;
+	    }
+
+	    me.edit(selection[0]);
+	},
+
+	edit: function(rec) {
+	    let me = this;
+
+	    if (rec.data.type === 'mapping' && !rec.data.gateway) {
+		me.openEditWindow(rec.data);
+	    }
+	},
+
+	openEditWindow: function(data) {
+	    let me = this;
+
+	    Ext.create('PVE.sdn.IpamEdit', {
+		autoShow: true,
+		mapping: data,
+		url: `/cluster/sdn/ipam`,
+		extraRequestParams: {
+		    vmid: data.vmid,
+		    mac: data.mac,
+		    zone: data.zone,
+		    vnet: data.vnet,
+		},
+		listeners: {
+		    destroy: () => me.reload(),
+		},
+	    });
+	},
+    },
+
+    listeners: {
+	itemdblclick: 'editDblClick',
+    },
+
+    tbar: [
+	{
+	    xtype: 'proxmoxButton',
+	    text: gettext('Reload'),
+	    handler: 'reload',
+	},
+    ],
+
+    columns: [
+	{
+	    xtype: 'treecolumn',
+	    text: gettext('Name / VMID'),
+	    dataIndex: 'name',
+	    width: 200,
+	    renderer: function(value, meta, record) {
+		if (record.get('gateway')) {
+		    return gettext('Gateway');
+		}
+
+		return record.get('name') ?? record.get('vmid') ?? ' ';
+	    },
+	},
+	{
+	    text: gettext('IP'),
+	    dataIndex: 'ip',
+	    width: 200,
+	},
+	{
+	    text: gettext('MAC'),
+	    dataIndex: 'mac',
+	    width: 200,
+	},
+	{
+	    text: gettext('Gateway'),
+	    dataIndex: 'gateway',
+	    width: 200,
+	},
+	{
+	    header: gettext('Actions'),
+	    xtype: 'actioncolumn',
+	    dataIndex: 'text',
+	    width: 150,
+	    items: [
+		{
+		    handler: function(table, rI, cI, item, e, { data }) {
+			let me = this;
+
+			Ext.create('PVE.sdn.IpamEdit', {
+			    autoShow: true,
+			    mapping: {},
+			    url: `/cluster/sdn/ipam`,
+			    isCreate: true,
+			    extraRequestParams: {
+				vnet: data.name,
+				zone: data.zone,
+			    },
+			    listeners: {
+				destroy: () => {
+				    me.up('pveDhcpTree').controller.reload();
+				},
+			    },
+			});
+		    },
+		    getTip: (v, m, rec) => gettext('Add'),
+		    getClass: (v, m, { data }) => {
+			if (data.type === 'vnet') {
+			    return 'fa fa-plus-square';
+			}
+
+			return 'pmx-hidden';
+		    },
+                },
+		{
+		    handler: 'editAction',
+		    getTip: (v, m, rec) => gettext('Edit'),
+		    getClass: (v, m, { data }) => {
+			if (data.type === 'mapping' && !data.gateway) {
+			    return 'fa fa-pencil fa-fw';
+			}
+
+			return 'pmx-hidden';
+		    },
+                },
+		{
+		    handler: 'onDelete',
+		    getTip: (v, m, rec) => gettext('Delete'),
+		    getClass: (v, m, { data }) => {
+			if (data.type === 'mapping' && !data.gateway) {
+			    return 'fa critical fa-trash-o';
+			}
+
+			return 'pmx-hidden';
+		    },
+                },
+	    ],
+	},
+    ],
+});
-- 
2.39.2




  parent reply	other threads:[~2023-11-17 11:50 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 11:39 [pve-devel] [PATCH v4 cluster/network/manager/qemu-server/container/docs 00/33] Add support for DHCP servers to SDN Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-cluster 01/33] add priv/macs.db Stefan Hanreich
2023-11-17 13:54   ` [pve-devel] applied: " Thomas Lamprecht
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 02/33] sdn: preparations for DHCP plugin Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 03/33] subnet: add dhcp options Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 04/33] sdn: zone: add dhcp option Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 05/33] ipam: plugins: preparations for DHCP Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 06/33] subnet: vnet: refactor IPAM related methods Stefan Hanreich
2023-11-17 14:13   ` Stefan Lendl
2023-11-17 15:12     ` Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 07/33] dhcp: add abstract class for DHCP plugins Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 08/33] sdn: dhcp: add dnsmasq plugin Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 09/33] sdn: dhcp: add helper for creating DHCP leases Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 10/33] api: add endpoints for managing PVE IPAM Stefan Hanreich
2023-11-18 16:27   ` Thomas Lamprecht
2023-11-20 10:55     ` Stefan Hanreich
2023-11-20 12:28       ` DERUMIER, Alexandre
2023-11-20 12:34         ` Stefan Hanreich
2023-11-20 12:50           ` Stefan Hanreich
2023-11-20 16:25           ` DERUMIER, Alexandre
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 11/33] api: subnet: add dhcp ranges Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 12/33] api: zone: add dhcp option Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 13/33] dhcp: regenerate config for DHCP plugins on applying configuration Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 14/33] sdn: fix tests Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 15/33] sdn: fix subnets && netbox ipam tests Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-network 16/33] add add_dhcp_mapping Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-manager 17/33] sdn: regenerate DHCP config on reload Stefan Hanreich
2023-11-21 21:15   ` [pve-devel] applied: " Thomas Lamprecht
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-manager 18/33] sdn: add DHCP option to Zone dialogue Stefan Hanreich
2023-11-17 11:39 ` [pve-devel] [PATCH v4 pve-manager 19/33] sdn: subnet: add panel for editing dhcp ranges Stefan Hanreich
2023-11-20 13:20   ` Dominik Csapak
2023-11-17 11:39 ` Stefan Hanreich [this message]
2023-11-17 15:04   ` [pve-devel] [PATCH v4 pve-manager 20/33] sdn: ipam: add ipam panel DERUMIER, Alexandre
2023-11-17 15:15     ` Stefan Hanreich
2023-11-18 14:25       ` DERUMIER, Alexandre
2023-11-20 13:44   ` Dominik Csapak
2023-11-17 11:39 ` [pve-devel] [PATCH v4 qemu-server 21/33] vmnic add|remove : add|del ip in ipam Stefan Hanreich
2023-11-21 13:53   ` [pve-devel] applied-series: " Wolfgang Bumiller
2023-11-17 11:40 ` [pve-devel] [PATCH v4 qemu-server 22/33] vm_start : vm-network-scripts: add_dhcp_reservation Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 qemu-server 23/33] api2: create|restore|clone: add_free_ip Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 qemu-server 24/33] vm_destroy: delete ip from ipam Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 qemu-server 25/33] nic hotplug: add_dhcp_mapping Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 qemu-server 26/33] nic online bridge/vlan change: link disconnect/reconnect Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 27/33] nic hotplug : add|del ips in ipam Stefan Hanreich
2023-11-21 13:47   ` [pve-devel] applied-series: " Wolfgang Bumiller
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 28/33] vm_destroy: remove ips from ipam for all interfaces Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 29/33] vm_create|restore: create ips in ipam Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 30/33] vm_clone : create ips in ipams Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 31/33] vm_apply_pending: add|del ips from ipam for offline changes Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-container 32/33] lxc-pve-prestart-hook : add_dhcp_mapping Stefan Hanreich
2023-11-17 11:40 ` [pve-devel] [PATCH v4 pve-docs 33/33] sdn: dhcp: Add documentation for DHCP Stefan Hanreich
2023-11-21 19:03   ` [pve-devel] applied: " Thomas Lamprecht
2023-11-17 15:47 ` [pve-devel] [PATCH v4 cluster/network/manager/qemu-server/container/docs 00/33] Add support for DHCP servers to SDN DERUMIER, Alexandre
2023-11-17 16:05   ` Stefan Hanreich
2023-11-17 16:07     ` Stefan Hanreich
2023-11-17 16:09     ` DERUMIER, Alexandre
2023-11-17 20:44       ` DERUMIER, Alexandre
2023-11-21 11:23   ` Stefan Lendl
2023-11-21 13:02     ` DERUMIER, Alexandre
2023-11-21 13:25     ` DERUMIER, Alexandre
2023-11-21 13:28     ` DERUMIER, Alexandre
2023-11-21 16:34       ` Stefan Lendl
2023-11-21 18:15         ` DERUMIER, Alexandre
2023-11-22  8:06         ` DERUMIER, Alexandre
2023-11-18 14:38 ` DERUMIER, Alexandre
2023-11-20 16:42 ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231117114011.834002-21-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal