コード例 #1
0
ファイル: config.py プロジェクト: infinidb/emtools
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'launch.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    jsonstr = None
    if json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)
    elif use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    else:
        print 'need cluster name'
        usage()
        sys.exit(2)
        
    #print jsonstr       
    req = configreq.ConfigRequest(jsonstr)

    Log = logutils.getLogger('config')
    Log.info('request: %s' % req.json_dumps())

    fget = ConfigGetter( req )
    reply = fget.run( req )

    Log.info('reply: %s' % reply.json_dumps())
    print reply
       
    if reply.has_key('rc'):
        return reply['rc']
    else:
        return 0
コード例 #2
0
ファイル: vagrantvmi.py プロジェクト: allfs/autooam
import time
import emtools.common as common
import emtools.common.utils as utils
import shutil
from datetime import datetime
from emtools.cluster.postcfg import PostConfigureHelper
from vagsubnet import VagrantSubnetAlloc
from vagfile import VagrantFileWriter
import autooam.testlib.vagboxes as vagboxes
import vagstatus
from versionmgr import VersionManager
import json

from emtools.cluster.configspec import ConfigSpec
import emtools.common.logutils as logutils
Log = logutils.getLogger(__name__)

class VagrantVMI(object):
    '''
    VagrantVMI is a concrete VMI class for interacting with a vagrant
    installation to create and run virtual machine clusters
    '''

    def __init__(self, cluster, vmi=None):
        '''
        Constructor
        '''
        self._cluster = cluster
        self._salloc = VagrantSubnetAlloc()
        self._sshkey = common.props['vmi.vagrantvmi.sshkey']       
        if vmi:
コード例 #3
0
ファイル: writeinventory.py プロジェクト: infinidb/emtools
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'launch.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)
        
    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)
    
    # debug only
    # print '%s' % req
    try:
        req = inventoryreq.InventoryRequest( jsonstr )

        Log = logutils.getLogger('writeinventory')
        Log.info('request: %s' % req.json_dumps())

        pmgr = PlaybookMgr( req['cluster_name'] )
        
        # the write_inventory method expects a list for each role
        role_map = {}
        for r in req['role_info'].iterkeys():
            if type( req['role_info'][r] ) == list:
                role_map[r] = req['role_info'][r]
            elif type( req['role_info'][r] ) == unicode:
                role_map[r] = [ req['role_info'][r] ]
            else:
                raise Exception("writeinventory ERROR: unsupported type in role info %s : %s" % r, req['role_info'][r])
            
        pmgr.write_inventory('infinidb', role_map )
    except:
        import traceback
        print errormsg.ErrorMsg_from_parms( msg=json.dumps( traceback.format_exc() ) )
        sys.exit(1)

    reply_json = '{ "rc" : 0 }'
    Log.info('reply: %s' % reply_json)
    print reply_json
    return 0
コード例 #4
0
ファイル: runplaybook.py プロジェクト: Kangmo/emtools
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'runplaybook.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)
        
    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)
    
    
    # debug only
    # print '%s' % req
    try:
        req = playbookreq.PlaybookRequest( jsonstr )

        Log = logutils.getLogger('runplaybook')
        Log.info('request: %s' % req.json_dumps())

        pmgr = PlaybookMgr( req['cluster_name'] )
        rc, results, out, err = pmgr.run_playbook(req['playbook_info']['name'], 'infinidb', req['playbook_info']['hostspec'], playbook_args=req['playbook_info']['extravars'])
        preply_dict = {
            'cluster_name' : req['cluster_name'],
            'playbook_info' : req['playbook_info'],
            'rc' : rc,
            'stdout' : out,
            'stderr' : err,
            'recap_info' : results
        }
        preply = playbookreply.PlaybookReply_from_dict(preply_dict)
        Log.info('reply: %s' % preply.json_dumps())
        print preply
        return rc
        
    except:
        import traceback
        print errormsg.ErrorMsg_from_parms( msg=json.dumps( traceback.format_exc() ) )
        sys.exit(1)
コード例 #5
0
ファイル: emcluster.py プロジェクト: infinidb/emtools
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. 

'''
emtools.cluster.emcluster

Represent a group of machine instances that form a cluster
'''
import os
from playbookinstall import PlaybookInstall
import emtools.common.logutils as logutils
import emtools.common as common
import emtools.common.utils as utils
from emtools.cluster.basecluster import BaseCluster

