Change in vdsm[master]: gluster: VDSM Gluster verb to set swift configuration

avishwan at redhat.com avishwan at redhat.com
Thu Mar 28 06:36:28 UTC 2013


Aravinda VK has uploaded a new change for review.

Change subject: gluster: VDSM Gluster verb to set swift configuration
......................................................................

gluster: VDSM Gluster verb to set swift configuration

VDSM Gluster verb for UFO(Unified File Object) configuration
manage.(setting the swift configuration)

glusterSwiftConfigSet: Set the config items from swift
proxy/account/object/container server

Change-Id: Ibba9c30d1ad4926c88e58cb4bc9a858b8a07f77b
Signed-off-by: Aravinda VK <avishwan at redhat.com>
---
M vdsm/gluster/api.py
M vdsm/gluster/exception.py
M vdsm/gluster/swift.py
M vdsm_cli/vdsClientGluster.py
4 files changed, 95 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/83/13383/1

diff --git a/vdsm/gluster/api.py b/vdsm/gluster/api.py
index bb0666f..e6ea775 100644
--- a/vdsm/gluster/api.py
+++ b/vdsm/gluster/api.py
@@ -225,6 +225,11 @@
                                                              configOption)
         return {"config": configValues}
 
+    @exportAsVerb
+    def swiftConfigSet(self, serverType, configDict, options=None):
+        self.svdsmProxy.glusterSwiftConfigSet(serverType,
+                                              configDict)
+
 
 def getGlusterMethods(gluster):
     l = []
diff --git a/vdsm/gluster/exception.py b/vdsm/gluster/exception.py
index 89421d4..c66e4b2 100644
--- a/vdsm/gluster/exception.py
+++ b/vdsm/gluster/exception.py
@@ -419,3 +419,8 @@
 
     def __init__(self, opt=""):
         self.err = ["Invalid Swift Config option: %s" % opt]
+
+
+class GlusterSwiftConfigWriteFailedException(GlusterGeneralException):
+    code = 4412
+    message = "Swift Config file write failed"
diff --git a/vdsm/gluster/swift.py b/vdsm/gluster/swift.py
index 4442dd5..6dc6f5d 100644
--- a/vdsm/gluster/swift.py
+++ b/vdsm/gluster/swift.py
@@ -19,6 +19,8 @@
 #
 
 from ConfigParser import DEFAULTSECT, ConfigParser
+import tempfile
+import shutil
 
 from . import exportToSuperVdsm
 import exception as ge
@@ -104,3 +106,60 @@
 @exportToSuperVdsm
 def swiftConfigGet(serverType, section=None, configOption=None):
     return _configGet(serverType, section, configOption)
+
+
+def _writeSwiftConfigFile(serverType, config):
+    config_file = SWIFT_CONFIG_FILES[serverType]
+    try:
+        # Write to a temp file
+        tempConfigFile = tempfile.NamedTemporaryFile(mode="wb", delete=False)
+        with open(tempConfigFile.name, 'wb') as configFile:
+            config.write(configFile)
+
+        # If src and dst are two different file system, then os.rename
+        # fails, In this case if temp file created in /tmp and if /tmp is
+        # seperate fs then os.rename gives following error, so use shutil
+        # OSError: [Errno 18] Invalid cross-device link
+        # mail.python.org/pipermail/python-list/2005-February/342893.html
+        shutil.move(tempConfigFile.name, config_file)
+    except IOError as e:
+        errMsg = "[Errno %s] %s: '%s'" % (e.errno, e.strerror, e.filename)
+        raise ge.GlusterSwiftConfigWriteFailedException(err=[errMsg])
+
+
+def _configSet(serverType, configDict):
+    """
+    Set config values in swift config files
+    :param serverType Type of swift server(gluster-swift-proxy,
+    gluster-swift-account, gluster-swift-object, gluster-swift-container)
+    :param configDict Dict of items to update with section name as key
+    Ex: {"section1": {"configOpt1": "value1", "configOpt2": "value2"},..}
+    """
+    config = _openSwiftConfigFile(serverType)
+
+    # Every section query automatically includes DEFAULTS options,
+    # to avoid this remove default options and reconstruct at the end
+    defaultValues = dict(config.defaults())
+    config._defaults = {}
+
+    for section in configDict:
+        if not config.has_section(section) and section.upper() != DEFAULTSECT:
+            config.add_section(section)
+
+        for configOption in configDict[section]:
+            value = configDict[section][configOption]
+            # Since default values seperated from main config object
+            # update defaultValues dict instead of config object
+            if section == DEFAULTSECT:
+                defaultValues[configOption] = value
+            else:
+                config.set(section, configOption, value)
+
+    # Restore defaults
+    config._defaults = defaultValues
+    _writeSwiftConfigFile(serverType, config)
+
+
+ at exportToSuperVdsm
+def swiftConfigSet(serverType, configDict):
+    _configSet(serverType, configDict)
diff --git a/vdsm_cli/vdsClientGluster.py b/vdsm_cli/vdsClientGluster.py
index ba1af88..6f80eb0 100644
--- a/vdsm_cli/vdsClientGluster.py
+++ b/vdsm_cli/vdsClientGluster.py
@@ -18,6 +18,7 @@
 #
 
 import pprint as pp
+import ast
 
 from vdsClient import service
 
@@ -325,6 +326,22 @@
         pp.pprint(status)
         return status['status']['code'], status['status']['message']
 
+    def do_glusterSwiftConfigSet(self, args):
+        params = self._eqSplit(args)
+        serverType = params.get('serverType', '')
+        if serverType == "":
+            raise ValueError
+        configDictStr = params.get('configDict', '{}')
+
+        try:
+            configDict = ast.literal_eval(configDictStr)
+        except:
+            raise ValueError
+
+        status = self.s.glusterSwiftConfigSet(serverType, configDict)
+        pp.pprint(status)
+        return status['status']['code'], status['status']['message']
+
 
 def getGlusterCmdDict(serv):
     return \
@@ -546,4 +563,13 @@
               'configOption is the config item in respective config file',
               'returns the Swift config values'
               )),
+         'glusterSwiftConfigSet': (
+             serv.do_glusterSwiftConfigSet,
+             ('serverType=<serverType> configDict=<configDict>\n\t',
+              'serverType is the type of swift service(proxy-server, '
+              'object-server, account-server, container-server)',
+              'configDict dict of config items which needs update'
+              '{"section1": {"key1": "value1", "key2": "value2"}..}',
+              'Updates the Swift configuration file'
+              )),
          }


--
To view, visit http://gerrit.ovirt.org/13383
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibba9c30d1ad4926c88e58cb4bc9a858b8a07f77b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Aravinda VK <avishwan at redhat.com>


More information about the vdsm-patches mailing list