Exemplo n.º 1
0
        public static Location Get(int id)
        {
            var lid = LocationId.Create(id);

            if (lid.ProviderId == 2) // AWS
            {
                var region = Aws.FindByRegionNumber(lid.RegionNumber);

                return((lid.ZoneNumber != 0)
                    ? region.WithZone(ZoneHelper.GetLetter(lid.ZoneNumber))
                    : region);
            }

            if (lid.ProviderId == 3) // GCP
            {
                if (lid.Type == LocationType.MultiRegion)
                {
                    switch (lid.ZoneNumber)
                    {
                    case 1: return(Gcp.US);

                    case 2: return(Gcp.EU);

                    case 3: return(Gcp.Asia);

                    default: throw new Exception("No multi-region found:" + lid.ZoneNumber);
                    }
                }

                return(Gcp.FindByRegionNumber(lid.RegionNumber));
            }

            if (lid.ProviderId == 4) // Azure
            {
                throw new Exception("Azure is not supported");
            }

            if (lid.ProviderId == ResourceProvider.GCore.Id)
            {
                return(GCore.Get(id));
            }

            if (lid.ProviderId == 10) // Digital Ocean
            {
                return(DigitalOcean.FindByRegionNumber(lid.RegionNumber));
            }

            if (lid.ProviderId == ResourceProvider.Wasabi.Id)
            {
                return(Wasabi.FindByRegionNumber(lid.RegionNumber));
            }

            throw new Exception($"Unexpected id: {lid.ProviderId}|{lid.RegionNumber}|{lid.ZoneNumber}");
        }
Exemplo n.º 2
0
        public LocationInfo(
            int id,
            string name,
            LocationStatus status = LocationStatus.Healthy)
        {
            Ensure.IsValidId(id);
            Ensure.NotNullOrEmpty(name, nameof(name));

            Id         = id;
            ProviderId = LocationId.Create(id).ProviderId;
            Name       = name;
            Status     = status;
        }
Exemplo n.º 3
0
 private static Location Create(ushort regionNumber, string name)
 {
     return(new Location(LocationId.Create(ResourceProvider.Aws, regionNumber), name));
 }
Exemplo n.º 4
0
        public static ResourceProvider FromLocationId(int locationId)
        {
            var providerId = LocationId.Create(locationId).ProviderId;

            return(Get(providerId));
        }
Exemplo n.º 5
0
            private static Location Create(int number, string name)
            {
                var locationId = LocationId.Create(ResourceProvider.GCore, (ushort)number, 0);

                return(new Location(locationId, name));
            }