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)
def _alloc_construct(self, cluster): '''create a new vmi instance.''' if not cluster.config().has_key('boxtype'): raise Exception("Vagrant cluster creation requires a boxtype in the ConfigSpec") # this hadoop validation check was formerly in configspec, but # moved to here to remove autooam/vagboxes dependency from # emtools/configspec if cluster.config().has_key('hadoop') and cluster.config()['hadoop']: if not vagboxes.hadoop_support(cluster.config()['boxtype']): raise Exception("Hadoop not supported on boxtype %s" % self.jsonmap['boxtype']) self._subnet = self._salloc.alloc(cluster) # first we want to look for our root directory, make sure it # does not already exist and then create it root = common.props['vmi.vagrantvmi.vagrantdir'] utils.mkdir_p(root) self._rundir = '%s/%s_%s' % (root, cluster.name(), str(cluster.id())) os.makedirs(self._rundir) # this is where we will write stdout and stderr for any calls # executed agaist this VMI self._outfile = "%s/%s.out" % (self._rundir, cluster.name()) self._defmemsize = common.props['vmi.vagrantvmi.defmemsize'] self._defcpus = common.props['vmi.vagrantvmi.defcpus'] # do a sanity check to make sure we don't ask for a non-existent package # we only support enterprise=False for versions 4.0 and later entpkg = cluster.config()['enterprise'] if ConfigSpec._version_greaterthan('4.0.0-0',cluster.config()['idbversion']): Log.info('resetting enterprise to True for version %s ' % cluster.config()['idbversion']) entpkg = True # make sure that our package exists vm = VersionManager() if cluster.config()['idbuser'] != 'root' or cluster.config()['binary']: ptype = 'binary' # set this to true in case not already set so that vagrant file writer # can depend on it being accurate cluster.config()['binary'] = True else: ptype = vagboxes.get_default_pkgtype(cluster.config()['boxtype']) self._pkgfile = vm.retrieve(cluster.config()['idbversion'], ptype, enterprise=entpkg) # handle the upgrade version if the user specified it upgfile = None upgvers = None if cluster.config()['upgrade']: upgfile = vm.retrieve(cluster.config()['upgrade'], ptype, enterprise=entpkg) upgvers = vm.get_pkg_version(upgfile) self._upgfile = upgfile # handle datdup package if the user requested it - note that the datdup # package is only relevant prior to version 4.0 datduppkgfile = None if cluster.config()['datdup'] and not ConfigSpec._version_greaterthan(cluster.config()['idbversion'],'4.0.0-0'): datduppkgfile = vm.retrieve(cluster.config()['idbversion'], ptype, datdup=True) self._alloc_machines() h = PostConfigureHelper() self._pfile = '%s/postconfigure.in' % self._rundir h.write_input(self._pfile, cluster, ptype) # @bug 5990: don't need to copy public key. vagrant # public access should already be setup when cluster # was instantiated. # copy public key to shared directory so that vagrant can access #utils.mkdir_p("%s/.ssh" % self._rundir) #shutil.copy( '%s.pub' % common.props['emtools.test.sshkeyfile'], # '%s/.ssh/public_key' % self._rundir) self._vfile = self._rundir + '/Vagrantfile' vfile = VagrantFileWriter( cluster, self._pkgfile, vm.get_pkg_version(self._pkgfile), datduppkgfile, self._upgfile, upgvers, self._subnet, self._rundir) vfile.writeVagrantFile( self._vfile ) cluster.vmi(self) # For external DBRoot storage: delete/recreate dataN directories # locally, to be NFS mounted for use on each PM if cluster.config()['storage'] == 'external': rootCount = cluster.config().total_dbroot_count() for i in range( rootCount ): dbRootDir = '%s/data%d' % (self._rundir, i+1) if os.path.exists( dbRootDir ): shutil.rmtree( dbRootDir ) os.mkdir( dbRootDir )
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)