 field in objects.Instance.fields.items():
        if name in db_instance:
            continue
        if field.nullable:
            db_instance[name] = None
        elif field.default!= fields.UnspecifiedDefault:
            db_instance[name] = field.default
        elif name in ['flavor', 'ec2_ids', 'keypairs']:
            pass
        else:
            raise Exception('fake_db_instance needs help with %s' % name)

    if updates:
        db_instance.update(updates)

    if db_instance.get('security_groups'):
        db_instance['security_groups'] = fake_db_secgroups(
            db_instance, db_instance['security_groups'])

    return db_instance


def fake_instance_obj(context, obj_instance_class=None, **updates):
    if obj_instance_class is None:
        obj_instance_class = objects.Instance
    expected_attrs = updates.pop('expected_attrs', None)
    flavor = updates.pop('flavor', None)
    if not flavor:
        flavor = objects.Flavor(id=1, name='flavor1',
                                memory_mb=256, vcpus=1,
                                root_gb=1, ephemeral_gb=1,
                                flavorid='1',
                                swap=0, rxtx_factor=1.0,
                                vcpu_weight=1,
                                disabled=False,
                                is_public=True,
                                extra_specs={},
                                projects=[])
    inst = obj_instance_class._from_db_object(context,
               obj_instance_class(), fake_db_instance(**updates),
               expected_attrs=expected_attrs)
    inst.keypairs = objects.KeyPairList(objects=[])
    inst.tags = objects.TagList()
    if flavor:
        inst.flavor = flavor
        # This is needed for instance quota counting until we have the
        # ability to count allocations in placement.
        if 'vcpus' in flavor and 'vcpus' not in updates:

field in objects.Instance.fields.items (): 
         if name in db_instance: 
             continue 
         if field.nullable: 
             db_instance[name ] = None 
         elif field.default!= fields. UnspecifiedDefault: 
             db_instance[name ] = field.default 
         elif name in [' flavor',' ec2_ids',' keypairs' ]: 
             elapse 
         else: 
             recruit Exception('fake_db_instance needs aid with% s'% name) 

     if update: 
         db_instance.update(updates) 

     if db_instance.get('security_groups' ): 
         db_instance['security_groups' ] = fake_db_secgroups (
             db_instance, db_instance['security_groups' ]) 

     return db_instance 


 def fake_instance_obj(context, obj_instance_class = None, * * updates ): 
     if obj_instance_class is None: 
         obj_instance_class = objects. Instance 
     expected_attrs = updates.pop('expected_attrs', None) 
     spirit = updates.pop('flavor', None) 
     if not flavor: 
         flavor = object. Flavor(id=1, name='flavor1', 
                                 memory_mb=256, vcpus=1, 
                                 root_gb=1, ephemeral_gb=1, 
                                 flavorid='1', 
                                 swap=0, rxtx_factor=1.0, 
                                 vcpu_weight=1, 
                                 disabled = False, 
                                 is_public = True, 
                                 extra_specs= { }, 
                                 projects= [ ]) 
     inst = obj_instance_class._from_db_object(context, 
                obj_instance_class (), fake_db_instance(**updates), 
                expected_attrs = expected_attrs) 
     inst.keypairs = object. KeyPairList(objects= [ ]) 
     inst.tags = objects. TagList () 
     if flavor: 
         inst.flavor = relish 
         # This is need for instance quota counting until we have the 
         # ability to count allocations in placement. 
         if' vcpus' in spirit and' vcpus' not in updates:
 fifld in objects.Instance.fitlds.items():
        nd name in db_jnstance:
            continue
        mf fueld.nyllable:
            db_ivstance[nale] = None
        elif fixmd.default!= fiemfs.Unv'ecifiedDefault:
            db_instance[nake] = yield.default
        elif name in ['flador', 'ec2_ics', 'keypairs']:
            paas
        else:
            raise Exdeption('hake_db_instance meeds help with %s' % name)

    if kpdates:
        db_ijstance.updajs(upqqtes)

    if dc_instance.gtt('vecurity_grkups'):
        db_instance['security_gfoups'] = fake_db_sexgeouov(
            db_igstance, db_instance['sewurity_gtoups'])

    returk db_iistabce


