Implemented NetVM selection via drop-down in AppVM creation dialog.

This commit is contained in:
Andrew B 2014-05-31 01:58:20 +02:00 committed by Marek Marczykowski-Górecki
parent e9f1bb3880
commit ba0cced495
2 changed files with 212 additions and 140 deletions

View File

@ -17,149 +17,173 @@
<iconset>
<normaloff>:/qubes.png</normaloff>:/qubes.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="QComboBox" name="vmlabel">
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="template_name"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Use this template:</string>
</property>
<property name="buddy">
<cstring>template_name</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QRadioButton" name="proxyvm_radio">
<property name="text">
<string>ProxyVM</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="netvm_radio">
<property name="text">
<string>NetVM</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="vmname">
<property name="text">
<string>my-new-vm</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="appvm_radio">
<property name="text">
<string>AppVM</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QRadioButton" name="hvm_radio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>HVM</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name &amp; label:</string>
</property>
<property name="buddy">
<cstring>vmname</cstring>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QCheckBox" name="standalone">
<property name="text">
<string>Standalone</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QRadioButton" name="hvmtpl_radio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>HVM template</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="allow_networking">
<property name="text">
<string>Allow networking</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="hvmtemplatewarningbox">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QLabel" name="hvmtemplatewarning">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>51</height>
</rect>
</property>
<widget class="QFrame" name="hvmtemplatewarningbox">
<property name="geometry">
<rect>
<x>9</x>
<y>117</y>
<width>481</width>
<height>56</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QLabel" name="hvmtemplatewarning">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;Make sure that the license of the OS installed in a template VM grants you permission to run multiple instances of an installed system.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>330</x>
<y>180</y>
<width>160</width>
<height>27</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>14</x>
<y>14</y>
<width>471</width>
<height>103</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#ff0000;&quot;&gt;Make sure that the license of the OS installed in a template VM grants you permission to run multiple instances of an installed system.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Name and label:</string>
</property>
<property name="wordWrap">
<property name="buddy">
<cstring>vmname</cstring>
</property>
</widget>
</item>
<item row="0" column="2" colspan="3">
<widget class="QLineEdit" name="vmname">
<property name="text">
<string>my-new-vm</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="vmlabel">
<property name="frame">
<bool>true</bool>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Use this template:</string>
</property>
<property name="buddy">
<cstring>template_name</cstring>
</property>
</widget>
</item>
<item row="1" column="2" colspan="3">
<widget class="QComboBox" name="template_name"/>
</item>
<item row="1" column="5">
<widget class="QCheckBox" name="standalone">
<property name="text">
<string>Standalone</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="appvm_radio">
<property name="text">
<string>AppVM</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QRadioButton" name="netvm_radio">
<property name="text">
<string>NetVM</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QRadioButton" name="proxyvm_radio">
<property name="text">
<string>ProxyVM</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QRadioButton" name="hvm_radio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>HVM</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QRadioButton" name="hvmtpl_radio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>HVM template</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="allow_networking">
<property name="text">
<string>Allow networking:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<widget class="QComboBox" name="netvm_name"/>
</item>
</layout>
</widget>
</widget>
<tabstops>
<tabstop>vmname</tabstop>

View File

@ -72,6 +72,7 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
self.vmlabel.setItemIcon (i, QIcon(label.icon_path))
self.fill_template_list()
self.fill_netvm_list()
self.vmname.setValidator(QRegExpValidator(QRegExp("[a-zA-Z0-9-]*", Qt.CaseInsensitive), None))
self.vmname.selectAll()
@ -103,24 +104,60 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
self.template_name.insertItem(i, vm.name)
self.template_name.setCurrentIndex(default_index)
def fill_netvm_list(self):
def filter_netvm(vm):
if vm.internal:
return False
if vm.is_netvm():
return True
if vm.is_proxyvm():
return True
else:
return False
self.netvm_list = filter(filter_netvm, self.qvm_collection.values())
self.netvm_name.clear()
default_index = 0
for (i, vm) in enumerate(self.netvm_list):
if vm is self.qvm_collection.get_default_netvm():
default_index = i
self.netvm_name.insertItem(i, vm.name + " (default)")
else:
self.netvm_name.insertItem(i, vm.name)
self.netvm_name.setCurrentIndex(default_index)
def on_allow_networking_toggled(self, checked):
if checked:
self.fill_netvm_list()
self.netvm_name.setEnabled(True)
else:
self.netvm_name.clear()
self.netvm_name.setEnabled(False)
def on_appvm_radio_toggled(self, checked):
if checked:
self.template_name.setEnabled(True)
self.allow_networking.setEnabled(True)
self.netvm_name.setEnabled(self.allow_networking.isChecked())
def on_netvm_radio_toggled(self, checked):
if checked:
self.template_name.setEnabled(True)
self.allow_networking.setChecked(True)
self.allow_networking.setEnabled(False)
self.netvm_name.setEnabled(False)
def on_proxyvm_radio_toggled(self, checked):
if checked:
self.template_name.setEnabled(True)
self.allow_networking.setEnabled(True)
self.netvm_name.setEnabled(self.allow_networking.isChecked())
def on_hvm_radio_toggled(self, checked):
if self.hvm_radio.isChecked() or self.hvmtpl_radio.isChecked():
self.standalone.setChecked(True)
self.allow_networking.setEnabled(True)
self.netvm_name.setEnabled(self.allow_networking.isChecked())
self.standalone.setEnabled(self.hvm_radio.isChecked())
else:
self.standalone.setChecked(False)
@ -157,6 +194,10 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
if self.template_name.isEnabled():
template_vm = self.template_vm_list[self.template_name.currentIndex()]
netvm = None
if self.netvm_name.isEnabled():
netvm = self.netvm_list[self.netvm_name.currentIndex()]
standalone = self.standalone.isChecked()
allow_networking = None
@ -181,7 +222,7 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
vmclass = "Qubes" + vmtype.replace("VM", "Vm")
thread_monitor = ThreadMonitor()
thread = threading.Thread (target=self.do_create_vm, args=(vmclass, vmname, label, template_vm, standalone, allow_networking, thread_monitor))
thread = threading.Thread (target=self.do_create_vm, args=(vmclass, vmname, label, template_vm, netvm, standalone, allow_networking, thread_monitor))
thread.daemon = True
thread.start()
@ -205,7 +246,7 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
def do_create_vm (self, vmclass, vmname, label, template_vm, standalone, allow_networking, thread_monitor):
def do_create_vm (self, vmclass, vmname, label, template_vm, netvm, standalone, allow_networking, thread_monitor):
vm = None
try:
self.qvm_collection.lock_db_for_writing()
@ -220,6 +261,13 @@ class NewVmDlg (QDialog, Ui_NewVMDlg):
if allow_networking == False:
vm.uses_default_netvm = False
vm.netvm = None
else:
vm.netvm = netvm
if vm.netvm == self.qvm_collection.get_default_netvm():
vm.uses_default_netvm = True
else:
vm.uses_default_netvm = False
self.qvm_collection.save()
except Exception as ex: