Ejemplo n.º 1
0
    def _get_available_nvmf_subsystems(self):
        __, tmp_file_path = tempfile.mkstemp(prefix='nvmet')

        # nvmetcli doesn't support printing to stdout yet,
        try:
            out, err = nvmcli.save(tmp_file_path)
        except putils.ProcessExecutionError:
            with excutils.save_and_reraise_exception():
                LOG.exception('Error from nvmetcli save')
                self._delete_file(tmp_file_path)

        # temp file must be readable by this process user
        # in order to avoid executing cat as root
        with utils.temporary_chown(tmp_file_path):
            try:
                out = cinder.privsep.path.readfile(tmp_file_path)
            except putils.ProcessExecutionError:
                with excutils.save_and_reraise_exception():
                    LOG.exception('Failed to read: %s', tmp_file_path)
                    self._delete_file(tmp_file_path)
            nvmf_subsystems = json.loads(out)

        self._delete_file(tmp_file_path)

        return nvmf_subsystems
Ejemplo n.º 2
0
    def _get_available_nvmf_subsystems(self):
        __, tmp_file_path = tempfile.mkstemp(prefix='nvmet')

        # nvmetcli doesn't support printing to stdout yet,
        try:
            out, err = nvmcli.save(tmp_file_path)
        except putils.ProcessExecutionError:
            with excutils.save_and_reraise_exception():
                LOG.exception('Error from nvmetcli save')
                self._delete_file(tmp_file_path)

        # temp file must be readable by this process user
        # in order to avoid executing cat as root
        with utils.temporary_chown(tmp_file_path):
            try:
                out = cinder.privsep.path.readfile(tmp_file_path)
            except putils.ProcessExecutionError:
                with excutils.save_and_reraise_exception():
                    LOG.exception('Failed to read: %s', tmp_file_path)
                    self._delete_file(tmp_file_path)
            nvmf_subsystems = json.loads(out)

        self._delete_file(tmp_file_path)

        return nvmf_subsystems