예제 #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()
예제 #2
0
파일: utils.py 프로젝트: pnavarro/nova
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()
예제 #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")
예제 #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')
예제 #5
0
파일: test_utils.py 프로젝트: gweuieon/nova
    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')
예제 #6
0
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()
예제 #7
0
파일: utils.py 프로젝트: jettang/icehouse
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()
예제 #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)
예제 #9
0
파일: localfs.py 프로젝트: dtroyer/nova
    def read_file(self, path):
        LOG.debug("Read file path=%s", path)
        canonpath = self._canonical_path(path)

        return utils.read_file_as_root(canonpath)
예제 #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)
예제 #11
0
파일: localfs.py 프로젝트: CiscoAS/nova
    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)