@Test public void testCreateConnection() { Vpc vpc1 = getTestVpc("vpc1"); Configuration vpc1Cfg = Utils.newAwsConfiguration(vpc1.getId(), "awstest"); Prefix vpc1Prefix = Prefix.parse("10.10.10.0/24"); Vpc vpc2 = getTestVpc("vpc2"); Configuration vpc2Cfg = Utils.newAwsConfiguration(vpc2.getId(), "awstest"); Prefix vpc2Prefix = Prefix.parse("10.10.20.0/24"); VpcPeeringConnection connection = new VpcPeeringConnection( "connection", vpc1.getId(), ImmutableList.of(vpc1Prefix), vpc2.getId(), ImmutableList.of(vpc2Prefix)); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(ImmutableList.of(vpc1Cfg, vpc2Cfg)); connection.createConnection(awsConfiguration, new Warnings()); String vrfName = Vpc.vrfNameForLink(connection.getId()); assertThat(vpc1Cfg, hasVrf(vrfName, Matchers.any(Vrf.class))); assertThat(vpc2Cfg, hasVrf(vrfName, Matchers.any(Vrf.class))); assertThat( vpc1Cfg.getVrfs().get(vrfName).getStaticRoutes(), equalTo( ImmutableSet.of( toStaticRoute( vpc2Prefix, Utils.interfaceNameToRemote(vpc2Cfg, connection.getId()), Utils.getInterfaceLinkLocalIp( vpc2Cfg, Utils.interfaceNameToRemote(vpc1Cfg, connection.getId())))))); assertThat( vpc2Cfg.getVrfs().get(vrfName).getStaticRoutes(), equalTo( ImmutableSet.of( toStaticRoute( vpc1Prefix, Utils.interfaceNameToRemote(vpc1Cfg, connection.getId()), Utils.getInterfaceLinkLocalIp( vpc1Cfg, Utils.interfaceNameToRemote(vpc2Cfg, connection.getId())))))); }
void createConnection(ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration accepterCfg = awsConfiguration.getNode(Vpc.nodeName(_accepterVpcId)); if (accepterCfg == null) { warnings.redFlag( String.format( "Accepter VPC %s not found for connection %s. Will not create the connection.", _accepterVpcId, _vpcPeeringConnectionId)); return; } Configuration requesterCfg = awsConfiguration.getNode(Vpc.nodeName(_requesterVpcId)); if (requesterCfg == null) { warnings.redFlag( String.format( "Requested VPC %s not found for connection %s. Will not create the connection.", _requesterVpcId, _vpcPeeringConnectionId)); return; } String vrfName = Vpc.vrfNameForLink(_vpcPeeringConnectionId); if (!accepterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(accepterCfg).setName(vrfName).build(); } if (!requesterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(requesterCfg).setName(vrfName).build(); } String ifaceNameSuffix = _vpcPeeringConnectionId; Utils.connect(awsConfiguration, accepterCfg, vrfName, requesterCfg, vrfName, ifaceNameSuffix); _requesterVpcCidrBlock.forEach( prefix -> addStaticRoute( accepterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( requesterCfg, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix))))); _accepterVpcCidrBlock.forEach( prefix -> addStaticRoute( requesterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( accepterCfg, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix))))); }
VpcPeeringConnection implements AwsVpcEntity, Serializable { void createConnection(ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration accepterCfg = awsConfiguration.getNode(Vpc.nodeName(_accepterVpcId)); if (accepterCfg == null) { warnings.redFlag( String.format( "Accepter VPC %s not found for connection %s. Will not create the connection.", _accepterVpcId, _vpcPeeringConnectionId)); return; } Configuration requesterCfg = awsConfiguration.getNode(Vpc.nodeName(_requesterVpcId)); if (requesterCfg == null) { warnings.redFlag( String.format( "Requested VPC %s not found for connection %s. Will not create the connection.", _requesterVpcId, _vpcPeeringConnectionId)); return; } String vrfName = Vpc.vrfNameForLink(_vpcPeeringConnectionId); if (!accepterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(accepterCfg).setName(vrfName).build(); } if (!requesterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(requesterCfg).setName(vrfName).build(); } String ifaceNameSuffix = _vpcPeeringConnectionId; Utils.connect(awsConfiguration, accepterCfg, vrfName, requesterCfg, vrfName, ifaceNameSuffix); _requesterVpcCidrBlock.forEach( prefix -> addStaticRoute( accepterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( requesterCfg, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix))))); _accepterVpcCidrBlock.forEach( prefix -> addStaticRoute( requesterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( accepterCfg, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix))))); } }
VpcPeeringConnection implements AwsVpcEntity, Serializable { void createConnection(ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration accepterCfg = awsConfiguration.getNode(Vpc.nodeName(_accepterVpcId)); if (accepterCfg == null) { warnings.redFlag( String.format( "Accepter VPC %s not found for connection %s. Will not create the connection.", _accepterVpcId, _vpcPeeringConnectionId)); return; } Configuration requesterCfg = awsConfiguration.getNode(Vpc.nodeName(_requesterVpcId)); if (requesterCfg == null) { warnings.redFlag( String.format( "Requested VPC %s not found for connection %s. Will not create the connection.", _requesterVpcId, _vpcPeeringConnectionId)); return; } String vrfName = Vpc.vrfNameForLink(_vpcPeeringConnectionId); if (!accepterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(accepterCfg).setName(vrfName).build(); } if (!requesterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(requesterCfg).setName(vrfName).build(); } String ifaceNameSuffix = _vpcPeeringConnectionId; Utils.connect(awsConfiguration, accepterCfg, vrfName, requesterCfg, vrfName, ifaceNameSuffix); _requesterVpcCidrBlock.forEach( prefix -> addStaticRoute( accepterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( requesterCfg, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix))))); _accepterVpcCidrBlock.forEach( prefix -> addStaticRoute( requesterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( accepterCfg, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix))))); } VpcPeeringConnection(
      String vpcPeeringConnectionId,
      String accepterVpcId,
      List<Prefix> accepterVpcCidrBlocks,
      String requesterVpcId,
      List<Prefix> requesterVpcCidrBlocks); }