Log = logutils.getLogger(__name__)

class EmCluster(BaseCluster):

    def __init__(self, name, configspec, rundir, pkgfile, machines = None, chefmode = True):
        '''Constructor.
        
        @param name - name for the cluster (ideally unique)
        @param configspec - reference to a ConfigSpec object
        @param rundir - runtime directory
        @param pkgfile - name of pkg file to be installed
        @param machines - [optional] map with instantiated machine info
        '''
        # Never employ chefmode for EmCluster
        super(EmCluster, self).__init__(name, configspec, machines=machines, chefmode=False)
        self._rundir  = rundir
コード例 #6
0
ファイル: installdatabase.py プロジェクト: Kangmo/emtools
def main(argv):
    """
    main function
    """

    try:
        opts, args = getopt.getopt(argv, "hvi", ["json="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    use_stdin = False
    json_file = ""

    # parse command line arguments
    for o, a in opts:
        if o == "-h":
            usage()
            sys.exit(2)
        elif o == "-v":
            print "installdatabase.py Version: %s" % version
            sys.exit(1)
        elif o == "-i":
            use_stdin = True
        elif o == "--json":
            json_file = a
        else:
            print "unsupported option: %s" % o
            usage()
            sys.exit(2)

    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print "ERROR: Must specify exactly one of -i or --json"
        usage()
        sys.exit(2)

    try:
        # load input into json string
        jsonstr = None
        if use_stdin:
            lines = sys.stdin.readlines()
            jsonstr = "".join(lines)
        elif json_file:
            f = open(json_file)
            lines = f.readlines()
            jsonstr = "".join(lines)

        Log = logutils.getLogger("installdatabase")
        req = installreq.InstallReq(jsonstr)
        Log.info("request: %s" % req.json_dumps())

        # construct configspec
        cfgspecbld = ConfigSpecBuilder(req)
        cfgspec, machines = cfgspecbld.run()

        # determine the approprate package file to be installed
        emVM = EmVersionManager()
        pkgfile = emVM.retrieve(cfgspec["idbversion"], "binary")
        Log.info("pkgfile: %s" % pkgfile)

        # create runtime directory
        root = common.props["emtools.playbookmgr.cluster_base"]
        rundir = "%s/%s" % (root, cfgspec["name"])
        if not os.path.exists(rundir):
            mkdir_p(rundir)

        # create the cluster
        emCluster = EmCluster(cfgspec["name"], cfgspec, rundir, pkgfile, machines)

        # create the postconfig response file
        h = PostConfigureHelper()
        pfile = "%s/postconfigure.in" % rundir
        h.write_input(pfile, emCluster, "binary")

        # perform the db install
        rc, results, out, err = emCluster.run_install_recipe()

        reply_dict = {
            "cluster_name": cfgspec["name"],
            "playbook_info": {
                "name": emCluster.get_playbook_filename(),
                "hostspec": emCluster.get_inventory_filename(),
                "extravars": emCluster.get_extra_vars(),
            },
            "rc": rc,
            "stdout": out,
            "stderr": err,
            "recap_info": results,
        }

        # test stub output
        # reply_dict = {
        #    'cluster_name' : cfgspec['name'],
        #    'playbook_info': {
        #        'name'     : 'test_name',
        #        'hostspec' : 'test_hostspec',
        #        'extravars': 'test_extravars'
        #    },
        #    'rc'           : 0,
        #    'stdout'       : 'test_stdout',
        #    'stderr'       : 'test_stderr',
        # }
        preply = playbookreply.PlaybookReply_from_dict(reply_dict)

        Log.info("reply: %s" % preply.json_dumps())
        print preply

        return 0

    except:
        import traceback

        print errormsg.ErrorMsg_from_parms(msg=json.dumps(traceback.format_exc()))
        sys.exit(1)
コード例 #7
0
ファイル: installdatabase.py プロジェクト: Kangmo/emtools
    def run(self):
        """Convert EM db installreq json string to a configspec"""

        # direct mapping of installreq properties to configspec properties
        # em db install properties      --> configspec properties
        # ------------------------          ---------------------
        #  cluster_name                     name
        #  cluster_info.infinidb_version    idbversion
        #  cluster_info.dbroots_per_pm      rolespec.pm.dbroots_per
        #  cluster_info.dbroot_list         rolespec.pm.dbroots_list
        #    (for future use)
        #  cluster_info.infinidb_user       idbuser
        #  cluster_info.storage_type
        #    "local"
        #    "gluster"                      datdup set to True
        #    "hdfs"                         empty hadoop entry
        #  cluster_info.pm_query            pm_query
        #  cluster_info.um_replication      Not Supported
        #  role_info                        rolespec.pm.count
        #
        # configspec properties that are constant or not applicable
        # ---------------------------------------------------------
        #  storage                          "internal"
        #  binary                           True
        #  upgrade                          False
        #  enterprise                       True
        #  hadoop.version                   not used (uses default)
        #  boxtype                          N/A
        #  em                               N/A
        #  rolespec.pm.memory               N/A
        #  rolespec.pm.cpus                 N/A

        cfgspec_dict = {}
        cfgspec_dict["name"] = self.__req["cluster_name"]
        cfgspec_dict["idbversion"] = self.__req["cluster_info"]["infinidb_version"]
        cfgspec_dict["idbuser"] = self.__req["cluster_info"]["infinidb_user"]
        if self.__req["cluster_info"]["storage_type"] == "gluster":
            cfgspec_dict["datdup"] = True
        else:
            cfgspec_dict["datdup"] = False
        cfgspec_dict["binary"] = True
        cfgspec_dict["storage"] = "internal"
        cfgspec_dict["upgrade"] = False
        cfgspec_dict["enterprise"] = True
        cfgspec_dict["pm_query"] = self.__req["cluster_info"]["pm_query"]
        if self.__req["cluster_info"]["storage_type"] == "hdfs":
            cfgspec_dict["hadoop"] = {}  # use hadoop defaults
            cfgspec_dict["storage"] = "hdfs"

        pmCount = 0
        umCount = 0
        cfgspec_dict["rolespec"] = {}
        machines = {}
        dbroots_per_pm = self.__req["cluster_info"]["dbroots_per_pm"]
        for key in self.__req["role_info"]:
            if key.startswith("pm"):
                pmCount += 1
                m = {}
                m["ip"] = self.__req["role_info"][key]
                m["hostname"] = self.__req["role_info"][key]
                dbroots = []
                pmnum = eval(key[2:])
                for j in range(1, dbroots_per_pm + 1):
                    dbroots.append(j + ((pmnum - 1) * dbroots_per_pm))
                m["dbroots"] = dbroots
                machines[key] = m
            if key.startswith("um"):
                umCount += 1
                m = {}
                m["ip"] = self.__req["role_info"][key]
                m["hostname"] = self.__req["role_info"][key]
                machines[key] = m
        if pmCount > 0:
            cfgspec_dict["rolespec"]["pm"] = {
                "count": pmCount,
                "dbroots_per": self.__req["cluster_info"]["dbroots_per_pm"],
            }
        else:
            # throw exception if no PM's present
            pass
        if umCount > 0:
            cfgspec_dict["rolespec"]["um"] = {"count": umCount}

        cfgspec_json = json.dumps(cfgspec_dict)
        machines_json = json.dumps(machines)
        Log = logutils.getLogger("installdatabase")
        Log.info("configspec: %s" % cfgspec_json)
        Log.info("machines: %s" % machines_json)
        cfg = ConfigSpec(cfgspec_json)

        cfg.validate()

        return cfg, machines
コード例 #8
0
def main(argv):
    '''
    main function
    '''

    try:
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    use_stdin = False
    json_file = ''

    for o, a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'launch.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)

    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)

    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open(json_file)
        lines = f.readlines()
        jsonstr = ''.join(lines)

    cmd = commandreq.CommandReq(jsonstr)

    Log = logutils.getLogger('idbconsole')
    Log.info('request: %s' % cmd.json_dumps())

    # debug only
    # print '%s' % cmd

    runner = ConsoleRunner(cmd)
    reply = runner.run()

    Log.info('reply: %s' % reply.json_dumps())
    print reply

    if reply.has_key('rc'):
        return reply['rc']
    else:
        return 0
コード例 #9
0
ファイル: getfacts.py プロジェクト: Kangmo/emtools
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvik:", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'launch.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        elif o == '-k':
            f = open(a)
            keystr = ''.join(f.readlines())
            print json.dumps(keystr)
            sys.exit(0)
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)
        
    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)

    Log = logutils.getLogger('getfacts')
    req = factreq.FactRequest( jsonstr )
    Log.info('request: %s' % req.json_dumps())
    
    # debug only
    # print '%s' % req
    
    fget = FactGetter( req )
    reply = fget.run()
    
    Log.info('reply: %s' % reply.json_dumps())
    print reply
    
    return 0
