コード例 #1
0
            public static readonly Location SFO2 = Create(12, "SFO2"); // 2017-07-12 | San Francisco

            public static Location Get(string name)
            {
                switch (name.ToUpper())
                {
                case "NYC1": return(NYC1);

                case "SFO1": return(SFO1);

                case "NYC2": return(NYC2);

                case "AMS2": return(AMS2);

                case "SGP1": return(SGP1);

                case "LON1": return(LON1);

                case "NYC3": return(NYC3);

                case "AMS3": return(AMS3);

                case "FRA1": return(FRA1);

                case "TOR1": return(TOR1);

                case "BLR1": return(BLR1);

                case "SFO2": return(SFO2);
                }

                throw ResourceError.NotFound(ResourceProvider.DigitalOcean, ResourceTypes.Location, name);
            }
コード例 #2
0
            public static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 1: return(NYC1);

                case 2: return(SFO1);

                case 3: return(NYC2);

                case 4: return(AMS2);

                case 5: return(SGP1);

                case 6: return(LON1);

                case 7: return(NYC3);

                case 8: return(AMS3);

                case 9: return(FRA1);

                case 10: return(TOR1);

                case 11: return(BLR1);

                case 12: return(SFO2);
                }

                throw ResourceError.NotFound(ResourceProvider.DigitalOcean, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #3
0
            public static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 01: return(US_Central1);

                case 02: return(Europe_West1);

                case 03: return(Asia_East1);

                case 04: return(US_East1);

                case 05: return(US_West1);

                case 06: return(Asia_NorthEast1);

                case 07: return(Asia_NorthEast1);

                case 08: return(Asia_SouthEast1);

                case 09: return(US_East4);

                case 10: return(Europe_West2);

                case 11: return(Europe_West3);

                case 12: return(SouthAmerica_East1);

                case 13: return(Asia_South1);
                }

                throw ResourceError.NotFound(ResourceProvider.Gcp, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #4
0
ファイル: NetworkManager.cs プロジェクト: renatotkr/Platform
        private async Task <NetworkInfo> GetAsync(string vpcId)
        {
            var network = await networkService.FindAsync(Aws, vpcId);;

            if (network == null)
            {
                var vpc = await ec2Client.DescribeVpcAsync(vpcId)
                          ?? throw ResourceError.NotFound(Aws, ResourceTypes.Network, vpcId);

                var region = Locations.Get(Aws, ec2Client.Region.Name);

                var registerRequest = new RegisterNetworkRequest(
                    addressBlocks: new[] { vpc.CidrBlock },
                    resource: ManagedResource.Network(region, vpc.VpcId),
                    ownerId: 1
                    );

                // TODO: Sync the subnets & security groups

                // TODO: Support ipv6 address blocks

                // Register the network with the platform
                network = await networkService.RegisterAsync(registerRequest);;
            }

            return(network);
        }
コード例 #5
0
            public static readonly Location Asia_South1          = Create(13, "asia-south1");          // | IN | Mumbai        | 2017-10-31

            public static Location Get(string name)
            {
                if (name == null)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                var lastChar = name[name.Length - 1];

                // -(a|b|c|d|...)
                if (!char.IsDigit(lastChar))
                {
                    var region = Get(name.Substring(0, name.Length - 2));

                    return(region.WithZone(lastChar));
                }

                // Check if it's a zone
                foreach (var location in All)
                {
                    if (location.Name == name)
                    {
                        return(location);
                    }
                }

                throw ResourceError.NotFound(ResourceProvider.Gcp, ResourceTypes.Location, name);
            }
コード例 #6
0
ファイル: NetworkManager.cs プロジェクト: renatotkr/Platform
        public async Task <SubnetInfo> GetSubnetAsync(ResourceProvider provider, string subnetId)
        {
            var subnet = await subnetService.FindAsync(provider, subnetId);;

            if (subnet == null)
            {
                var awsSubnet = await ec2Client.DescribeSubnetAsync(subnetId)
                                ?? throw ResourceError.NotFound(Aws, ResourceTypes.Subnet, subnetId);

                var location = Locations.Get(Aws, awsSubnet.AvailabilityZone);

                var network = await networkService.GetAsync(Aws, awsSubnet.VpcId);;

                var createRequest = new RegisterSubnetRequest(
                    addressBlocks: new[] { awsSubnet.CidrBlock },
                    networkId: network.Id,
                    resource: ManagedResource.Subnet(location, awsSubnet.SubnetId)
                    );

                // TODO: Include the ipv6 address blocks

                // Register the subnet with the platform
                subnet = await subnetService.RegisterAsync(createRequest);;
            }

            return(subnet);
        }
コード例 #7
0
        public static Location Get(ResourceProvider provider, string name)
        {
            #region Preconditions

            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            #endregion

            switch (provider.Id)
            {
            case 2: return(Aws.Get(name));

            case 3: return(Gcp.Get(name));

            case 10: return(DigitalOcean.Get(name));

            case 105: return(GCore.Get(name));
            }

            throw ResourceError.NotFound(provider, ResourceTypes.Location, name);
        }
コード例 #8
0
ファイル: DatabaseService.cs プロジェクト: renatotkr/Platform
        public async Task <DatabaseInfo> GetAsync(long id)
        {
            Ensure.IsValidId(id);

            return(await db.Databases.FindAsync(id)
                   ?? throw ResourceError.NotFound(ResourceTypes.Database, id));
        }
コード例 #9
0
        public async Task <Distribution> GetAsync(ResourceProvider provider, string resourceId)
        {
            Ensure.NotNull(provider, nameof(provider));

            return(await db.Distributions.QueryFirstOrDefaultAsync(
                       Conjunction(Eq("providerId", provider.Id), Eq("resourceId", resourceId))
                       ) ?? throw ResourceError.NotFound(provider, ResourceTypes.Distribution, resourceId));
        }
コード例 #10
0
        public async Task <EnvironmentInfo> GetAsync(long ownerId, string name)
        {
            Ensure.NotNull(name, nameof(name));

            return(await db.Environments.QueryFirstOrDefaultAsync(
                       Conjunction(Eq("ownerId", ownerId), Eq("name", name), IsNull("deleted"))
                       ) ?? throw ResourceError.NotFound(ResourceTypes.Environment, ownerId, name));
        }
コード例 #11
0
            public static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 1: return(USEast1);
                }

                throw ResourceError.NotFound(ResourceProvider.Wasabi, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #12
0
        // 1 | aws:vpc1

        public async Task <NetworkInfo> GetAsync(string name)
        {
            if (long.TryParse(name, out var id))
            {
                return(await GetAsync(id));
            }

            var(provider, resourceId) = ResourceName.Parse(name);

            return(await FindAsync(provider, resourceId)
                   ?? throw ResourceError.NotFound(ManagedResource.Network(provider, name)));
        }
コード例 #13
0
            public static readonly Location SaintPetersburg = Create(39, "k12"); // 2017-12-11 | 11th in Russia

            // Coming...
            // - Denver
            // - Los Angeles
            // - Toronto
            // - São Paulo
            // - Vienna

            // tii (TR/Istanbul)
            // ttkb (RU/Yekaterinburg)

            // tde (Omaha?)

            public static Location Get(int id)
            {
                foreach (var location in All)
                {
                    if (location.Id == id)
                    {
                        return(location);
                    }
                }

                throw ResourceError.NotFound(ResourceProvider.GCore, ResourceTypes.Location, id.ToString());
            }
コード例 #14
0
            public static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 01: return(DAL);

                case 02: return(NYC);

                case 03: return(SEA);
                }

                throw ResourceError.NotFound(ResourceProvider.Incero, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #15
0
            public static readonly Location SEA = Create(3, "SEA"); // ? | US/WA/Seattle

            public static Location Get(string name)
            {
                switch (name.ToUpper())
                {
                case "DAL": return(DAL);

                case "NYC": return(NYC);

                case "SEA": return(SEA);
                }

                throw ResourceError.NotFound(ResourceProvider.Incero, ResourceTypes.Location, name);
            }
コード例 #16
0
        public async Task <VolumeInfo> GetAsync(string name)
        {
            Ensure.NotNullOrEmpty(name, nameof(name));

            if (long.TryParse(name, out var id))
            {
                return(await GetAsync(id));
            }

            var(provider, resourceId) = ResourceName.Parse(name);

            return(await FindAsync(provider, resourceId)
                   ?? throw ResourceError.NotFound(ManagedResource.Volume(provider, name)));
        }
コード例 #17
0
            public static readonly Location EUWest3      = Create(18, "eu-west-3");      // | EU    | Paris         | 2018-12-18

            internal static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 01: return(USEast1);

                case 02: return(EUWest1);

                case 03: return(USWest1);

                case 04: return(APSouthEast1);

                case 05: return(APNorthEast1);

                case 06: return(USGovWest1);

                case 07: return(USWest2);

                case 08: return(SAEast1);

                case 09: return(APSouthEast2);

                case 10: return(CNNorth1);

                case 11: return(EUCentral1);

                case 12: return(APNortheast2);

                case 13: return(APSouth1);

                case 14: return(USEast2);

                case 15: return(CACentral1);

                case 16: return(EUWest2);

                case 17: return(CNNorthwest1);

                case 18: return(EUWest3);
                }

                throw ResourceError.NotFound(ResourceProvider.Aws, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #18
0
        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);
        }
