[pve-devel] r5492 - in pve-manager/pve2: lib/PVE/API2 www/manager www/manager/form www/manager/grid

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Feb 8 11:01:01 CET 2011


Author: dietmar
Date: 2011-02-08 11:01:01 +0100 (Tue, 08 Feb 2011)
New Revision: 5492

Modified:
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/www/manager/NodeConfig.js
   pve-manager/pve2/www/manager/PVEUtils.js
   pve-manager/pve2/www/manager/StorageBrowser.js
   pve-manager/pve2/www/manager/form/StdForm.js
   pve-manager/pve2/www/manager/grid/ObjectView.js
Log:
implement DNS view/edit


Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-02-08 10:01:01 UTC (rev 5492)
@@ -176,6 +176,96 @@
 	};
     }});
 
+__PACKAGE__->register_method({
+    name => 'dns', 
+    path => 'dns', 
+    method => 'GET',
+    description => "Read DNS settings.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => "object",
+   	additionalProperties => 0,
+	properties => {
+	    search => {
+		description => "Search domain for host-name lookup.",
+		type => 'string',
+		optional => 1,
+	    },
+	    dns1 => {
+		description => 'First name server IP address.',
+		type => 'string',
+		optional => 1,
+	    },		
+	    dns2 => {
+		description => 'Second name server IP address.',
+		type => 'string',
+		optional => 1,
+	    },		
+	    dns3 => {
+		description => 'Third name server IP address.',
+		type => 'string',
+		optional => 1,
+	    },		
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $res = PVE::INotify::read_file('resolvconf');
+
+	return $res;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'update_dns', 
+    path => 'dns', 
+    method => 'PUT',
+    description => "Write DNS settings.",
+    proxyto => 'node',
+    protected => 1,
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    search => {
+		description => "Search domain for host-name lookup.",
+		type => 'string',
+	    },
+	    dns1 => {
+		description => 'First name server IP address.',
+		type => 'string',
+		format => 'ipv4',
+		optional => 1,
+	    },		
+	    dns2 => {
+		description => 'Second name server IP address.',
+		type => 'string',
+		format => 'ipv4',
+		optional => 1,
+	    },		
+	    dns3 => {
+		description => 'Third name server IP address.',
+		type => 'string',
+		format => 'ipv4',
+		optional => 1,
+	    },		
+	},
+    },
+    returns => { type => "null" },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::INotify::update_file('resolvconf', $param);
+
+	return undef;
+    }});
+
 package PVE::API2::Nodes;
 
 use strict;

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-02-08 10:01:01 UTC (rev 5492)
@@ -1,5 +1,173 @@
 Ext.ns("PVE");
 
