virt-manager

changeset 1279:d46b95ddbbcf

createpool: Support logical pool enumeration.
author Cole Robinson <crobinso@redhat.com>
date Tue Oct 20 21:12:35 2009 -0400 (2009-10-20)
parents d4e84203126c
children 8fff2676bce1
files src/virtManager/createpool.py src/vmm-create-pool.glade
line diff
     1.1 --- a/src/virtManager/createpool.py	Tue Oct 20 20:20:59 2009 -0400
     1.2 +++ b/src/virtManager/createpool.py	Tue Oct 20 21:12:35 2009 -0400
     1.3 @@ -78,13 +78,19 @@
     1.4              "on_pool_format_focus": (self.update_doc, "format", "pool-info2"),
     1.5              "on_pool_format_changed": (self.update_doc_changed, "format",
     1.6                                         "pool-info2"),
     1.7 +
     1.8              "on_pool_target_path_focus_in_event": (self.update_doc,
     1.9                                                     "target_path",
    1.10                                                     "pool-info2"),
    1.11 +            "on_pool_target_path_focus": (self.update_doc, "target_path",
    1.12 +                                          "pool-info2"),
    1.13 +            "on_pool_target_path_changed": (self.update_doc_changed,
    1.14 +                                            "target_path",
    1.15 +                                            "pool-info2"),
    1.16 +
    1.17              "on_pool_source_path_focus_in_event": (self.update_doc,
    1.18                                                     "source_path",
    1.19                                                     "pool-info2"),
    1.20 -
    1.21              "on_pool_source_path_focus": (self.update_doc, "source_path",
    1.22                                            "pool-info2"),
    1.23              "on_pool_source_path_changed": (self.update_doc_changed,
    1.24 @@ -127,6 +133,15 @@
    1.25          format_list.pack_start(text2, False)
    1.26          format_list.add_attribute(text2, 'text', 1)
    1.27  
    1.28 +        # Target path combo box entry
    1.29 +        target_list = self.window.get_widget("pool-target-path")
    1.30 +        # target_path, Label, pool class instance
    1.31 +        target_model = gtk.ListStore(str, str, object)
    1.32 +        target_list.set_model(target_model)
    1.33 +        target_list.set_text_column(0)
    1.34 +        target_list.child.connect("focus-in-event", self.update_doc,
    1.35 +                                  "target_path", "pool-info2")
    1.36 +
    1.37          # Source path combo box entry
    1.38          source_list = self.window.get_widget("pool-source-path")
    1.39          # source_path, Label, pool class instance
    1.40 @@ -149,7 +164,7 @@
    1.41  
    1.42          self.window.get_widget("pool-name").set_text("")
    1.43          self.window.get_widget("pool-type").set_active(0)
    1.44 -        self.window.get_widget("pool-target-path").set_text("")
    1.45 +        self.window.get_widget("pool-target-path").child.set_text("")
    1.46          self.window.get_widget("pool-source-path").child.set_text("")
    1.47          self.window.get_widget("pool-hostname").set_text("")
    1.48          self.window.get_widget("pool-format").set_active(-1)
    1.49 @@ -172,24 +187,35 @@
    1.50          for f in formats:
    1.51              model.append([f, f])
    1.52  
    1.53 -    def populate_source_paths(self):
    1.54 -        widget = self.window.get_widget("pool-source-path")
    1.55 -        model = widget.get_model()
    1.56 -        model.clear()
    1.57 +    def populate_pool_sources(self):
    1.58 +        source_list = self.window.get_widget("pool-source-path")
    1.59 +        source_model = source_list.get_model()
    1.60 +        source_model.clear()
    1.61  
    1.62 +        target_list = self.window.get_widget("pool-target-path")
    1.63 +        target_model = target_list.get_model()
    1.64 +        target_model.clear()
    1.65 +
    1.66 +        use_list = source_list
    1.67 +        use_model = source_model
    1.68          entry_list = []
    1.69          if self._pool.type == Storage.StoragePool.TYPE_SCSI:
    1.70              entry_list = self.list_scsi_adapters()
    1.71 +            use_list = source_list
    1.72 +            use_model = source_model
    1.73 +
    1.74 +        elif self._pool.type == Storage.StoragePool.TYPE_LOGICAL:
    1.75 +            pool_list = self.list_pool_sources()
    1.76 +            entry_list = map(lambda p: [p.target_path, p.target_path, p],
    1.77 +                             pool_list)
    1.78 +            use_list = target_list
    1.79 +            use_model = target_model
    1.80  
    1.81          for e in entry_list:
    1.82 -            model.append(e)
    1.83 +            use_model.append(e)
    1.84  
    1.85          if entry_list:
    1.86 -            widget.set_active(0)
    1.87 -            widget.child.set_editable(False)
    1.88 -        else:
    1.89 -            widget.set_active(-1)
    1.90 -            widget.child.set_editable(True)
    1.91 +            use_list.set_active(0)
    1.92  
    1.93      def list_scsi_adapters(self):
    1.94          scsi_hosts = self.conn.get_devices("scsi_host")
    1.95 @@ -208,6 +234,19 @@
    1.96  
    1.97          return clean_list
    1.98  
    1.99 +    def list_pool_sources(self):
   1.100 +        name = self.get_config_name()
   1.101 +        pool_type = self._pool.type
   1.102 +
   1.103 +        plist = []
   1.104 +        try:
   1.105 +            plist = Storage.StoragePool.pool_list_from_sources(self.conn.vmm,
   1.106 +                                                               name, pool_type)
   1.107 +        except Exception, e:
   1.108 +            logging.exception("Pool enumeration failed")
   1.109 +
   1.110 +        return plist
   1.111 +
   1.112      def show_options_by_pool(self):
   1.113          src     = hasattr(self._pool, "source_path")
   1.114          src_b   = src and not self.conn.is_remote()
   1.115 @@ -233,7 +272,7 @@
   1.116              self.populate_pool_format()
   1.117              self.window.get_widget("pool-format").set_active(0)
   1.118  
   1.119 -        self.populate_source_paths()
   1.120 +        self.populate_pool_sources()
   1.121  
   1.122  
   1.123      def get_config_type(self):
   1.124 @@ -246,7 +285,17 @@
   1.125          return self.window.get_widget("pool-name").get_text()
   1.126  
   1.127      def get_config_target_path(self):
   1.128 -        return self.window.get_widget("pool-target-path").get_text()
   1.129 +        src = self.window.get_widget("pool-target-path")
   1.130 +        if not src.get_property("sensitive"):
   1.131 +            return None
   1.132 +
   1.133 +        # If we provide the user with a drop down
   1.134 +        model = src.get_model()
   1.135 +        selection = src.get_active()
   1.136 +        if selection != -1:
   1.137 +            return model[selection][1]
   1.138 +
   1.139 +        return src.child.get_text()
   1.140  
   1.141      def get_config_source_path(self):
   1.142          src = self.window.get_widget("pool-source-path")
   1.143 @@ -304,7 +353,7 @@
   1.144                                     startfolder="/var/lib/libvirt",
   1.145                                     foldermode=True)
   1.146          if target:
   1.147 -            self.window.get_widget("pool-target-path").set_text(target)
   1.148 +            self.window.get_widget("pool-target-path").child.set_text(target)
   1.149  
   1.150  
   1.151      def forward(self, ignore=None):
   1.152 @@ -371,7 +420,7 @@
   1.153              self.window.get_widget("pool-forward").show()
   1.154          elif page_number == PAGE_FORMAT:
   1.155              self.show_options_by_pool()
   1.156 -            self.window.get_widget("pool-target-path").set_text(self._pool.target_path)
   1.157 +            self.window.get_widget("pool-target-path").child.set_text(self._pool.target_path)
   1.158              self.window.get_widget("pool-back").set_sensitive(True)
   1.159              buildret = self.get_build_default()
   1.160              self.window.get_widget("pool-build").set_sensitive(buildret[1])
   1.161 @@ -386,11 +435,14 @@
   1.162          pools we find via FindPoolSources, this will be different
   1.163          """
   1.164          source_list = self.window.get_widget("pool-source-path")
   1.165 +        target_list = self.window.get_widget("pool-target-path")
   1.166  
   1.167          pool = copy.copy(self._pool)
   1.168  
   1.169          if source_list.get_active() != -1:
   1.170              pool = source_list.get_model()[source_list.get_active()][2]
   1.171 +        elif target_list.get_active() != -1:
   1.172 +            pool = target_list.get_model()[target_list.get_active()][2]
   1.173  
   1.174          return pool
   1.175  
     2.1 --- a/src/vmm-create-pool.glade	Tue Oct 20 20:20:59 2009 -0400
     2.2 +++ b/src/vmm-create-pool.glade	Tue Oct 20 21:12:35 2009 -0400
     2.3 @@ -402,10 +402,9 @@
     2.4                            <widget class="GtkHBox" id="hbox13">
     2.5                              <property name="visible">True</property>
     2.6                              <child>
     2.7 -                              <widget class="GtkEntry" id="pool-target-path">
     2.8 +                              <widget class="GtkComboBoxEntry" id="pool-target-path">
     2.9                                  <property name="visible">True</property>
    2.10 -                                <property name="can_focus">True</property>
    2.11 -                                <property name="invisible_char">&#x25CF;</property>
    2.12 +                                <signal name="changed" handler="on_pool_target_path_changed"/>
    2.13                                  <signal name="focus_in_event" handler="on_pool_target_path_focus_in_event"/>
    2.14                                </widget>
    2.15                                <packing>