summaryrefslogtreecommitdiffstats
path: root/com.gluster.storage.management.server.scripts/src/nodes/ServerRequestHandler.py
blob: 31d4eb8cba7e4b0cedfd5e7038ec30745740cfb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#  Copyright (C) 2010 Gluster, Inc. <http://www.gluster.com>
#  This file is part of Gluster Storage Platform.
#
#  Gluster Storage Platform is free software; you can redistribute it
#  and/or modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 3 of
#  the License, or (at your option) any later version.
#
#  Gluster Storage Platform is distributed in the hope that it will be
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
#  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see
#  <http://www.gnu.org/licenses/>.

import os

import Commands
from Protocol import *
from Globals import *
from GetServerNetworkConfig import *

def handleRequestGetServerNetworkConfig(requestDom):
    return getServerNetworkConfig(requestDom)

def handleRequest(requestString):
    log("Received request %s" % repr(requestString))

    requestDom = XDOM()
    requestDom.parseString(requestString)
    if not requestDom:
        log("Invalid request")
        return None

    preRequestMap = {}

    postRequestMap = {}

    cleanupRequestMap = {}

    requestMap = { Commands.COMMAND_GET_SERVER_NETWORK_CONFIG        : handleRequestGetServerNetworkConfig }

    messageId = requestDom.getMessageId()
    if not messageId:
        log("Invalid message Id")
        return None

    requestCommand = requestDom.getRequestCommand()
    if not requestCommand:
        log("invalid request command")
        return None

    requestAction = requestDom.getRequestAction()
    version = requestDom.getVersion()
    #if not isSupportedVersion(version):
    #    log("Unsupported version request %s" % requestDom.toxml())
    #    return ResponseXml(requestCommand, "Unsupported version request", messageId, version).toxml()

    try:
        if not requestAction:
            responseDom = requestMap[requestCommand](requestDom)
        elif requestAction.upper() == "PRE":
            responseDom = preRequestMap[requestCommand](requestDom)
        elif requestAction.upper() == "POST":
            responseDom = postRequestMap[requestCommand](requestDom)
        elif requestAction.upper() == "CLEANUP":
            responseDom = cleanupRequestMap[requestCommand](requestDom)
        else:
            log("Unknown request action %s" % requestAction)
            return None
        return responseDom.toxml()
    except KeyError:
        log("No handler found for command %s for action %s" % (requestCommand, requestAction))
        return ResponseXml(requestCommand, "Invalid command", messageId, version).toxml()