+PVE.NodeDNSEdit = Ext.extend(PVE.window.ModalDialog, {
+
+    initComponent : function() {
+	var self = this;
+
+	var nodename = self.nodename;
+
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var formpanel = new PVE.form.StdForm({
+	    url: "/api2/extjs/nodes/" + nodename + "/dns",
+	    method: 'PUT',
+	    trackResetOnLoad: true,
+
+	    labelWidth: 120,
+	    frame: true,
+            defaults: {
+		width: '100%'
+	    },
+
+	    items: [
+		{
+		    xtype: 'textfield',
+                    fieldLabel: 'Search domain',
+                    name: 'search',
+                    allowBlank: false
+		}, 
+		{
+		    html: "<div> </div>"
+		},
+		{
+ 		    xtype: 'textfield',
+                    fieldLabel: 'First DNS server',
+		    vtype: 'IPAddress',
+                    name: 'dns1'
+		},
+		{
+ 		    xtype: 'textfield',
+                    fieldLabel: 'Second DNS server',
+		    vtype: 'IPAddress',
+                    name: 'dns2'
+		},
+		{
+ 		    xtype: 'textfield',
+                    fieldLabel: 'Third DNS server',
+ 		    vtype: 'IPAddress',
+                    name: 'dns3'
+		}
+	    ]
+	});
+
+
+	formpanel.getForm().load({
+	    url: "/api2/extjs/nodes/" + nodename + "/dns",
+	    method: 'GET',
+	    failure: function(form, action) {
+		console.dir(action.result);
+		Ext.Msg.alert("Load failed", action.result.message, function() {
+		    self.close();
+		});
+	    }
+	});
+
+	var submit = new Ext.Button({
+	    text: 'OK',
+	    disabled: true,
+	    handler: function(){
+		formpanel.submitHandler({
+		    success: function() { 
+			self.close();
+		    }
+		});
+	    }
+	});
+
+	formpanel.on("actioncomplete", function(form, action){
+	    if(action.type == 'load'){
+		submit.enable();
+	    }
+	});
+
+	Ext.apply(self, {
+	    title: "Edit DNS Settings",
+	    items: formpanel,
+            width: 400,
+	    buttons: [
+		submit,
+		{
+		    text: 'Reset',
+		    handler: function(){
+			formpanel.getForm().reset();
+		    }
+		},
+		{
+		    text: 'Cancel',
+		    handler: function(){
+			self.close();
+		    }
+		}
+	    ]
+	});
+
+	PVE.NodeDNSEdit.superclass.initComponent.call(self);
+    }
+});
+
+PVE.NodeDNSView = Ext.extend(PVE.grid.ObjectView, {
+
+    initComponent : function() {
+	var self = this;
+
+	var nodename = self.nodename;
+
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var store = new PVE.data.ObjectStore({
+	    url: "/api2/json/nodes/" + nodename + "/dns",
+	    method: 'GET',
+	    rows: {
+		search: { header: 'Search domain' },
+		dns1: { header: 'First DNS server' },
+		dns2: { header: 'Second DNS server' },
+		dns3: { header: 'Third DNS server' },
+	    }
+	});
+
+	var update_config = function() {
+	    store.load();
+	};
+
+	var run_editor = function() {
+	    var win = new PVE.NodeDNSEdit({
+		nodename: nodename,
+		height: 250
+	    });
+	    win.on("close", function() {
+		update_config();
+	    });
+	    win.show();
+	};
+
+	Ext.apply(self, {
+	    store: store,
+	    layout: 'fit',
+	    cwidth1: 150,
+	    tbar: [ 
+		{
+		    text: "Edit",
+		    handler: run_editor
+		}
+	    ],
+	    listeners: {
+		show: function() {
+		    update_config();
+		},
+		rowdblclick: function() {
+		    run_editor();
+		}
+	    }
+	});
+
+	PVE.NodeDNSView.superclass.initComponent.call(self);
+    }
+});
+Ext.reg('pveNodeDNSView', PVE.NodeDNSView);
+
 PVE.NodeConfig = Ext.extend(PVE.ConfigPanel, {
 
     initComponent : function() {
@@ -43,7 +211,8 @@
 		{
 		    title: 'DNS',
 		    id: 'dns',
-		    html: 'dns ' + nodename
+		    xtype: 'pveNodeDNSView',
+		    nodename: nodename
 		},
 		{
 		    title: 'Time',

Modified: pve-manager/pve2/www/manager/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/manager/PVEUtils.js	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/www/manager/PVEUtils.js	2011-02-08 10:01:01 UTC (rev 5492)
@@ -21,6 +21,15 @@
     }
 });
 
+// custom Vtype for vtype:'IPAddress'
+Ext.apply(Ext.form.VTypes, {
+    IPAddress:  function(v) {
+        return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
+    },
+    IPAddressText: 'Must be a numeric IP address',
+    IPAddressMask: /[\d\.]/i
+});
+
 PVE.Utils = function() {
 
     var log_severity_hash = {

Modified: pve-manager/pve2/www/manager/StorageBrowser.js
===================================================================
--- pve-manager/pve2/www/manager/StorageBrowser.js	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/www/manager/StorageBrowser.js	2011-02-08 10:01:01 UTC (rev 5492)
@@ -169,6 +169,7 @@
 		    xtype: 'pveObjectView',
 		    store: self.store,
 		    margins: "10 10 10 10",
+		    height: 200,
 		    width: 300,
 		    tbar: [
 			"<b>Configuration", "->", 
@@ -216,6 +217,7 @@
 		},
 		new PVE.StorageStatus ({
 		    confdata: self.confdata,
+ 		    height: 200,
 		    width: 300
 		})
 	    ]

Modified: pve-manager/pve2/www/manager/form/StdForm.js
===================================================================
--- pve-manager/pve2/www/manager/form/StdForm.js	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/www/manager/form/StdForm.js	2011-02-08 10:01:01 UTC (rev 5492)
@@ -8,7 +8,7 @@
 	// NOTE: If subclassing FormPanel, any configuration options for 
 	// the BasicForm must be applied to initialConfig
 	Ext.apply(self, Ext.apply(self.initialConfig, {
-	    bodyStyle: 'padding:10px',
+	    bodyStyle: 'padding:5px',
 	    autoScroll: true,
 
  	    submitHandler: function(options) {

Modified: pve-manager/pve2/www/manager/grid/ObjectView.js
===================================================================
--- pve-manager/pve2/www/manager/grid/ObjectView.js	2011-02-08 09:53:11 UTC (rev 5491)
+++ pve-manager/pve2/www/manager/grid/ObjectView.js	2011-02-08 10:01:01 UTC (rev 5492)
@@ -29,31 +29,26 @@
 	};
 
 	Ext.apply(self, {
+	    hideHeaders: true,
 	    stateful: false,
 	    enableHdMenu: false,
-	    height: 200,
-	    colModel: new Ext.grid.ColumnModel({
-		defaults: {
-		    sortable: false
-		},
-		columns: [
-		    {
-			header: 'Name',
-			width: 0.3,
-			dataIndex: 'name',
-			renderer: render_key
-		    },{
-			header: 'Value',
-			width: 0.7,
-			dataIndex: 'value',
-			renderer: render_value
-		    }
-		]
-	    }),
-	    viewConfig: { forceFit: true },	    
-
+	    autoExpandColumn: 'value',
+	    columns: [
+		{
+		    header: 'Name',
+		    width: self.cwidth1,
+		    dataIndex: 'name',
+		    sortable: false,
+		    renderer: render_key
+		},{
+		    id: 'value',
+		    header: 'Value',
+		    dataIndex: 'value',
+		    sortable: false,
+		    renderer: render_value
+		}
+	    ],
 	    sm: new Ext.grid.RowSelectionModel({singleSelect:true})
-
 	});
 
 	PVE.grid.ObjectView.superclass.initComponent.call(self);




More information about the pve-devel mailing list