public async Task <SubnetInfo> RegisterAsync(RegisterSubnetRequest request) { Ensure.Object(request, nameof(request)); // Validate the request // TODO: Get subnetCount from network? var subnet = new SubnetInfo( id: await db.Subnets.GetNextScopedIdAsync(request.NetworkId), addressBlocks: request.AddressBlocks, resource: request.Resource ); await db.Subnets.InsertAsync(subnet); return(subnet); }
public async Task <NetworkInterfaceInfo> GetAsync(ResourceProvider provider, string resourceId) { var record = await networkInterfaces.FindAsync(provider, resourceId);; if (record == null) { var nic = await ec2.DescribeNetworkInterfaceAsync(resourceId) ?? throw ResourceError.NotFound(Aws, ResourceTypes.NetworkInterface, resourceId); var network = await networkService.GetAsync(Aws, nic.VpcId); var region = Locations.Get(network.LocationId); SubnetInfo subnet = nic.SubnetId != null ? await subnetService.FindAsync(Aws, nic.SubnetId) : null; var securityGroupIds = new long[nic.Groups.Length]; for (var i = 0; i < securityGroupIds.Length; i++) { var nsg = await nsgManager.GetAsync(network, nic.Groups[i]);; securityGroupIds[i] = nsg.Id; } // TODO: Lookup host & create an attachment (ni.Attachment?.AttachTime) ... var registerRequest = new RegisterNetworkInterfaceRequest( mac: MacAddress.Parse(nic.MacAddress), subnetId: subnet?.Id ?? 0, securityGroupIds: securityGroupIds, resource: ManagedResource.NetworkInterface(region, nic.NetworkInterfaceId) ); record = await networkInterfaces.RegisterAsync(registerRequest);; } return(record); }