#NEWLINE# def normalize_nova_secgroup_rules( rules ) : #NEWLINE# #INDENT# 'Normalize the structure of nova security group rules\n\n    Note that nova uses -1 for non-specific port values, but neutron\n    represents these with None.\n\n    :param list rules: A list of security group rule dicts.\n\n    :returns: A list of normalized dicts.\n    ' #NEWLINE# ret = [ { #NEWLINE# #INDENT# 'id' : r [ 'id' ] , #NEWLINE# 'direction' : 'ingress' , #NEWLINE# 'ethertype' : 'IPv4' , #NEWLINE# 'port_range_min' : ( None if ( r [ 'from_port' ] == ( - 1 ) ) else r [ 'from_port' ] ) , #NEWLINE# 'port_range_max' : ( None if ( r [ 'to_port' ] == ( - 1 ) ) else r [ 'to_port' ] ) , #NEWLINE# 'protocol' : r [ 'ip_protocol' ] , #NEWLINE# 'remote_ip_prefix' : r [ 'ip_range' ] . get ( 'cidr' , None ) , #NEWLINE# 'security_group_id' : r [ 'parent_group_id' ] , #NEWLINE# #UNINDENT# } for r in rules ] #NEWLINE# return meta . obj_list_to_dict ( ret )