コード例 #1
0
def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    cifsDirName = "%s/%s" % (Globals.CIFS_EXPORT_DIR, volumeName)

    if Utils.runCommand("mount -t glusterfs 127.0.0.1:%s %s" % (volumeName, volumeMountDirName)) != 0:
        Utils.log("Failed to mount volume %s" % (volumeName))
        sys.stderr.write("Failed to mount volume %s\n" % (volumeName))
        sys.exit(1)
    if Utils.runCommand("ln -fTs %s %s" % (volumeMountDirName, cifsDirName)) != 0:
        Utils.log("Failed to create reexport link %s" % cifsDirName)
        sys.stderr.write("Failed to create reexport link %s\n" % cifsDirName)
        sys.exit(2)
    if Utils.runCommand("/usr/sbin/selinuxenabled") == 0:
        if Utils.runCommand("chcon -t samba_share_t %s -h" % cifsDirName) != 0:
            Utils.log("Failed to change security context for the link %s" % cifsDirName)
            sys.stderr.write("Failed to change security context for the link %s\n" % cifsDirName)
            sys.exit(2)
    if not VolumeUtils.includeVolume(volumeName):
        Utils.log("Failed to include volume for CIFS reexport")
        sys.stderr.write("Failed to include volume for CIFS reexport\n")
        sys.exit(3)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(4)
    sys.exit(0)
コード例 #2
0
def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    cifsDirName = "%s/%s" % (Globals.CIFS_EXPORT_DIR, volumeName)

    if not Utils.removeFile(cifsDirName):
        Utils.log("Failed to remove reexport link %s" % cifsDirName)
        sys.stderr.write("Failed to remove reexport link %s\n" % cifsDirName)
        sys.exit(1)
    if not VolumeUtils.excludeVolume(volumeName):
        Utils.log("Failed to exclude volume for CIFS reexport")
        sys.stderr.write("Failed to exclude volume for CIFS reexport\n")
        sys.exit(2)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(3)
    if Utils.runCommand("umount %s" % (volumeMountDirName)) != 0:
        Utils.log("Failed to unmount volume %s" % (volumeName))
        sys.stderr.write("Failed to unmount volume %s\n" % (volumeName))
        sys.exit(4)
    sys.exit(0)
コード例 #3
0
ファイル: stop_volume_cifs.py プロジェクト: hjimmy/glustermg
def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    cifsDirName = "%s/%s" % (Globals.CIFS_EXPORT_DIR, volumeName)

    if not Utils.removeFile(cifsDirName):
        Utils.log("Failed to remove reexport link %s" % cifsDirName)
        sys.stderr.write("Failed to remove reexport link %s\n" % cifsDirName)
        sys.exit(1)
    if not VolumeUtils.excludeVolume(volumeName):
        Utils.log("Failed to exclude volume for CIFS reexport")
        sys.stderr.write("Failed to exclude volume for CIFS reexport\n")
        sys.exit(2)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(3)
    if Utils.runCommand("grep '%s ' /etc/mtab" % (volumeMountDirName), shell=True) == 0:
        if Utils.runCommand("umount -fl %s" % (volumeMountDirName)) != 0:
            Utils.log("Failed to unmount volume %s" % (volumeName))
            sys.stderr.write("Failed to unmount volume %s\n" % (volumeName))
            sys.exit(4)
    sys.exit(0)