コード例 #10
0
def main(argv):
    '''
    main function
    '''

    try:
        opts, args = getopt.getopt(
            argv, "hiv", ["hosts=", "roles=", "idbversion=", "storagetype="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    installInfinidbFlag = False
    hostnames = []
    roles = None
    idbversion = None
    storage_type = None

    for o, a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        if o == '-i':
            installInfinidbFlag = True
        elif o == '-v':
            print 'emsim.py Version: %s' % version
            sys.exit(1)
        elif o == '--hosts':
            hostnames = a.split(',')
        elif o == '--roles':
            roles = eval(a)
        elif o == '--idbversion':
            idbversion = a
        elif o == '--storagetype':
            storage_type = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)

    Log = logutils.getLogger('emsim')

    if len(args) < 3:
        print 'ERROR: Not enough command-line arguments!'
        usage()
        sys.exit(2)
    elif len(hostnames) < 1:
        print 'ERROR: Must specify at least one hostname with --hosts!'
        usage()
        sys.exit(2)

    cluster_name = args[0]
    ssh_user = args[1]
    ssh_keyfile = args[2]

    f = open(ssh_keyfile)
    keystr = ''.join(f.readlines())
    f.close()

    requireInfinidb = True
    if installInfinidbFlag:
        requireInfinidb = False
    factreply = do_facts(cluster_name, hostnames, keystr, ssh_user,
                         requireInfinidb)

    # Install infinidb if user requested.
    if installInfinidbFlag:
        if do_installdb(cluster_name,
                        hostnames,
                        roles,
                        idbversion,
                        storage_type=storage_type) != 0:
            sys.exit(1)

        # run getfacts to verify the infinidb install
        factreply = do_facts(cluster_name, hostnames, keystr, ssh_user, True)

    # construct contents of inventory file from getfacts reply
    role_in = factreply['role_info']
    role_out = {"pm:children": []}
    for r in role_in:
        role_out[r] = [role_in[r]]
        role_out['pm:children'].append(r)
    if role_in.has_key('um1'):
        role_out['oam_server'] = role_in['um1']
    else:
        role_out['oam_server'] = role_in['pm1']

    if do_inv(cluster_name, role_out) != 0:
        sys.exit(1)

    # Install EM if user did not request alternate infinidb install
    if not installInfinidbFlag:
        if do_playbook(cluster_name, 'all.yml', 'all') != 0:
            sys.exit(1)

    if do_console(cluster_name, 'getsystemstatus') != 0:
        sys.exit(1)
    if do_console(cluster_name, 'getactivealarms') != 0:
        sys.exit(1)
    if do_console(cluster_name, 'gettablelocks') != 0:
        sys.exit(1)

    if do_config(cluster_name,
                 'set',
                 set_params=[{
                     "em_category": "UM",
                     "em_parameter": "TotalUmMemory",
                     "value": "1G"
                 }]) != 0:
        sys.exit(1)
    if do_config(
            cluster_name, 'get', check_parm="TotalUmMemory",
            check_val="1G") != 0:
        sys.exit(1)
    if do_config(cluster_name,
                 'set',
                 set_params=[{
                     "em_category": "UM",
                     "em_parameter": "TotalUmMemory",
                     "value": "4G"
                 }]) != 0:
        sys.exit(1)
    if do_config(
            cluster_name, 'get', check_parm="TotalUmMemory",
            check_val="4G") != 0:
        sys.exit(1)

    return 0
コード例 #11
0
ファイル: idbconsole.py プロジェクト: Kangmo/emtools
def main(argv):
    '''
    main function
    '''
    
    try:                                
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)   
    
    # defaults
    use_stdin = False
    json_file = ''
    
    for o,a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'launch.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)
        
    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)
        
    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open( json_file )
        lines = f.readlines()
        jsonstr = ''.join(lines)
    
    cmd = commandreq.CommandReq( jsonstr )

    Log = logutils.getLogger('idbconsole')
    Log.info('request: %s' % cmd.json_dumps())
    
    # debug only
    # print '%s' % cmd
    
    runner = ConsoleRunner( cmd )
    reply = runner.run()
    
    Log.info('reply: %s' % reply.json_dumps())
    print reply
    
    if reply.has_key('rc'):
        return reply['rc']
    else:
        return 0
