コード例 #1
0
    def ok(self, ignore1=None, ignore2=None):
        if self.widget("iso-image").get_active():
            path = self.widget("iso-path").get_text()
        else:
            path = self.mediacombo.get_path()
        if path == "" or path is None:
            return self.err.val_err(_("Invalid Media Path"),
                                    _("A media path must be specified."))

        names = DeviceDisk.path_in_use_by(self.disk.conn, path)
        if names:
            res = self.err.yes_no(
                _('Disk "%s" is already in use by other guests %s') %
                (path, names), _("Do you really want to use the disk?"))
            if not res:
                return False

        vmmAddStorage.check_path_search(self, self.conn, path)

        try:
            self.disk.path = path
        except Exception as e:
            return self.err.val_err(_("Invalid Media Path"), e)

        self.emit("cdrom-chosen", self.disk, path)
        self.close()
コード例 #2
0
ファイル: storagelist.py プロジェクト: zz38/virt-manager
    def _populate_vols(self):
        list_widget = self.widget("vol-list")
        pool = self._current_pool()
        vols = pool and pool.get_volumes() or []
        model = list_widget.get_model()
        list_widget.get_selection().unselect_all()
        model.clear()

        vadj = self.widget("vol-scroll").get_vadjustment()
        vscroll_percent = vadj.get_value() // max(vadj.get_upper(), 1)

        for vol in vols:
            key = vol.get_connkey()

            try:
                path = vol.get_target_path()
                name = vol.get_pretty_name(pool.get_type())
                cap = str(vol.get_capacity())
                sizestr = vol.get_pretty_capacity()
                fmt = vol.get_format() or ""
            except Exception:
                logging.debug(
                    "Error getting volume info for '%s', "
                    "hiding it",
                    key,
                    exc_info=True)
                continue

            namestr = None
            try:
                if path:
                    names = DeviceDisk.path_in_use_by(vol.conn.get_backend(),
                                                      path)
                    namestr = ", ".join(names)
                    if not namestr:
                        namestr = None
            except Exception:
                logging.exception("Failed to determine if storage volume in "
                                  "use.")

            sensitive = True
            if self._vol_sensitive_cb:
                sensitive = self._vol_sensitive_cb(fmt)

            row = [None] * VOL_NUM_COLUMNS
            row[VOL_COLUMN_KEY] = key
            row[VOL_COLUMN_NAME] = name
            row[VOL_COLUMN_SIZESTR] = sizestr
            row[VOL_COLUMN_CAPACITY] = cap
            row[VOL_COLUMN_FORMAT] = fmt
            row[VOL_COLUMN_INUSEBY] = namestr
            row[VOL_COLUMN_SENSITIVE] = sensitive
            model.append(row)

        def _reset_vscroll_position():
            vadj.set_value(vadj.get_upper() * vscroll_percent)

        self.idle_add(_reset_vscroll_position)
コード例 #3
0
    def _populate_vols(self):
        list_widget = self.widget("vol-list")
        pool = self._current_pool()
        vols = pool and pool.get_volumes() or []
        model = list_widget.get_model()
        list_widget.get_selection().unselect_all()
        model.clear()

        vadj = self.widget("vol-scroll").get_vadjustment()
        vscroll_percent = vadj.get_value() // max(vadj.get_upper(), 1)

        for vol in vols:
            key = vol.get_connkey()

            try:
                path = vol.get_target_path()
                name = vol.get_pretty_name(pool.get_type())
                cap = str(vol.get_capacity())
                sizestr = vol.get_pretty_capacity()
                fmt = vol.get_format() or ""
            except Exception:
                logging.debug("Error getting volume info for '%s', "
                              "hiding it", key, exc_info=True)
                continue

            namestr = None
            try:
                if path:
                    names = DeviceDisk.path_in_use_by(vol.conn.get_backend(),
                                                       path)
                    namestr = ", ".join(names)
                    if not namestr:
                        namestr = None
            except Exception:
                logging.exception("Failed to determine if storage volume in "
                                  "use.")

            sensitive = True
            if self._vol_sensitive_cb:
                sensitive = self._vol_sensitive_cb(fmt)

            row = [None] * VOL_NUM_COLUMNS
            row[VOL_COLUMN_KEY] = key
            row[VOL_COLUMN_NAME] = name
            row[VOL_COLUMN_SIZESTR] = sizestr
            row[VOL_COLUMN_CAPACITY] = cap
            row[VOL_COLUMN_FORMAT] = fmt
            row[VOL_COLUMN_INUSEBY] = namestr
            row[VOL_COLUMN_SENSITIVE] = sensitive
            model.append(row)

        def _reset_vscroll_position():
            vadj.set_value(vadj.get_upper() * vscroll_percent)
        self.idle_add(_reset_vscroll_position)