コード例 #1
0
ファイル: clustermgr.py プロジェクト: allfs/autooam
 def alloc_new(self,name, configspec, vmitype, chefmode=True):
     '''Allocates a new cluster.
     
     @param name - name for the cluster (ideally unique)
     @param configspec - a ConfigSpec instance
     @param vmitype - string specifying vmi type (supported: 'vagrant')
     '''
     cid = self._db.insert({})        
     try:
         configspec.validate()
         cluster = Cluster( name, configspec, cid, chefmode=chefmode )
         VMI.Create(vmitype, cluster)
         self._db.update( 
                         { '_id' : cluster.id() }, 
                         { u'name' : name,
                           u'config' : configspec.jsonmap, 
                           u'vmi' : cluster.get_vmi().jsonmap(), 
                           u'machines' : cluster.machines()} )
     except Exception as exc:
         import traceback
         Log.error('Cluster creation failed: %s' % exc)
         Log.error( traceback.format_exc() )
         self._db.remove( { '_id' : cid } )
         raise Exception('Failed to create cluster: %s' % name)
     
     return cluster