VpcPeeringConnection implements AwsVpcEntity, Serializable { void createConnection(ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration accepterCfg = awsConfiguration.getNode(Vpc.nodeName(_accepterVpcId)); if (accepterCfg == null) { warnings.redFlag( String.format( "Accepter VPC %s not found for connection %s. Will not create the connection.", _accepterVpcId, _vpcPeeringConnectionId)); return; } Configuration requesterCfg = awsConfiguration.getNode(Vpc.nodeName(_requesterVpcId)); if (requesterCfg == null) { warnings.redFlag( String.format( "Requested VPC %s not found for connection %s. Will not create the connection.", _requesterVpcId, _vpcPeeringConnectionId)); return; } String vrfName = Vpc.vrfNameForLink(_vpcPeeringConnectionId); if (!accepterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(accepterCfg).setName(vrfName).build(); } if (!requesterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(requesterCfg).setName(vrfName).build(); } String ifaceNameSuffix = _vpcPeeringConnectionId; Utils.connect(awsConfiguration, accepterCfg, vrfName, requesterCfg, vrfName, ifaceNameSuffix); _requesterVpcCidrBlock.forEach( prefix -> addStaticRoute( accepterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( requesterCfg, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix))))); _accepterVpcCidrBlock.forEach( prefix -> addStaticRoute( requesterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( accepterCfg, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix))))); } VpcPeeringConnection(
      String vpcPeeringConnectionId,
      String accepterVpcId,
      List<Prefix> accepterVpcCidrBlocks,
      String requesterVpcId,
      List<Prefix> requesterVpcCidrBlocks); @Override String getId(); @Override boolean equals(Object o); @Override int hashCode(); }
VpcPeeringConnection implements AwsVpcEntity, Serializable { void createConnection(ConvertedConfiguration awsConfiguration, Warnings warnings) { Configuration accepterCfg = awsConfiguration.getNode(Vpc.nodeName(_accepterVpcId)); if (accepterCfg == null) { warnings.redFlag( String.format( "Accepter VPC %s not found for connection %s. Will not create the connection.", _accepterVpcId, _vpcPeeringConnectionId)); return; } Configuration requesterCfg = awsConfiguration.getNode(Vpc.nodeName(_requesterVpcId)); if (requesterCfg == null) { warnings.redFlag( String.format( "Requested VPC %s not found for connection %s. Will not create the connection.", _requesterVpcId, _vpcPeeringConnectionId)); return; } String vrfName = Vpc.vrfNameForLink(_vpcPeeringConnectionId); if (!accepterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(accepterCfg).setName(vrfName).build(); } if (!requesterCfg.getVrfs().containsKey(vrfName)) { Vrf.builder().setOwner(requesterCfg).setName(vrfName).build(); } String ifaceNameSuffix = _vpcPeeringConnectionId; Utils.connect(awsConfiguration, accepterCfg, vrfName, requesterCfg, vrfName, ifaceNameSuffix); _requesterVpcCidrBlock.forEach( prefix -> addStaticRoute( accepterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( requesterCfg, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix))))); _accepterVpcCidrBlock.forEach( prefix -> addStaticRoute( requesterCfg.getVrfs().get(vrfName), toStaticRoute( prefix, Utils.interfaceNameToRemote(accepterCfg, ifaceNameSuffix), Utils.getInterfaceLinkLocalIp( accepterCfg, Utils.interfaceNameToRemote(requesterCfg, ifaceNameSuffix))))); } VpcPeeringConnection(
      String vpcPeeringConnectionId,
      String accepterVpcId,
      List<Prefix> accepterVpcCidrBlocks,
      String requesterVpcId,
      List<Prefix> requesterVpcCidrBlocks); @Override String getId(); @Override boolean equals(Object o); @Override int hashCode();  }