@require_admin_context
def instance_type_create(context, values):
 session = get_session()
 with session.begin():
  try:
   instance_type_get_by_name(context, values['name'], session)
   raise exception.InstanceTypeExists(name=values['name'])
  except exception.InstanceTypeNotFoundByName:
   pass
  try:
   instance_type_get_by_flavor_id(context, values['flavorid'], session)
   raise exception.InstanceTypeIdExists(flavor_id=values['flavorid'])
  except exception.FlavorNotFound:
   pass
  try:
   specs = values.get('extra_specs')
   specs_refs = []
   if specs:
    for (k, v) in specs.iteritems():
     specs_ref = models.InstanceTypeExtraSpecs()
     specs_ref['key'] = k
     specs_ref['value'] = v
     specs_refs.append(specs_ref)
   values['extra_specs'] = specs_refs
   instance_type_ref = models.InstanceTypes()
   instance_type_ref.update(values)
   instance_type_ref.save(session=session)
  except Exception as e:
   raise db_exc.DBError(e)
  return _dict_with_extra_specs(instance_type_ref)

@ require_admin_context def instance_type_create ( context , values ) : session = get_session ( ) with session . begin ( ) : try : instance_type_get_by_name ( context , values [ 'name' ] , session ) raise exception . InstanceTypeExists ( name = values [ 'name' ] ) except exception . InstanceTypeNotFoundByName : pass try : instance_type_get_by_flavor_id ( context , values [ 'flavorid' ] , session ) raise exception . InstanceTypeIdExists ( flavor_id = values [ 'flavorid' ] ) except exception . FlavorNotFound : pass try : specs = values . get ( 'extra_specs' ) specs_refs = [ ] if specs : for ( k , v ) in specs . iteritems ( ) : specs_ref = models . InstanceTypeExtraSpecs ( ) specs_ref [ 'key' ] = k specs_ref [ 'value' ] = v specs_refs . append ( specs_ref ) values [ 'extra_specs' ] = specs_refs instance_type_ref = models . InstanceTypes ( ) instance_type_ref . update ( values ) instance_type_ref . save ( session = session ) except Exception as e : raise db_exc . DBError ( e ) return _dict_with_extra_specs ( instance_type_ref )
create a new instance type .