[virt-tools-list] [virt-manager PATCH] virt-manager: add support for startupPolicy config when adding new storage device
Chen Hanxiao
chen_han_xiao at 126.com
Tue Feb 4 11:55:36 UTC 2014
From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
We could define policy what to do with the disk
if the source file is not accessible.
This patch will add support for startupPolicy config
when adding new storage device.
Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
ui/addhardware.ui | 27 +++++++++++++++++++++++++++
virtManager/addhardware.py | 26 ++++++++++++++++++++++++++
virtinst/devicedisk.py | 9 ++++++++-
3 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 47967a6..d29d472 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -290,6 +290,33 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">St_artup policy:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="config-startup-policy">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
</child>
<child type="label">
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 727e959..b3117ad 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -220,6 +220,10 @@ class vmmAddHardware(vmmGObjectUI):
# Disk format mode
self.populate_disk_format_combo_wrapper(True)
+ # Disk startup policy
+ policy_list = self.widget("config-startup-policy")
+ self.build_disk_sourceStartupPolicy_combo(self.vm, policy_list)
+
# Input device type
input_list = self.widget("input-type")
input_model = Gtk.ListStore(str, str, str)
@@ -712,6 +716,21 @@ class vmmAddHardware(vmmGObjectUI):
combo.set_active(-1)
@staticmethod
+ def build_disk_sourceStartupPolicy_combo(vm, combo, no_default=False):
+ ignore = vm
+ model = Gtk.ListStore(str, str)
+ combo.set_model(model)
+ uiutil.set_combo_text_column(combo, 1)
+
+ combo.set_active(-1)
+ for m in virtinst.VirtualDisk.startup_policies:
+ model.append([m, m])
+
+ if not no_default:
+ model.append([None, "None"])
+ combo.set_active(0)
+
+ @staticmethod
def populate_disk_format_combo(vm, combo, create):
model = Gtk.ListStore(str)
combo.set_model(model)
@@ -923,6 +942,10 @@ class vmmAddHardware(vmmGObjectUI):
fmt = self.widget("config-storage-format")
return fmt.get_child().get_text()
+ def get_config_disk_sourceStartupPolicy(self):
+ return uiutil.get_list_selection(
+ self.widget("config-startup-policy"), 0)
+
# Input getters
def get_config_input(self):
row = uiutil.get_list_selection(self.widget("input-type"))
@@ -1447,6 +1470,7 @@ class vmmAddHardware(vmmGObjectUI):
bus = self.get_config_disk_bus()
device = self.get_config_disk_device()
cache = self.get_config_disk_cache()
+ sourceStartupPolicy = self.get_config_disk_sourceStartupPolicy()
fmt = self.get_config_disk_format()
controller_model = None
@@ -1464,6 +1488,8 @@ class vmmAddHardware(vmmGObjectUI):
disk.bus = bus
if cache:
disk.driver_cache = cache
+ if sourceStartupPolicy:
+ disk.sourceStartupPolicy = sourceStartupPolicy
# Generate target
if not self.is_customize_dialog:
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index ce407ba..4526cb8 100644
--- a/virtinst/devicedisk.py
+++ b/virtinst/devicedisk.py
@@ -182,6 +182,13 @@ class VirtualDisk(VirtualDevice):
IO_MODE_THREADS = "threads"
io_modes = [IO_MODE_NATIVE, IO_MODE_THREADS]
+ STARTUP_POLICY_NONE = None
+ STARTUP_POLICY_MANDATORY = "mandatory"
+ STARTUP_POLICY_REQUISITE = "requisite"
+ STARTUP_POLICY_OPTIONAL = "optional"
+ startup_policies = [STARTUP_POLICY_NONE, STARTUP_POLICY_MANDATORY,
+ STARTUP_POLICY_REQUISITE, STARTUP_POLICY_OPTIONAL]
+
error_policies = ["ignore", "stop", "enospace", "report"]
@staticmethod
@@ -452,7 +459,7 @@ class VirtualDisk(VirtualDevice):
"type", "device",
"driver_name", "driver_type",
"driver_cache", "driver_io", "error_policy",
- "_xmlpath", "target", "bus",
+ "_xmlpath", "target", "bus", "sourceStartupPolicy",
]
def __init__(self, *args, **kwargs):
--
1.8.4.2
More information about the virt-tools-list
mailing list