add qemu IPConfigEdit for CloudInit

resembles the lxc IPConfigEdit, but is slightly different

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2018-03-15 16:21:33 +01:00 committed by Wolfgang Bumiller
parent abe824aa95
commit 01e02121c7
3 changed files with 306 additions and 0 deletions

View File

@ -129,6 +129,7 @@ JSSRC= \
qemu/CreateWizard.js \
qemu/USBEdit.js \
qemu/AgentIPView.js \
qemu/IPConfigEdit.js \
lxc/Summary.js \
lxc/Network.js \
lxc/Resources.js \

View File

@ -162,6 +162,63 @@ Ext.define('PVE.Parser', { statics: {
return drivestr;
},
parseIPConfig: function(key, value) {
if (!(key && value)) {
return;
}
var res = {};
var errors = false;
Ext.Array.each(value.split(','), function(p) {
if (!p || p.match(/^\s*$/)) {
return; // continue
}
var match_res;
if ((match_res = p.match(/^ip=(\S+)$/)) !== null) {
res.ip = match_res[1];
} else if ((match_res = p.match(/^gw=(\S+)$/)) !== null) {
res.gw = match_res[1];
} else if ((match_res = p.match(/^ip6=(\S+)$/)) !== null) {
res.ip6 = match_res[1];
} else if ((match_res = p.match(/^gw6=(\S+)$/)) !== null) {
res.gw6 = match_res[1];
} else {
errors = true;
return false; // break
}
});
if (errors) {
return;
}
return res;
},
printIPConfig: function(cfg) {
var c = "";
var str = "";
if (cfg.ip) {
str += "ip=" + cfg.ip;
c = ",";
}
if (cfg.gw) {
str += c + "gw=" + cfg.gw;
c = ",";
}
if (cfg.ip6) {
str += c + "ip6=" + cfg.ip6;
c = ",";
}
if (cfg.gw6) {
str += c + "gw6=" + cfg.gw6;
c = ",";
}
return str;
},
parseOpenVZNetIf: function(value) {
if (!value) {
return;

View File

@ -0,0 +1,248 @@
Ext.define('PVE.qemu.IPConfigPanel', {
extend: 'Proxmox.panel.InputPanel',
xtype: 'pveIPConfigPanel',
insideWizard: false,
vmconfig: {},
onGetValues: function(values) {
var me = this;
if (values.ipv4mode !== 'static') {
values.ip = values.ipv4mode;
}
if (values.ipv6mode !== 'static') {
values.ip6 = values.ipv6mode;
}
var params = {};
var cfg = PVE.Parser.printIPConfig(values);
if (cfg === '') {
params['delete'] = [me.confid];
} else {
params[me.confid] = cfg;
}
return params;
},
setVMConfig: function(config) {
var me = this;
me.vmconfig = config;
},
setIPConfig: function(confid, data) {
var me = this;
me.confid = confid;
if (data.ip === 'dhcp') {
data.ipv4mode = data.ip;
data.ip = '';
} else {
data.ipv4mode = 'static';
}
if (data.ip6 === 'dhcp' || data.ip6 === 'auto') {
data.ipv6mode = data.ip6;
data.ip6 = '';
} else {
data.ipv6mode = 'static';
}
me.ipconfig = data;
me.setValues(me.ipconfig);
},
initComponent : function() {
var me = this;
me.ipconfig = {};
me.column1 = [
{
xtype: 'displayfield',
fieldLabel: gettext('Network Device'),
value: me.netid
},
{
layout: {
type: 'hbox',
align: 'middle'
},
border: false,
margin: '0 0 5 0',
items: [
{
xtype: 'label',
text: gettext('IPv4') + ':'
},
{
xtype: 'radiofield',
boxLabel: gettext('Static'),
name: 'ipv4mode',
inputValue: 'static',
checked: false,
margin: '0 0 0 10',
listeners: {
change: function(cb, value) {
me.down('field[name=ip]').setDisabled(!value);
me.down('field[name=gw]').setDisabled(!value);
}
}
},
{
xtype: 'radiofield',
boxLabel: gettext('DHCP'),
name: 'ipv4mode',
inputValue: 'dhcp',
checked: false,
margin: '0 0 0 10'
}
]
},
{
xtype: 'textfield',
name: 'ip',
vtype: 'IPCIDRAddress',
value: '',
disabled: true,
fieldLabel: gettext('IPv4/CIDR')
},
{
xtype: 'textfield',
name: 'gw',
value: '',
vtype: 'IPAddress',
disabled: true,
fieldLabel: gettext('Gateway') + ' (' + gettext('IPv4') +')'
}
];
me.column2 = [
{
xtype: 'displayfield'
},
{
layout: {
type: 'hbox',
align: 'middle'
},
border: false,
margin: '0 0 5 0',
items: [
{
xtype: 'label',
text: gettext('IPv6') + ':'
},
{
xtype: 'radiofield',
boxLabel: gettext('Static'),
name: 'ipv6mode',
inputValue: 'static',
checked: false,
margin: '0 0 0 10',
listeners: {
change: function(cb, value) {
me.down('field[name=ip6]').setDisabled(!value);
me.down('field[name=gw6]').setDisabled(!value);
}
}
},
{
xtype: 'radiofield',
boxLabel: gettext('DHCP'),
name: 'ipv6mode',
inputValue: 'dhcp',
checked: false,
margin: '0 0 0 10'
},
{
xtype: 'radiofield',
boxLabel: gettext('SLAAC'),
name: 'ipv6mode',
inputValue: 'auto',
checked: false,
margin: '0 0 0 10'
}
]
},
{
xtype: 'textfield',
name: 'ip6',
value: '',
vtype: 'IP6CIDRAddress',
disabled: true,
fieldLabel: gettext('IPv6/CIDR')
},
{
xtype: 'textfield',
name: 'gw6',
vtype: 'IP6Address',
value: '',
disabled: true,
fieldLabel: gettext('Gateway') + ' (' + gettext('IPv6') +')'
}
];
me.callParent();
}
});
Ext.define('PVE.qemu.IPConfigEdit', {
extend: 'Proxmox.window.Edit',
isAdd: true,
initComponent : function() {
/*jslint confusion: true */
var me = this;
// convert confid from netX to ipconfigX
var match = me.confid.match(/^net(\d+)$/);
if (match) {
me.netid = me.confid;
me.confid = 'ipconfig' + match[1];
}
var nodename = me.pveSelNode.data.node;
if (!nodename) {
throw "no node name specified";
}
me.isCreate = me.confid ? false : true;
var ipanel = Ext.create('PVE.qemu.IPConfigPanel', {
confid: me.confid,
netid: me.netid,
nodename: nodename
});
Ext.applyIf(me, {
subject: gettext('Network Config'),
items: ipanel
});
me.callParent();
me.load({
success: function(response, options) {
me.vmconfig = response.result.data;
var ipconfig = {};
var value = me.vmconfig[me.confid];
if (value) {
ipconfig = PVE.Parser.parseIPConfig(me.confid, value);
if (!ipconfig) {
Ext.Msg.alert(gettext('Error'), gettext('Unable to parse network configuration'));
me.close();
return;
}
}
ipanel.setIPConfig(me.confid, ipconfig);
ipanel.setVMConfig(me.vmconfig);
}
});
}
});