#NEWLINE# def create( self , req , body ) : #NEWLINE# #INDENT# context = sg . _authorize_context ( req ) #NEWLINE# authorize ( context ) #NEWLINE# nova_context . require_admin_context ( context ) #NEWLINE# sg_rule = self . _from_body ( body , 'security_group_default_rule' ) #NEWLINE# try : #NEWLINE# #INDENT# values = self . _rule_args_to_dict ( to_port = sg_rule . get ( 'to_port' ) , from_port = sg_rule . get ( 'from_port' ) , ip_protocol = sg_rule . get ( 'ip_protocol' ) , cidr = sg_rule . get ( 'cidr' ) ) #NEWLINE# #UNINDENT# except Exception as exp : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = six . text_type ( exp ) ) #NEWLINE# #UNINDENT# if ( values is None ) : #NEWLINE# #INDENT# msg = _ ( 'Not enough parameters to build a valid rule.' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# if self . security_group_api . default_rule_exists ( context , values ) : #NEWLINE# #INDENT# msg = _ ( 'This default rule already exists.' ) #NEWLINE# raise exc . HTTPConflict ( explanation = msg ) #NEWLINE# #UNINDENT# security_group_rule = self . security_group_api . add_default_rules ( context , [ values ] ) [ 0 ] #NEWLINE# fmt_rule = self . _format_security_group_default_rule ( security_group_rule ) #NEWLINE# return { #NEWLINE# #INDENT# 'security_group_default_rule' : fmt_rule , #NEWLINE# #UNINDENT# }