コード例 #19
0
            public static Location FindByRegionNumber(int regionNumber)
            {
                switch (regionNumber)
                {
                case 01: return(EWR);

                case 02: return(ORD);

                case 03: return(DFW);

                case 04: return(SEA);

                case 05: return(LAX);

                case 06: return(ATL);

                case 07: return(AMS);

                case 08: return(LHR);

                case 09: return(FRA);

                case 10: return(SJC);

                case 11: return(SYD);

                case 12: return(CDG);

                case 13: return(NRT);

                case 14: return(MIA);

                case 15: return(SGP);
                }

                throw ResourceError.NotFound(ResourceProvider.Vultr, ResourceTypes.Location, "region#" + regionNumber);
            }
コード例 #20
0
            public static readonly Location SGP = Create(15, "SGP"); // ? | Singapore

            public static Location Get(string name)
            {
                switch (name.ToUpper())
                {
                case "EWR": return(EWR);

                case "ORD": return(ORD);

                case "DFW": return(DFW);

                case "SEA": return(SEA);

                case "LAX": return(LAX);

                case "ATL": return(ATL);

                case "AMS": return(AMS);

                case "LHR": return(LHR);

                case "FRA": return(FRA);

                case "SJC": return(SJC);

                case "SYD": return(SYD);

                case "CDG": return(CDG);

                case "NRT": return(NRT);

                case "MIA": return(MIA);

                case "SGP": return(SGP);
                }

                throw ResourceError.NotFound(ResourceProvider.Vultr, ResourceTypes.Location, name);
            }