コード例 #12
0
def main(argv):
    '''
    main function
    '''

    try:
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    use_stdin = False
    json_file = ''

    for o, a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'runplaybook.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)

    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)

    jsonstr = None
    if use_stdin:
        lines = sys.stdin.readlines()
        jsonstr = ''.join(lines)
    elif json_file:
        f = open(json_file)
        lines = f.readlines()
        jsonstr = ''.join(lines)

    # debug only
    # print '%s' % req
    try:
        req = playbookreq.PlaybookRequest(jsonstr)

        Log = logutils.getLogger('runplaybook')
        Log.info('request: %s' % req.json_dumps())

        pmgr = PlaybookMgr(req['cluster_name'])
        rc, results, out, err = pmgr.run_playbook(
            req['playbook_info']['name'],
            'infinidb',
            req['playbook_info']['hostspec'],
            playbook_args=req['playbook_info']['extravars'])
        preply_dict = {
            'cluster_name': req['cluster_name'],
            'playbook_info': req['playbook_info'],
            'rc': rc,
            'stdout': out,
            'stderr': err,
            'recap_info': results
        }
        preply = playbookreply.PlaybookReply_from_dict(preply_dict)
        Log.info('reply: %s' % preply.json_dumps())
        print preply
        return rc

    except:
        import traceback
        print errormsg.ErrorMsg_from_parms(
            msg=json.dumps(traceback.format_exc()))
        sys.exit(1)
