#NEWLINE# def _format_security_group( security_group , os_security_group , security_groups , os_security_groups ) : #NEWLINE# #INDENT# ec2_security_group = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ec2_security_group [ 'groupId' ] = security_group [ 'id' ] #NEWLINE# if security_group . get ( 'vpc_id' ) : #NEWLINE# #INDENT# ec2_security_group [ 'vpcId' ] = security_group [ 'vpc_id' ] #NEWLINE# #UNINDENT# ec2_security_group [ 'ownerId' ] = os_security_group [ 'tenant_id' ] #NEWLINE# ec2_security_group [ 'groupName' ] = os_security_group [ 'name' ] #NEWLINE# ec2_security_group [ 'groupDescription' ] = os_security_group [ 'description' ] #NEWLINE# ingress_permissions = [ ] #NEWLINE# egress_permissions = [ ] #NEWLINE# for os_rule in os_security_group . get ( 'security_group_rules' , [ ] ) : #NEWLINE# #INDENT# if ( os_rule . get ( 'ethertype' , 'IPv4' ) == 'IPv6' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ec2_rule = { #NEWLINE# #INDENT# 'ipProtocol' : ( ( - 1 ) if ( os_rule [ 'protocol' ] is None ) else os_rule [ 'protocol' ] ) , #NEWLINE# 'fromPort' : ( ( - 1 ) if ( os_rule [ 'port_range_min' ] is None ) else os_rule [ 'port_range_min' ] ) , #NEWLINE# 'toPort' : ( ( - 1 ) if ( os_rule [ 'port_range_max' ] is None ) else os_rule [ 'port_range_max' ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# remote_group_id = os_rule [ 'remote_group_id' ] #NEWLINE# if ( remote_group_id is not None ) : #NEWLINE# #INDENT# ec2_remote_group = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# db_remote_group = next ( ( g for g in security_groups if ( g [ 'os_id' ] == remote_group_id ) ) , None ) #NEWLINE# if ( db_remote_group is not None ) : #NEWLINE# #INDENT# ec2_remote_group [ 'groupId' ] = db_remote_group [ 'id' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# os_remote_group = next ( ( g for g in os_security_groups if ( g [ 'id' ] == remote_group_id ) ) , None ) #NEWLINE# if ( os_remote_group is not None ) : #NEWLINE# #INDENT# ec2_remote_group [ 'groupName' ] = os_remote_group [ 'name' ] #NEWLINE# ec2_remote_group [ 'userId' ] = os_remote_group [ 'tenant_id' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# ec2_rule [ 'groups' ] = [ ec2_remote_group ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( os_rule [ 'remote_ip_prefix' ] is not None ) : #NEWLINE# #INDENT# ec2_rule [ 'ipRanges' ] = [ { #NEWLINE# #INDENT# 'cidrIp' : os_rule [ 'remote_ip_prefix' ] , #NEWLINE# #UNINDENT# } ] #NEWLINE# #UNINDENT# #UNINDENT# if ( os_rule . get ( 'direction' ) == 'egress' ) : #NEWLINE# #INDENT# egress_permissions . append ( ec2_rule ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( security_group is None ) and ( os_rule [ 'protocol' ] is None ) ) : #NEWLINE# #INDENT# for ( protocol , min_port , max_port ) in ( ( 'icmp' , ( - 1 ) , ( - 1 ) ) , ( 'tcp' , 1 , 65535 ) , ( 'udp' , 1 , 65535 ) ) : #NEWLINE# #INDENT# ec2_rule [ 'ipProtocol' ] = protocol #NEWLINE# ec2_rule [ 'fromPort' ] = min_port #NEWLINE# ec2_rule [ 'toPort' ] = max_port #NEWLINE# ingress_permissions . append ( copy . deepcopy ( ec2_rule ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ingress_permissions . append ( ec2_rule ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ec2_security_group [ 'ipPermissions' ] = ingress_permissions #NEWLINE# ec2_security_group [ 'ipPermissionsEgress' ] = egress_permissions #NEWLINE# return ec2_security_group