コード例 #21
0
            public static Location Get(string name)
            {
                // ap-northeast-2a

                var lastCharacter = name[name.Length - 1];

                // it's a zone if it ends with a character
                if (char.IsLetter(lastCharacter))
                {
                    var region = Get(name.Substring(0, name.Length - 1));

                    return(region.WithZone(lastCharacter));
                }

                foreach (var region in All)
                {
                    if (region.Name == name)
                    {
                        return(region);
                    }
                }

                throw ResourceError.NotFound(ResourceProvider.Aws, ResourceTypes.Location, name);
            }
コード例 #22
0
 public async Task <BucketInfo> GetAsync(long id)
 {
     return(await db.Buckets.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Volume, id));
 }
コード例 #23
0
 public async Task <NetworkInfo> GetAsync(long id)
 {
     return(await db.Networks.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Network, id));
 }
コード例 #24
0
ファイル: ImageService.cs プロジェクト: renatotkr/Platform
 public async Task <ImageInfo> GetAsync(long ownerId, string name)
 {
     return(await db.Images.QueryFirstOrDefaultAsync(
                And(Eq("ownerId", ownerId), Eq("name", name))
                ) ?? throw ResourceError.NotFound(ResourceTypes.Image, ownerId, name));
 }
コード例 #25
0
 public async Task <Distribution> GetAsync(long id)
 {
     return(await db.Distributions.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Environment, id));
 }
コード例 #26
0
 public async Task <NetworkInfo> GetAsync(ResourceProvider provider, string resourceId)
 {
     return(await db.Networks.FindAsync(provider, resourceId)
            ?? throw ResourceError.NotFound(provider, ResourceTypes.Network, resourceId));
 }
コード例 #27
0
 public async Task <Cluster> GetAsync(long id)
 {
     return(await db.Clusters.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Cluster, id));
 }
コード例 #28
0
 public async Task <EnvironmentInfo> GetAsync(long id)
 {
     return(await db.Environments.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Environment, id));
 }
コード例 #29
0
 public async Task <DomainRegistration> GetAsync(long id)
 {
     return(await db.DomainRegistrations.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.DomainRegistration, id));
 }
コード例 #30
0
 public async Task <ProgramInfo> GetAsync(long id)
 {
     return(await db.Programs.FindAsync(id)
            ?? throw ResourceError.NotFound(ResourceTypes.Program, id));
 }