Skip to content

Commit

Permalink
gluster:refactor: Refactor GlusterFSConnection class
Browse files Browse the repository at this point in the history
Gluster volume info is required when validating that gluster volume
is replica 3 and when calculating gluster backup servers option.
volinfo property introduced to save multiple calls to get gluster
volume info.
self._volname and self._volfileserver introduced because they are
used in multiple places in the code.

Change-Id: I3014723e1e3d1164a986f5e04208e199396b21b0
Signed-off-by: Ala Hino <ahino@redhat.com>
Reviewed-on: https://gerrit.ovirt.org/42952
Reviewed-by: Nir Soffer <nsoffer@redhat.com>
Continuous-Integration: Jenkins CI
Reviewed-by: Adam Litke <alitke@redhat.com>
  • Loading branch information
alhino authored and dankenigsberg committed Jun 29, 2015
1 parent 427e3a4 commit 907560b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions vdsm/storage/storageServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,32 +282,39 @@ def __init__(self,
vfsType=vfsType,
options=options,
mountClass=mountClass)
self._backup_servers_option = None
self._volinfo = None
self._volfileserver, volname = self._remotePath.split(":", 1)
self._volname = volname.strip('/')

@property
def options(self):
if self._backup_servers_option is None:
self._backup_servers_option = self._get_backup_servers_option()
backup_servers_option = self._get_backup_servers_option()
return ",".join(
p for p in (self._options, self._backup_servers_option) if p)
p for p in (self._options, backup_servers_option) if p)

@property
def volinfo(self):
if self._volinfo is None:
self._volinfo = self._get_gluster_volinfo()
return self._volinfo

def _get_backup_servers_option(self):
if "backup-volfile-servers" in self._options:
self.log.warn("Using user specified backup-volfile-servers option")
return ""

volfileServer, volname = self._remotePath.split(":", 1)
volname = volname.strip('/')
volInfo = supervdsm.getProxy().glusterVolumeInfo(volname,
volfileServer)
servers = [brick.split(":")[0]
for brick in volInfo[volname]['bricks']]
servers.remove(volfileServer)
servers = [brick.split(":")[0] for brick in self.volinfo['bricks']]
servers.remove(self._volfileserver)
if not servers:
return ""

return "backup-volfile-servers=" + ":".join(servers)

def _get_gluster_volinfo(self):
volinfo = supervdsm.getProxy().glusterVolumeInfo(self._volname,
self._volfileserver)
return volinfo[self._volname]


class NFSConnection(object):
DEFAULT_OPTIONS = ["soft", "nosharecache"]
Expand Down

0 comments on commit 907560b

Please sign in to comment.