コード例 #13
0
    def run(self):
        """Convert EM db installreq json string to a configspec"""

        # direct mapping of installreq properties to configspec properties
        # em db install properties      --> configspec properties
        # ------------------------          ---------------------
        #  cluster_name                     name
        #  cluster_info.infinidb_version    idbversion
        #  cluster_info.dbroots_per_pm      rolespec.pm.dbroots_per
        #  cluster_info.dbroot_list         rolespec.pm.dbroots_list
        #    (for future use)
        #  cluster_info.infinidb_user       idbuser
        #  cluster_info.storage_type
        #    "local"
        #    "gluster"                      datdup set to True
        #    "hdfs"                         empty hadoop entry
        #  cluster_info.pm_query            pm_query
        #  cluster_info.um_replication      Not Supported
        #  role_info                        rolespec.pm.count
        #
        # configspec properties that are constant or not applicable
        # ---------------------------------------------------------
        #  storage                          "internal"
        #  binary                           True
        #  upgrade                          False
        #  enterprise                       True
        #  hadoop.version                   not used (uses default)
        #  boxtype                          N/A
        #  em                               N/A
        #  rolespec.pm.memory               N/A
        #  rolespec.pm.cpus                 N/A

        cfgspec_dict = {}
        cfgspec_dict['name'] = self.__req['cluster_name']
        cfgspec_dict['idbversion'] = self.__req['cluster_info'][
            'infinidb_version']
        cfgspec_dict['idbuser'] = self.__req['cluster_info']['infinidb_user']
        if self.__req['cluster_info']['storage_type'] == 'gluster':
            cfgspec_dict['datdup'] = True
        else:
            cfgspec_dict['datdup'] = False
        cfgspec_dict['binary'] = True
        cfgspec_dict['storage'] = 'internal'
        cfgspec_dict['upgrade'] = False
        cfgspec_dict['enterprise'] = True
        cfgspec_dict['pm_query'] = self.__req['cluster_info']['pm_query']
        if self.__req['cluster_info']['storage_type'] == 'hdfs':
            cfgspec_dict['hadoop'] = {}  # use hadoop defaults
            cfgspec_dict['storage'] = 'hdfs'

        pmCount = 0
        umCount = 0
        cfgspec_dict['rolespec'] = {}
        machines = {}
        dbroots_per_pm = self.__req['cluster_info']['dbroots_per_pm']
        for key in self.__req['role_info']:
            if key.startswith('pm'):
                pmCount += 1
                m = {}
                m['ip'] = self.__req['role_info'][key]
                m['hostname'] = self.__req['role_info'][key]
                dbroots = []
                pmnum = eval(key[2:])
                for j in range(1, dbroots_per_pm + 1):
                    dbroots.append(j + ((pmnum - 1) * dbroots_per_pm))
                m['dbroots'] = dbroots
                machines[key] = m
            if key.startswith('um'):
                umCount += 1
                m = {}
                m['ip'] = self.__req['role_info'][key]
                m['hostname'] = self.__req['role_info'][key]
                machines[key] = m
        if pmCount > 0:
            cfgspec_dict['rolespec']['pm'] = {
                'count': pmCount,
                'dbroots_per': self.__req['cluster_info']['dbroots_per_pm']
            }
        else:
            # throw exception if no PM's present
            pass
        if umCount > 0:
            cfgspec_dict['rolespec']['um'] = {'count': umCount}

        cfgspec_json = json.dumps(cfgspec_dict)
        machines_json = json.dumps(machines)
        Log = logutils.getLogger('installdatabase')
        Log.info('configspec: %s' % cfgspec_json)
        Log.info('machines: %s' % machines_json)
        cfg = ConfigSpec(cfgspec_json)

        cfg.validate()

        return cfg, machines
