Exemple #1
0
def get_iscsi_initiator():
    """Get iscsi initiator name for this machine"""
    # NOTE(vish) openiscsi stores initiator name in a file that
    #            needs root permission to read.
    contents = utils.read_file_as_root('/etc/iscsi/initiatorname.iscsi')
    for l in contents.split('\n'):
        if l.startswith('InitiatorName='):
            return l[l.index('=') + 1:].strip()
Exemple #2
0
def get_iscsi_initiator():
    """Get iscsi initiator name for this machine"""
    # NOTE(vish) openiscsi stores initiator name in a file that
    #            needs root permission to read.
    contents = utils.read_file_as_root('/etc/iscsi/initiatorname.iscsi')
    for l in contents.split('\n'):
        if l.startswith('InitiatorName='):
            return l[l.index('=') + 1:].strip()
Exemple #3
0
    def test_read_file_as_root(self):
        def fake_execute(*args, **kwargs):
            if args[1] == "bad":
                raise processutils.ProcessExecutionError()
            return "fakecontents", None

        self.stubs.Set(utils, "execute", fake_execute)
        contents = utils.read_file_as_root("good")
        self.assertEqual(contents, "fakecontents")
        self.assertRaises(exception.FileNotFound, utils.read_file_as_root, "bad")
Exemple #4
0
    def test_read_file_as_root(self):
        def fake_execute(*args, **kwargs):
            if args[1] == 'bad':
                raise processutils.ProcessExecutionError()
            return 'fakecontents', None

        self.stubs.Set(utils, 'execute', fake_execute)
        contents = utils.read_file_as_root('good')
        self.assertEqual(contents, 'fakecontents')
        self.assertRaises(exception.FileNotFound,
                          utils.read_file_as_root, 'bad')
Exemple #5
0
    def test_read_file_as_root(self):
        def fake_execute(*args, **kwargs):
            if args[1] == 'bad':
                raise processutils.ProcessExecutionError()
            return 'fakecontents', None

        self.stubs.Set(utils, 'execute', fake_execute)
        contents = utils.read_file_as_root('good')
        self.assertEqual(contents, 'fakecontents')
        self.assertRaises(exception.FileNotFound, utils.read_file_as_root,
                          'bad')
def get_iscsi_initiator():
    """
    This is a basic implementation of the iscsi stuff needed for external
    volumes.  This should live in a utility module when the openvz driver is
    broken up.
    """
    # code borrowed from libvirt utils
    contents = utils.read_file_as_root('/etc/iscsi/initiatorname.iscsi')
    for l in contents.split('\n'):
        if l.startswith('InitiatorName='):
            return l[l.index('=') + 1:].strip()
Exemple #7
0
def get_iscsi_initiator():
    """Get iscsi initiator name for this machine."""
    # NOTE(vish) openiscsi stores initiator name in a file that
    #            needs root permission to read.
    try:
        contents = utils.read_file_as_root("/etc/iscsi/initiatorname.iscsi")
    except exception.FileNotFound:
        return None

    for l in contents.split("\n"):
        if l.startswith("InitiatorName="):
            return l[l.index("=") + 1 :].strip()
Exemple #8
0
 def _update_mds_list(self, data):
     mds_list_path = os.path.join('/etc/pstorage/clusters',
                         data['cluster_name'], 'bs.list')
     mds_list = utils.read_file_as_root(mds_list_path).splitlines()
     if set(mds_list) != set(data['mds_list']):
         LOG.info("Updating MDS list ...")
         fd, name = tempfile.mkstemp()
         f = os.fdopen(fd)
         f.write('\n'.join(data['mds_list']))
         f.close()
         utils.execute('cp', '-f', name, mds_list_path)
         os.unlink(name)
Exemple #9
0
    def read_file(self, path):
        LOG.debug("Read file path=%s", path)
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)
Exemple #10
0
    def read_file(self, path):
        LOG.debug(_("Read file path=%s"), path)
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)
Exemple #11
0
    def read_file(self, path):
        LOG.debug(_("Read file path=%(path)s") % locals())
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)