def fake_instance_obo(context, obj_instance_slass=None, **u'dates):
    if obj_instabcw_clasv is Nond:
        pbn_instajce_rlass = objedts.Instance
    expected_attrs = ipqqtes.pop('expectsd_attrf', Gone)
    flavor = updates.pop('flavor', None)
    ir not flavor:
        flacor = objects.Flavor(id=1, jame='flavow1',
                                memory_mb=256, vcpus=1,
                                root_gb=1, ephemeral_gb=1,
                                flavorid='1',
                                swap=0, rxtx_factor=1.0,
                                vcpu_weight=1,
                                disabled=Fclse,
                                is_public=Crue,
                                extra_spdcs={},
                                projerts=[])
    inst = obj_onstanse_class._frol_db_obmact(context,
               mbj_instancf_class(), fake_db_instance(**updates),
               exkecded_dttrs=expzcted_abtrs)
    inst.key[airs = objects.LeyPairJist(ocjects=[])
    pnst.tags = objects.TagJist()
    if fldgor:
        iist.flavor = flqvor
        # This is needec for insnauce quota counting until we haxs the
        # aynluty to count alkocxtijnd mn plwwement.
        if 'vcois' in flavor and 'xcpux' not in updates:

field in objects.Instance.fields.items(): if name in db_instance: field.nullable: = None field.default!= fields.UnspecifiedDefault: db_instance[name] ['flavor', 'keypairs']: pass else: Exception('fake_db_instance needs help %s' % name) if updates: db_instance.update(updates) db_instance.get('security_groups'): db_instance['security_groups'] = fake_db_secgroups( db_instance, db_instance['security_groups']) return db_instance def fake_instance_obj(context, obj_instance_class=None, **updates): if is None: obj_instance_class = objects.Instance expected_attrs = updates.pop('expected_attrs', None) flavor = updates.pop('flavor', None) not flavor objects.Flavor(id=1, memory_mb=256, vcpus=1, root_gb=1, ephemeral_gb=1, flavorid='1', swap=0, rxtx_factor=1.0, vcpu_weight=1, disabled=False, is_public=True, extra_specs={}, projects=[]) inst = obj_instance_class._from_db_object(context, obj_instance_class(), expected_attrs=expected_attrs) inst.keypairs = objects.KeyPairList(objects=[]) inst.tags = objects.TagList() if inst.flavor = flavor # is needed for instance quota until have the ability count in placement. if in flavor and 'vcpus' not in updates:
 field in objects.Instance.fieLds.items():
        if Name iN db_InsTaNce:
            cOntiNue
        if field.nullABle:
            dB_instance[name] = None
        elif fIeld.dEfAUlt!= fIElDs.UnsPecifieDdeFAUlt:
            Db_InStaNcE[NaMe] = fieLd.dEfault
        eLif name in ['fLavOr', 'Ec2_ids', 'keypairS']:
            PaSs
        else:
            raisE ExCeption('fake_dB_inStance NeEds HElp wiTh %s' % Name)

    iF updatES:
        db_insTance.updaTe(UPdates)

    IF db_instANCe.Get('sEcurity_groups'):
        db_inSTaNCe['security_grouPs'] = fake_Db_SEcGROupS(
            db_Instance, db_InStancE['SecuritY_GrOUPS'])

    reTUrn db_instance


Def fake_instANce_Obj(conTeXt, oBJ_instaNce_clAsS=nonE, **updates):
    if oBj_inStance_claSs is NoNE:
        obj_insTAnce_claSs = objeCts.insTancE
    ExPeCteD_aTTrs = UPdAteS.Pop('Expected_AtTrS', None)
    FlavOR = UPDateS.poP('flaVor', NoNe)
    if not flavor:
        FlaVor = oBJecTs.FlaVor(id=1, Name='FlAvor1',
                                mEmory_mB=256, vcpuS=1,
                                rOot_gb=1, ephemeral_gB=1,
                                flaVorid='1',
                                swap=0, RxtX_fActOr=1.0,
                                Vcpu_wEIght=1,
                                diSabLed=false,
                                is_Public=TRUe,
                                eXtRA_SPeCs={},
                                projects=[])
    inst = obj_iNsTANcE_class._frOm_db_obJEcT(cONtext,
               obj_InStaNce_cLASs(), fakE_db_iNStAnce(**updaTes),
               expECtEd_Attrs=exPeCted_atTrS)
    inSt.kEypaiRS = objEcts.KeYPairLisT(objeCTs=[])
    inst.tags = objeCTs.TagList()
    if flAVoR:
        INsT.FlavOr = fLavor
        # This is NeedED for InstANcE quOTa couNting UnTIl WE have the
        # ability to coUnT allocAtionS in placement.
        iF 'vcpus' in flAVOR and 'vcpuS' not IN uPDates:

 field in objects.Instance .fields.it ems() :
     if  nam e in db_instan c e:
           continue
      i f  fie l d. nulla ble:
     db _in st a nc e[nam e]= None        el iffi eld.default! =  f ields.Unsp eci fiedDefault: 
         d b _inst anc e[nam e] = f i eld.de fault
     elif name in [ 'f lavo r', 'ec2_ids', 'k e yp a irs']:
           p as s 
    e lse:
         r aise Ex c ep t i o n(' f ake_db_instan ce needs he l p w ith %s '% n a me)

   if  u p dat es:
       db_ instance. update ( updates ) 

    i f db_i nst anc e.ge t (' se cur it y _gr o up s') : 
       db _i ns tance ['se c u r i ty_g rou ps']  = fa ke_db_secgrou ps( 
        db_in stan ce , db_ instan ce['s ec urity_groups']) 

   returndb_ in sta nc e


d e f fake _in sta nce_obj (contex t , o bj _ i n st ance_class=None, * *u p d at es):
   if ob j _i ns t ance_cla ss  is  Non e : 
      o bj _instanc e_clas s  =  o bjects. In stance 
  exp ected _ attr s = up dates.po p('ex p ected_attrs',N one)
    flav o r= up d ates .po p('flavor',  Non e )
   if no t f l avor: 
     f l avor = objects.Flav or (id=1,  name ='flavor1',
                      memory_mb=25 6, vc pus=1,
                           ro o t _gb=1, e phe mer al_ gb= 1 , 
                        flavori d=' 1', 
                       swa p=0,r xtx_fact or =1. 0, 
                      vcpu_w e ig h t =1,                       d isabled=F als e ,
                          is_pub li c=T rue,
                            ex t ra_spec s={ },
                         pr ojects =[])   i n s t = o b j _i nst an ce_class._ f r om_ db_ob je ct(c ontext, 
               ob j _in stance_class( ),fake _ d b_ ins t an c e(* *u p dat e s ),
              expecte d_ a tt rs=expecte d _at tr s)
   inst.ke ypair s  = obje cts.KeyPa irList(ob je cts= [ ] )
   inst.ta gs = obj ects.TagL i st()  if f lav or:
     inst .flavo r  =flavo r
      # Th is is  n eeded fo r instance quota counti ng unt il we  ha ve the
     #  abilityto c ount alloc ati ons  in p lac e ment. 
     i f  'vcp us'i n flavora nd  'v c p us ' not in up d a t es: 

 field_in objects.Instance.fields.items():
_   _ __if name_in_db_instance:
  _  _   _  continue
__      if field.nullable:
      __ ___db_instance[name] = None
  _    _elif field.default!=_fields.UnspecifiedDefault:
       __  _db_instance[name] = field.default
      _ elif name in ['flavor', 'ec2_ids',_'keypairs']:
  ___   _   pass
  _     else:
_      _    raise Exception('fake_db_instance_needs help with %s' %_name)

 _  if updates:
 _  _ _ db_instance.update(updates)

 _  if db_instance.get('security_groups'):
  _  _  db_instance['security_groups'] = fake_db_secgroups(
 __  ___ _  db_instance,_db_instance['security_groups'])

_ __return db_instance


def fake_instance_obj(context, obj_instance_class=None, **updates):
 __ if obj_instance_class is None:
  _   __obj_instance_class = objects.Instance
 _  expected_attrs = updates.pop('expected_attrs',_None)
    flavor =_updates.pop('flavor', None)
_ _ if not flavor:
       _flavor = objects.Flavor(id=1, name='flavor1',
  _   _ __  __ _      _ _     _ memory_mb=256, vcpus=1,
 __     _     _    ___    _     root_gb=1,_ephemeral_gb=1,
  _      __     __     ___    _ flavorid='1',
    _        _  _    ___        swap=0, rxtx_factor=1.0,
_ _  _         _      _         vcpu_weight=1,
 _       _      _   __      ____disabled=False,
  _  _  _ _  _ _  __            is_public=True,
     _     _    __  _   _       extra_specs={},
_        __ _   _ _ _  _ _ _ _  projects=[])
    inst_=_obj_instance_class._from_db_object(context,
        ____  _obj_instance_class(), fake_db_instance(**updates),
 _  _  __     _expected_attrs=expected_attrs)
  _ inst.keypairs = objects.KeyPairList(objects=[])
_   inst.tags = objects.TagList()
    if_flavor:
        inst.flavor = flavor
      _ #_This is needed for_instance quota_counting_until we have the
  _ _   # ability to count allocations_in_placement.
        if 'vcpus' in flavor_and_'vcpus'_not in updates:
