コード例 #1
0
        public async Task <SA_Vpc> GetVPC()
        {
            //var filters = new List<Filter>();
            //var filter = new Filter("Name", new List<string> { environment.ToString() });
            //filters.Add(filter);
            //var request = new DescribeVpcsRequest()
            //{
            //    Filters = filters
            //};
            //Vpc
            var response = await client.DescribeVpcsAsync();

            var vpc = response.Vpcs.Find(o => o.Tags.Find(p => p.Key == "Name").Value == environment.ToString());

            if (vpc == null)
            {
                return(null);
            }
            var awsVpc = new SA_Vpc()
            {
                CidrBlock = vpc.CidrBlock,
                Name      = vpc.Tags.Find(o => o.Key == "Name").Value,
                State     = vpc.State,
                VpcId     = vpc.VpcId
            };

            return(awsVpc);
        }
コード例 #2
0
        public async Task <string> CreatePeeringConnection(SA_Vpc requesterVpc, SA_Vpc accepterVpc)
        {
            var peeringConnectionId = await ec2Helper.CreatePeeringConnection(
                //AwsCommon.GetEnvironmentAccounts()[GlobalVariables.Enviroment].Account ,
                GlobalVariables.EnvironmentAccounts[GlobalVariables.Enviroment].Account,
                requesterVpc.VpcId, accepterVpc.VpcId,
                Utils.FormatresourceName(SA_ResourceTypeName.RdsPeeringConnection));

            await Task.Delay(5000);

            await ec2Helper.AcceptPeeringConnection(peeringConnectionId);

            await AddPeeringConnectionToRouteTables(requesterVpc, accepterVpc, peeringConnectionId);

            return(peeringConnectionId);
        }
コード例 #3
0
        private async Task RemovePeeringConnectionFromRouteTables(SA_Vpc requesterVpc, SA_Vpc accepterVpc, string peerConnectionId)
        {
            //Set requester
            var requesterRouteTables = await ec2Helper.GetRouteTablesByVpc(requesterVpc.VpcId);

            foreach (var routeTable in requesterRouteTables)
            {
                await ec2Helper.DeleteRouteForRouteTable(accepterVpc.CidrBlock, routeTable);
            }

            var accepterRouteTables = await ec2Helper.GetRouteTablesByVpc(requesterVpc.VpcId);

            foreach (var routeTable in accepterRouteTables)
            {
                await ec2Helper.DeleteRouteForRouteTable(requesterVpc.CidrBlock, routeTable);
            }
        }
コード例 #4
0
        private async Task AddPeeringConnectionToRouteTables(SA_Vpc requesterVpc, SA_Vpc accepterVpc, string peerConnectionId)
        {
            //Set requester
            var requesterRouteTables = await ec2Helper.GetRouteTablesByVpc(requesterVpc.VpcId);

            foreach (var routeTable in requesterRouteTables)
            {
                ec2Helper.CreateRouteForRouteTable(peerConnectionId, null, null, accepterVpc.CidrBlock, routeTable);
            }

            var accepterRouteTables = await ec2Helper.GetRouteTablesByVpc(accepterVpc.VpcId);

            foreach (var routeTable in accepterRouteTables)
            {
                ec2Helper.CreateRouteForRouteTable(peerConnectionId, null, null, requesterVpc.CidrBlock, routeTable);
            }
        }
コード例 #5
0
        public async Task DeletePeeringConnection(string vpcPeeringConnectionId, SA_Vpc requesterVpc, SA_Vpc accepterVpc)
        {
            await ec2Helper.DeletePeeringConnection(vpcPeeringConnectionId);

            await RemovePeeringConnectionFromRouteTables(requesterVpc, accepterVpc, vpcPeeringConnectionId);
        }