コード例 #4
0
def main():
    volumeInfo = getGlusterVolumeInfo()
    if not volumeInfo:
        print "No volume present.  Removing CIFS volume configuration if any"
        Utils.runCommand("rm -fr %s/*" % Globals.VOLUME_CONF_DIR, root=True, shell=True)
        Utils.runCommand("rm -fr %s/*" % Globals.REEXPORT_DIR, root=True, shell=True)
        Utils.runCommand("rm -fr %s/*" % Globals.CIFS_EXPORT_DIR, root=True, shell=True)
        sys.exit(0)

    lines = Utils.readFile(Globals.VOLUME_SMBCONF_FILE)
    volumeSmbConfList = [line.strip() for line in lines]
    for volumeName in volumeInfo.keys():
        if not "include = %s/%s.smbconf" % (Globals.VOLUME_CONF_DIR, volumeName) in volumeSmbConfList:
            continue
        if 'STOPPED' == volumeInfo[volumeName]['VolumeStatus'].upper():
            Utils.runCommand("rmdir %s/%s" % (Globals.CIFS_EXPORT_DIR, volumeName), root=True)
            if not VolumeUtils.excludeVolume(volumeName):
                Utils.log("Failed to exclude %s volume for CIFS reexport" % volumeName)
            continue
        if 'STARTED' == volumeInfo[volumeName]['VolumeStatus'].upper():
            volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
            if Utils.runCommand("mount -t glusterfs 127.0.0.1:%s %s" % (volumeName, volumeMountDirName)) != 0:
                Utils.log("Failed to mount volume %s" % (volumeName))

    smbConfFileList = glob.glob("%s/*.smbconf" % Globals.VOLUME_CONF_DIR)
    volumeList = [smbConfFileName.split(".smbconf")[0].split("/")[-1] for smbConfFileName in smbConfFileList]
    danglingVolumeList = list(set(volumeList).difference(set(volumeInfo.keys())))
    if not danglingVolumeList:
        sys.exit(0)

    print "Cleaning up dangling volume(s):", danglingVolumeList
    for volumeName in danglingVolumeList:
        Utils.runCommand("rmdir %s/%s" % (Globals.REEXPORT_DIR, volumeName), root=True)
        Utils.runCommand("rm -f %s/%s" % (Globals.CIFS_EXPORT_DIR, volumeName), root=True)
        if not VolumeUtils.excludeVolume(volumeName):
            Utils.log("Failed to exclude volume %s for CIFS reexport" % volumeName)
        Utils.runCommand("rm -f %s/%s.smbconf" % (Globals.VOLUME_CONF_DIR, volumeName), root=True)

    sys.exit(0)
コード例 #5
0
def main():
    if len(sys.argv) < 3:
        sys.stderr.write("usage: %s VOLUME_NAME USER1 USER2 ...\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]
    userList = sys.argv[2:]

    if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, userList):
        sys.stderr.write("Failed to update volume cifs configuration\n")
        sys.exit(1)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(2)
    sys.exit(0)
コード例 #6
0
def main():
    if len(sys.argv) < 3:
        sys.stderr.write("usage: %s VOLUME_NAME USER1 USER2 ...\n" %
                         os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]
    userList = sys.argv[2:]

    if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, userList):
        sys.stderr.write("Failed to update volume cifs configuration\n")
        sys.exit(1)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(2)
    sys.exit(0)
コード例 #7
0
def main():
    if len(sys.argv) < 4:
        sys.stderr.write("usage: %s VOLUME_NAME OWNER HOSTALLOWED\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]
    owner = sys.argv[2]
    hostAllowed = sys.argv[3]

    if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, owner, hostAllowed):
        sys.stderr.write("Failed to update volume cifs configuration\n")
        sys.exit(1)
    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(2)
    sys.exit(0)
コード例 #8
0
def main():

   if len(sys.argv) < 2:
        sys.stderr.write("usage: %s VOLUME_NAME [ALLOWHOSTS]\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

   volumeName = sys.argv[1]
   allowhosts = "*"
   if len(sys.argv) == 3:
        allowhosts = sys.argv[2]

   if not VolumeUtils.writeVolumeCifsSharedConfiguration(volumeName, allowhosts):
        sys.stderr.write("Failed to update volume cifs configuration\n")
        sys.exit(1)
   if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(2)
   sys.exit(0)
コード例 #9
0
def main():
    if len(sys.argv) < 3:
        sys.stderr.write("usage: %s VOLUME_NAME USER1 USER2 ...\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]
    userList = sys.argv[2:]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    try:
        if not os.path.exists(volumeMountDirName):
            os.mkdir(volumeMountDirName)
    except OSError, e:
        Utils.log("failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.stderr.write("Failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.exit(1)

    if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, userList):
        sys.stderr.write("Failed to write volume cifs configuration\n")
        sys.exit(2)

    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(3)
    sys.exit(0)


if __name__ == "__main__":
    main()
コード例 #10
0
    volumeName = sys.argv[1]
    owner = sys.argv[2]
    hostAllowed = sys.argv[3]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    try:
        if not os.path.exists(volumeMountDirName):
            os.mkdir(volumeMountDirName)
#   junli.li change mod of volumeMountDirName to 777, then, writeusers can write to this dir
        os.system('chmod 777 ' + volumeMountDirName)
    except OSError, e:
        Utils.log("failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.stderr.write("Failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.exit(1)

#   add arguments to writeVolumeCifsConfiguration()   junli.li
#   if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, userList):
    if not VolumeUtils.writeVolumeCifsConfiguration(volumeName, owner, hostAllowed):
        sys.stderr.write("Failed to write volume cifs configuration\n")
        sys.exit(2)

    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(3)
    sys.exit(0)


if __name__ == "__main__":
    main()
コード例 #11
0
    sys.path.append(p2)
import Globals
import Utils
import VolumeUtils


def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    try:
        if os.path.exists(volumeMountDirName):
            os.rmdir(volumeMountDirName)
    except OSError, e:
        Utils.log("failed deleting %s: %s\n" % (volumeMountDirName, str(e)))
        sys.stderr.write("Failed deleting %s: %s\n" % (volumeMountDirName, str(e)))
        sys.exit(1)

    if VolumeUtils.removeVolumeCifsConfiguration(volumeName):
        sys.exit(0)
    sys.stderr.write("Unable to remove volume cifs configuration\n")
    sys.exit(2)


if __name__ == "__main__":
    main()
コード例 #12
0
    sys.path.append(p1)
if not p2 in sys.path:
    sys.path.append(p2)
import Globals
import Utils
import VolumeUtils

def main():
    if len(sys.argv) != 2:
        sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0]))
        sys.exit(-1)

    volumeName = sys.argv[1]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    try:
        os.rmdir(volumeMountDirName)
    except OSError, e:
        Utils.log("failed deleting %s: %s\n" % (volumeMountDirName, str(e)))
        sys.stderr.write("Failed deleting %s: %s\n" % (volumeMountDirName, str(e)))
        sys.exit(1)

    if VolumeUtils.removeVolumeCifsConfiguration(volumeName):
        sys.exit(0)
    sys.stderr.write("Unable to remove volume cifs configuration\n")
    sys.exit(2)