コード例 #14
0
def main(argv):
    '''
    main function
    '''

    try:
        opts, args = getopt.getopt(argv, "hvi", ['json='])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    # defaults
    use_stdin = False
    json_file = ''

    # parse command line arguments
    for o, a in opts:
        if o == '-h':
            usage()
            sys.exit(2)
        elif o == '-v':
            print 'installdatabase.py Version: %s' % version
            sys.exit(1)
        elif o == '-i':
            use_stdin = True
        elif o == '--json':
            json_file = a
        else:
            print 'unsupported option: %s' % o
            usage()
            sys.exit(2)

    if (use_stdin and json_file) or (not use_stdin and not json_file):
        print 'ERROR: Must specify exactly one of -i or --json'
        usage()
        sys.exit(2)

    try:
        # load input into json string
        jsonstr = None
        if use_stdin:
            lines = sys.stdin.readlines()
            jsonstr = ''.join(lines)
        elif json_file:
            f = open(json_file)
            lines = f.readlines()
            jsonstr = ''.join(lines)

        Log = logutils.getLogger('installdatabase')
        req = installreq.InstallReq(jsonstr)
        Log.info('request: %s' % req.json_dumps())

        # construct configspec
        cfgspecbld = ConfigSpecBuilder(req)
        cfgspec, machines = cfgspecbld.run()

        # determine the approprate package file to be installed
        emVM = EmVersionManager()
        pkgfile = emVM.retrieve(cfgspec['idbversion'], 'binary')
        Log.info('pkgfile: %s' % pkgfile)

        # create runtime directory
        root = common.props['emtools.playbookmgr.cluster_base']
        rundir = '%s/%s' % (root, cfgspec['name'])
        if not os.path.exists(rundir):
            mkdir_p(rundir)

        # create the cluster
        emCluster = EmCluster(cfgspec['name'], cfgspec, rundir, pkgfile,
                              machines)

        # create the postconfig response file
        h = PostConfigureHelper()
        pfile = '%s/postconfigure.in' % rundir
        h.write_input(pfile, emCluster, 'binary')

        # perform the db install
        rc, results, out, err = emCluster.run_install_recipe()

        reply_dict = {
            'cluster_name': cfgspec['name'],
            'playbook_info': {
                'name': emCluster.get_playbook_filename(),
                'hostspec': emCluster.get_inventory_filename(),
                'extravars': emCluster.get_extra_vars()
            },
            'rc': rc,
            'stdout': out,
            'stderr': err,
            'recap_info': results
        }

        # test stub output
        #reply_dict = {
        #    'cluster_name' : cfgspec['name'],
        #    'playbook_info': {
        #        'name'     : 'test_name',
        #        'hostspec' : 'test_hostspec',
        #        'extravars': 'test_extravars'
        #    },
        #    'rc'           : 0,
        #    'stdout'       : 'test_stdout',
        #    'stderr'       : 'test_stderr',
        #}
        preply = playbookreply.PlaybookReply_from_dict(reply_dict)

        Log.info('reply: %s' % preply.json_dumps())
        print preply

        return 0

    except:
        import traceback
        print errormsg.ErrorMsg_from_parms(
            msg=json.dumps(traceback.format_exc()))
        sys.exit(1)