Пример #1
0
    def __init__(self, name, configspec, cid, machines = None, chefmode = True, attach = False):
        '''Constructor.
        
        @param name - name for the cluster (ideally unique)
        @param configspec - reference to a ConfigSpec object
        @param cid - unique id allocated to the cluster
        @param machines - [optional] map with instantiated machine info
        '''
        super(Cluster, self).__init__(name, configspec, machines=machines, chefmode=chefmode)

        # check to see if an EM is in use and set self._emapi accordingly
        if self.config()['em'] and self.config()['em']['present']:
            self._emapi = EnterpriseManagerAPI(self.config()['em']['emhost'], self.config()['em']['emport'], name)

            # populate the special "cluster" case where we match the em boxtype with the rest of the cluster
            if self.config()['em'].has_key('boxtype') and self.config()['em']['boxtype'] == "cluster":
                self.config()['em']['boxtype'] = self.config()['boxtype']

            # if we are installing the EM we want to go ahead and retrieve the version information
            # so that it is part of the run reporting
            if common.props['vmi.vagrantvmi.unit-test']:
                self.config()['em']['version'] = 'em-unit-test'
            elif self.config()['em']['invm'] and not attach:
                # if version is Latest and we are creating instead of attaching, then
                # go ahead and retrieve the EM package we will need.  This is important
                # so that the EM version is set after the constructor returns
                Log.info('Retrieving EM version %s...' % self.config()['em']['version'])
                vmgr = emvmgr.EMVersionManager()
                pkgtype = vagboxes.get_default_pkgtype(self.config()['em']['boxtype'])
                (emversion, pkgfile) = vmgr.retrieve(self.config()['em']['version'], pkgtype)
                self.config()['em']['version'] = emversion
            elif not attach:
                # this means we are point to an existing EM, insert the hostname as the version
                self.config()['em']['version'] = self.config()['em']['emhost']
        else:
            self._emapi = None
        self._id = cid

        # moved this validation from configspec to here,
        # because it only applies to autooam usage.
        if self._config['hadoop']:
            if not self._config['hadoop'].has_key('instance-templates'):
                Log.error('Must specify instance-templates when using hadoop')
                raise Exception("Must specify instance-templates when using hadoop")
Пример #2
0
    def run_cmd(self):
        '''
        Prepare and run the ansible playbook command for
        the operation type specified in the constructor
        '''
        self._rundir  = self._cluster.get_vmi()._rundir
        emboxtype = self._cluster.config()['em']['boxtype']
        if not vagboxes.em_support(emboxtype):
            # Don't even try to install if the boxtype does not support an EM
            print 'supported is %s' % vagboxes.list_all(flags=vagboxes.FLAG_EM)
            Log.error("boxtype %s does not support the EM!" % emboxtype)
            return 1
        
        self._pkgtype = vagboxes.get_default_pkgtype(emboxtype)
        vmgr = emvmgr.EMVersionManager()
        (emversion, self._pkgfile) = vmgr.retrieve(self._cluster.config()['em']['version'], self._pkgtype)
        self._pkgname = os.path.split( self._pkgfile )[1]
        
        (ansible_yml,cmdargs) = self._prepare_playbook_install()

        extra_playdir = self._cluster.get_extra_playbook_dir()
        p = PlaybookMgr( os.path.basename(self._rundir), extra_playdir )

        # create ansible inventory file with list of hosts
        emrole = self._cluster.config()['em']['role']
        iplist = [ self._cluster.machine(emrole)['ip'] ]
        ipdict = { 'all' : iplist }
        p.write_inventory( 'emdefault', ipdict )

        # create ansible.cfg file
        self._idbuser = self._cluster.config()['idbuser']
        f = open( common.props['vmi.vagrantvmi.sshkey'] )
        keytext = ''.join(f.readlines())
        p.config_ssh( self._idbuser, keytext )

        # execute playbook thru PlaybookMgr
        Log.info("Running %s EM pkg install playbook; --extra-vars=%s" % (ansible_yml,cmdargs))
        rc, results, out, err = p.run_playbook(ansible_yml, 'emdefault', playbook_args=cmdargs)
        return rc
Пример #3
0
    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 )
Пример #4
0
 def testBoxes(self):
     self.assertEqual( vagboxes.get_default_pkgtype('cal-precise64'), 'deb')
     self.assertEqual( vagboxes.get_os_family('cal-precise64'), 'ubuntu')
     self.assertEqual( vagboxes.get_os_version('cal-precise64'), '12.04')
     self.assertEqual( vagboxes.get_description('cal-precise64'), 'Ubuntu 12.04.1 LTS (Precise Pangolin)')