if __name__ == "__main__":
    main()
コード例 #13
0
    volumeName = sys.argv[1]
    allowhosts = "*"
    if len(sys.argv) == 3:
	allowhosts = sys.argv[2]

    volumeMountDirName = "%s/%s" % (Globals.REEXPORT_DIR, volumeName)
    try:
        if not os.path.exists(volumeMountDirName):
            os.mkdir(volumeMountDirName)
#   junli.li change mod of volumeMountDirName to 777, then, writeusers can write to this dir
        os.system('chmod 777 ' + volumeMountDirName)
        os.system('chown -R nobody:nobody ' + volumeMountDirName)
    except OSError, e:
        Utils.log("failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.stderr.write("Failed creating %s: %s\n" % (volumeMountDirName, str(e)))
        sys.exit(1)

    if not VolumeUtils.writeVolumeCifsSharedConfiguration(volumeName, allowhosts):
        sys.stderr.write("Failed to write volume cifs configuration\n")
        sys.exit(2)

    if Utils.runCommand("service smb reload") != 0:
        Utils.log("Failed to reload smb service")
        sys.stderr.write("Failed to reload smb service\n")
        sys.exit(3)
    sys.exit(0)


if __name__ == "__main__":
    main()
コード例 #14
0
def getLogs(clusterName,volumeName, brickName,linecount='100', severity=None, fromTimeStamp=None, toTimeStamp=None):
    params = []
    params.append(clusterName)
    params.append(volumeName)
    params.append(brickName)
    params.append(linecount)
    params.append(severity)
    params.append(fromTimeStamp)
    params.append(toTimeStamp)
    web.header('Content-Type', 'application/xml')
    print severity

    if severity not in Globals.VOLUME_LOG_TYPE:
        code,reval = '23501','bad severity type:%s' % severity
        result = Utils.errorCode(code, reval, params)
        web.HTTPError(status = "400 Bad request", data = result)
        return result

    volLogList = []
    if (brickName is not None) and (brickName.strip() is not ''):
        server_dir = brickName.split(':/')
        if len(server_dir) == 2:
            file = server_dir[1].strip()
            log = file.replace('/', '-')
            LOGFILE = BRICK_LOG_DIR + log + '.log*'
            cmd = 'python ' + BACKEND_SCRIPT + 'get_volume_brick_log.py ' + LOGFILE + ' ' + str(linecount)

            (status,output) = Utils.executeOnServer(server_dir[0].strip(), cmd)
            output.replace('\n',' ')
            if status == -1:
                code, reval = '26104', 'error when connecting to remote host ' + server_dir[0].strip() + ' from localhost:' + output
            elif status == -2:
                code,reval = '26059', 'Error when using pub key to connect remote server ' + server_dir[0].strip() + '.' + output
            elif status == 1:
                if re.match('volume log not found',output):
                    code, reval = '20053', 'volume ' + volumeName + ' does not exist.\n' + output
                    result = Utils.errorCode(code, reval, params)
                    web.HTTPError(status = "400 Bad request", data = result)
                    return result
                else:
                    code, reval = '23015', 'Error when executing "' + cmd + '".\n' + output
            if status:
                result = Utils.errorCode(code, reval, params)
                web.HTTPError(status = "400 Bad Request", data = '')
                return result
            weblog = xml.etree.ElementTree.fromstring(output) 
            for entry in weblog.findall("logMessage"):
                volumeLogMessage = VolumeLogMessage()
                volumeLogMessage.setBrick(brickName)
                volumeLogMessage.setMessage(entry.find('message').text)
                volumeLogMessage.setSeverity(entry.find('severity').text)
                volumeLogMessage.setTimestamp(entry.find('timestamp').text)
                volLogList.append(volumeLogMessage)
    else:
        cmd = 'python ' + BACKEND_SCRIPT + 'get_volume_bricks.py ' + volumeName
        serverName = volumeService.getServerName(clusterName)
        (status,output) = Utils.executeOnServer(serverName, cmd)
        list = output.split(' ')
        if list[-1] == 'exist':
            result = Utils.errorCode('20053', 'volume ' + volumeName + ' does not exist', params)
            raise web.HTTPError(status='400 Bad Request', data=result)
        bricklist = output.split('\n')
        VolumeUtils.isExecSucess(status, output, serverName, volumeName, cmd, '23130', params)
        #if status == -1:
        #    code, reval = '26104', 'error when connecting to remote host [' + serverName + '] from localhost:' + output
        #elif status == -2:
        #    code,reval = '26059', 'Error when using pub key to connect remote server [' + serverName + '].' + output
        #elif status == 1:
        #    code, reval = '23019','Error when getting bricks from server [' + serverName + '].'
        #result = ''
        #if status:
        #    web.header('Content-Type', 'text/xml')
        #    result = Utils.errorCode(code, reval, [])
        #    web.HTTPError(status = "400 Bad Request", data = '')
        #    return result
        for brick in bricklist:
            server_dir = brick.split(':/')
            if len(server_dir) != 2:
                break
            file = server_dir[1].strip()
            log = file.replace('/', '-')
            LOGFILE = BRICK_LOG_DIR + log + '.log'
            cmd = 'python ' + BACKEND_SCRIPT + 'get_volume_brick_log.py ' + LOGFILE + ' ' + str(linecount)
            status,output = Utils.executeOnServer(server_dir[0].strip(), cmd) 
            if status == -1:
                code, reval = '26104', 'error when connecting to remote host ' + server_dir[0].strip() + ' from localhost:' + output
            elif status == -2:
                code,reval = '26059', 'Error when using pub key to connect remote server ' + server_dir[0].strip() + '.' + output
            elif status == 1:
                if re.match('exist', output):
                    code, reval = '20053', 'volume ' + volumeName + ' does not exist.\n' + output
                else:
                    code, reval = '23021', 'Error when executing "' + cmd + '".\n' + output
            if status:
                result = Utils.errorCode(code, reval, [])
                raise web.HTTPError(status = "400 Bad Request", data = result) 
            weblog = xml.etree.ElementTree.fromstring(output)
            
            for entry in weblog.findall("logMessage"):
                volumeLogMessage = VolumeLogMessage()
                volumeLogMessage.setBrick(brick)
                volumeLogMessage.setMessage(entry.find('message').text)
                volumeLogMessage.setSeverity(entry.find('severity').text)
                volumeLogMessage.setTimestamp(entry.find('timestamp').text)
                volLogList.append(volumeLogMessage)
    if (severity is not None) and (severity.strip() != '') and (severity.lower() != 'all'):
        volLogList = filterServerity(volLogList, severity)
    if (fromTimeStamp is not None) and (toTimeStamp is not None) and (fromTimeStamp is not '') and (toTimeStamp is not ''):
        volLogList = filterTimeStamp(volLogList, fromTimeStamp, toTimeStamp)
    responseDom = XmlHandler.ResponseXml()
    logMessagesTag = responseDom.appendTagRoute("logMessages")
    
    for volumeLogMessage in volLogList:
        logMessageTag = responseDom.createTag("logMessage",None)
        logMessagesTag.appendChild(logMessageTag)
        logMessageTag.appendChild(responseDom.createTag("brick",volumeLogMessage.getBrick()))
        logMessageTag.appendChild(responseDom.createTag("message",volumeLogMessage.getMessage()))
        logMessageTag.appendChild(responseDom.createTag("severity",volumeLogMessage.getSeverity()))
        logMessageTag.appendChild(responseDom.createTag("timestamp",volumeLogMessage.getTimeStamp()))
    return logMessagesTag.toxml()