Exemplo n.º 1
0
def main():
    with racktables() as rt:
        rt.connect()
        sshOps = serverGroup()
        try:
            for server in rt.getActiveServers():
                # server: (id,name,type)
                try:
                    # Get 1 char to know the OS version
                    osVer = sshOps.sshCmd(server[1], "cat "
                                          "/etc/debian_version",
                                          sync=True)[0][0][0]
                except sshLoginException as sLE:
                    print(sLE)
                else:
                    if osVer != '':
                        rtVer = rt.getServerVersion(server[0])
                        if rtVer == '':
                            print("Adding OS version (%s) for %s" %
                                  (osVer, server[1]))
                            rt.insertVersion(server[0], server[2], osVer)
                        else:
                            if osVer != rtVer:
                                print("Changing OS version for %s "
                                      "from \'%s\' to \'%s\'" %
                                      (server[1], rtVer, osVer))
                                rt.updateVersion(server[0], osVer)
                    else:
                        print("Error getting OS version from %s" % server[1])
        except KeyboardInterrupt:
            sys.exit(2)
    return
def main():
    hlpDsc = "Generate links for fastssh script"
    optParser = argparse.ArgumentParser(description=hlpDsc)
    optParser.add_argument("-f",
                           "--fastssh-script",
                           help="fastssh script"
                           " path",
                           metavar="STRING",
                           required=True,
                           type=str,
                           dest="fastssh")
    optParser.add_argument("-d",
                           "--directory",
                           help="target directory"
                           "for the symlinks",
                           metavar="STRING",
                           type=str,
                           required=False,
                           dest="dir",
                           default=getcwd())
    args = optParser.parse_args()
    try:
        with racktables() as rt:
            rt.connect()
            for server in rt.getActiveServers():
                target = '%s%s%s' % (args.dir, sep, server[1])
                if not lexists(target):
                    symlink(args.fastssh, target)
    except KeyboardInterrupt:
        exit(2)
    return
Exemplo n.º 3
0
def main():
    cores = dict()
    solrTypes = ['search', 'keywords', 'premium', 'solr-extra']
    optParser = ArgumentParser()
    optParser.add_argument('-t',
                           '--type',
                           help='Index type: [%s]' % '|'.join(solrTypes),
                           metavar='TYPE',
                           required=False,
                           type=str,
                           choices=solrTypes,
                           default='search',
                           dest='solrType')
    optParser.add_argument('-c',
                           '--cores',
                           help='Show core information',
                           action='store_true',
                           required=False,
                           default=False,
                           dest='showCores')
    optParser.add_argument('-s',
                           '--servers',
                           help='Show servers information',
                           action='store_true',
                           required=False,
                           default=True,
                           dest='showServers')
    try:
        args = optParser.parse_args()
    except IOError as ioe:
        print("%s: %s" % (ioe.filename, ioe.strerror))
        sys.exit(1)
    with racktables() as rt:
        rt.connect()
        solrParser = solrXml.solrXmlParser()
        servers = []
        map(lambda x: servers.append(x[1]), rt.getServersByName(args.solrType))
        for server in servers:
            results = solrParser.getSizes(solrParser.getXml(server))
            for core in results.keys():
                if core == 'total':
                    cores[server] = results[core]
                else:
                    if core not in cores:
                        cores[core] = results[core]
                    else:
                        if cores[core] != results[core]:
                            # print "%s has different size !!!" % core
                            cores[core] = results[core]
        for key in cores.keys():
            printInfo = False
            if args.showServers and key in servers:
                printInfo = True
            if args.showCores and key not in servers:
                printInfo = True
            if printInfo:
                print "%s: %d (%s)" % (key, int(
                    cores[key]), humanReadable(int(cores[key])))
    return
Exemplo n.º 4
0
def main():
    with racktables() as rt:
        rt.connect()
        sshOps = serverGroup()
        ptrns = dict()
        ptrns['iface'] = re.compile('^[0-9]+: (?P<iface>[^:@]+)')
        ptrns['ip'] = re.compile('inet (?P<ip>[0-9\.\/]+) brd')
        try:
            for server in rt.getActiveServers():
                # server: (id,name,type)
                try:
                    ipOutput = sshOps.sshCmd(server[1], "ip a l ",
                                             sync=True)[0]
                except sshLoginException as sLE:
                    print(sLE)
                else:
                    print('* %s' % server[1])
                    realInfo = cleanIfaces(parseIproute(ipOutput, ptrns))
                    dbIps = cleanIfaces(rt.getServerIPs(server[0]))
                    for i in realInfo.keys():
                        if i not in dbIps and len(realInfo[i]) > 0:
                            print("\t%s:%s is not registered [%s]" %
                                  (server[1], i, ','.join(realInfo[i])))
                            dotIp = realInfo[i][0].split("/")[0]
                            ipDbInfo = rt.getIpInfo(dotIp)
                            if len(ipDbInfo) == 0:
                                print("\tAllocate %s (%s) in %s" %
                                      (dotIp, i, server[1]))
                                rt.allocateIp(dotIp, server[0], i)
                            else:
                                for record in ipDbInfo:
                                    print("\t!! IP address %s is registered "
                                          "at %s:%s" %
                                          (dotIp, record[1], record[2]))
                        else:
                            for cidr in realInfo[i]:
                                ip = cidr.split("/")[0]
                                net = int(cidr.split("/")[1])
                                if ip not in dbIps[i] \
                                   and net != 32 \
                                   and not rt.isAllocatedIp(ip):
                                    print("\tAllocate %s (%s) in %s" %
                                          (ip, i, server[1]))
                                    rt.allocateIp(ip, server[0], i)
        except KeyboardInterrupt:
            sys.exit(2)
    return
Exemplo n.º 5
0
def main():
    hlpDsc = "Send a command to multiple servers"
    optParser = argparse.ArgumentParser(description=hlpDsc)
    optParser.add_argument("-k",
                           "--key",
                           help="pattern in servername",
                           metavar="STRING",
                           required=False,
                           type=str,
                           dest="key",
                           default='')
    optParser.add_argument("-n",
                           "--no-newline",
                           help="don't add a new line"
                           "with the servername in the output",
                           required=False,
                           action='store_false',
                           dest="newline",
                           default=True)
    optParser.add_argument("command",
                           help="command line to execute",
                           metavar="shell command",
                           nargs='*')
    args = optParser.parse_args()
    if len(args.command) == 0:
        optParser.print_help()
        sys.exit(2)
    try:
        sshOps = serverGroup()
        with racktables() as rt:
            rt.connect()
            for server in rt.getServersByName(args.key):
                if args.newline:
                    print('\n\033[1;33m=====> %s <=====\033[0m' % server[1])
                else:
                    print('\033[1;33m%s\033[0m: ' % server[1], end='')
                try:
                    sshOps.sshCmd(server[1], ' '.join(args.command))
                except sshLoginException as sLE:
                    print(sLE)
    except KeyboardInterrupt:
        sys.exit(3)
    return
def main():
    with racktables() as rt:
        border()
        rt.connect()
        try:
            for server in rt.getPhysicalServers():
                # server: (id,name,type)
                if not rt.isRetired(server[0]):
                    values = []
                    values.append(rt.getServiceTag(server[0]))
                    values.append(server[1])
                    values.append(rt.getServerModel(server[0]))
                    values.append(fmtTime(rt.getServerSupportEnd(server[0])))
                    values.append(fmtTime(rt.getServerHwEnd(server[0])))
                    print(fmtLine('|', values))
        except fieldLenException:
            print("Wrong array length for values")
            sys.exit(2)
        except KeyboardInterrupt:
            sys.exit(3)
        border(False)
    return
Exemplo n.º 7
0
def main():
    with racktables() as rt:
        rt.connect()
        print int2ip(rt.getFreeIP('Backend', 205))
    return
Exemplo n.º 8
0
def main():
    with racktables() as rt:
        rt.connect()
        sshOps = serverGroup()
        ptrns = dict()
        ptrns['iface'] = re.compile('^[0-9]+: (?P<iface>[^:@]+)')
        ptrns['ip'] = re.compile('inet (?P<ip>[0-9\.\/]+)')
        ptrns['mac'] = re.compile('link\/ether (?P<mac>[0-9a-f:]+)')
        ignoredIfaces = ['lo', 'kvm']
        try:
            for server in rt.getActiveServers():
                # server: (id,name,type)
                try:
                    ipOutput = sshOps.sshCmd(server[1], "ip a l ",
                                             sync=True)[0]
                except sshLoginException as sLE:
                    print(sLE)
                else:
                    print('* %s' % server[1])
                    realInfo = parseIproute(ipOutput, ptrns)
                    dbInfo = dict()
                    dbIps = rt.getServerIPs(server[0])
                    dbIfaces = rt.getServerInterfaces(server[0])
                    for i in dbIps.keys():
                        dbInfo[i] = dict()
                        if i in dbIfaces:
                            dbInfo[i]["mac"] = dbIfaces[i]
                            # if i not in ignoredIfaces:
                            #    print("=> %s %s %s" % (i, dbIfaces[i],
                            #          ','.join(dbInfo[i])))
                        else:
                            dbInfo[i]["mac"] = '000000000000'
                            print("!!! %s interface is not registered" % i)
                            # print("=> %s %s" % (i, ','.join(dbInfo[i])))
                        dbInfo[i]["ip"] = dbIps[i]
                    for i in dbIfaces.keys():
                        if i not in dbInfo:
                            dbInfo[i] = dict()
                            dbInfo[i]["mac"] = dbIfaces[i]
                            dbInfo[i]["ip"] = list()
                    for i in realInfo.keys():
                        # if i not in ignoredIfaces:
                        #    print("|- %s %s %s" % (i, realInfo[i]["mac"],
                        #          ','.join(realInfo[i]["ip"])))
                        if i not in ignoredIfaces:
                            if i not in dbInfo:
                                print("insert into Port (object_id, name, "
                                      "iif_id, type, l2address) values (%s, "
                                      "'%s', 1, 24, '%s');" %
                                      (server[0], i, realInfo[i]["mac"]))
                            else:
                                if realInfo[i]["mac"] != dbInfo[i]["mac"]:
                                    print("!!! %s MAC mismatch: %s <=> %s" %
                                          (i, realInfo[i]["mac"],
                                           dbInfo[i]["mac"]))
                                for ip in realInfo[i]["ip"]:
                                    if ip.split("/")[0] not in dbInfo[i]["ip"] \
                                       and ip.split("/")[1] != 32:
                                        print("!!! Unregistered IP %s "
                                              "(%s:%s)" % (ip, server[1], i))
        except KeyboardInterrupt:
            sys.exit(2)
    return