Beispiel #1
0
 public static string GetAdminUserName(Resource server, Datacenter dc)
 {
     string user;
     if (!server.Attributes.TryGetValue("adminUser", out user) || String.IsNullOrEmpty(user))
     {
         user = String.Format(
             "{0}-admin",
             dc.FullName);
     }
     return user;
 }
Beispiel #2
0
        public Service GetService(int datacenter, string name)
        {
            Datacenter dc = this[datacenter];

            if (dc == null)
            {
                throw new KeyNotFoundException(String.Format(
                                                   CultureInfo.CurrentCulture,
                                                   Strings.DeploymentEnvironment_UnknownDatacenter,
                                                   datacenter));
            }
            return(dc.GetService(name));
        }
Beispiel #3
0
 private static IEnumerable <Service> LoadServices(Datacenter dc, XElement root)
 {
     if (root == null)
     {
         return(Enumerable.Empty <Service>());
     }
     return(root.Elements().Select(e =>
     {
         var svc = new Service(dc);
         LoadComponent(e, typeFromAttribute: false, instance: svc);
         svc.Uri = e.AttributeValueOrDefault <Uri>("url", s => new Uri(s));
         return svc;
     }));
 }
Beispiel #4
0
        private static Datacenter LoadDatacenter(XElement e, DeploymentEnvironment env)
        {
            var dc = new Datacenter(env)
            {
                Id            = e.AttributeValueOrDefault <int>("id", Int32.Parse),
                Region        = e.AttributeValueOrDefault("region"),
                AffinityGroup = e.AttributeValueOrDefault("affinityGroup")
            };

            dc.Resources.AddRange(LoadComponents <Resource>(e.Element("resources")));
            dc.Services.AddRange(LoadServices(dc, e.Element("services")));

            return(dc);
        }
        protected async Task<IDictionary<string, string>> LoadServiceConfig(Datacenter dc, Service service)
        {
            await Console.WriteInfoLine(Strings.AzureCommandBase_FetchingServiceConfig, service.Value);

            // Get creds
            var creds = await GetAzureCredentials();
            var ns = XNamespace.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration");

            // Connect to the Compute Management Client
            using (var client = CloudContext.Clients.CreateComputeManagementClient(creds))
            {
                // Download config for the deployment
                var result = await client.Deployments.GetBySlotAsync(service.Value, DeploymentSlot.Production);

                var parsed = XDocument.Parse(result.Configuration);
                return parsed.Descendants(ns + "Setting").ToDictionary(
                    x => x.Attribute("name").Value,
                    x => x.Attribute("value").Value,
                    StringComparer.OrdinalIgnoreCase);
            }
        }
        protected async Task<AzureDefaults> LoadDefaultsFromAzure(Datacenter dc, string databaseConnectionString = null, string storageConnectionString = null)
        {
            bool expired = false;
            try
            {
                if (String.IsNullOrWhiteSpace(databaseConnectionString) ||
                    String.IsNullOrWhiteSpace(storageConnectionString))
                {
                    var config = await LoadServiceConfig(dc, dc.GetService("work"));

                    databaseConnectionString = databaseConnectionString ??
                        GetValueOrDefault(config, "Sql.Legacy");
                    storageConnectionString = storageConnectionString ??
                        GetValueOrDefault(config, "Storage.Legacy");
                }

                if (String.IsNullOrWhiteSpace(databaseConnectionString) ||
                    String.IsNullOrWhiteSpace(storageConnectionString))
                {
                    throw new InvalidOperationException(Strings.Command_MissingEnvironmentArguments);
                }

                await Console.WriteInfoLine(
                    Strings.Command_ConnectionInfo,
                    new SqlConnectionStringBuilder(databaseConnectionString).DataSource,
                    CloudStorageAccount.Parse(storageConnectionString).Credentials.AccountName);
            }
            catch (CloudException ex)
            {
                if (ex.ErrorCode == "AuthenticationFailed")
                {
                    expired = true;
                }
                else
                {
                    throw;
                }
            }

            if (expired)
            {
                await Console.WriteErrorLine(Strings.AzureCommandBase_TokenExpired);
                throw new OperationCanceledException();
            }

            return new AzureDefaults { DatabaseConnectionString = databaseConnectionString, StorageConnectionString = storageConnectionString };
        }
Beispiel #7
0
 public Service(Datacenter dc)
 {
     Datacenter = dc;
 }
Beispiel #8
0
 public Service(Datacenter dc)
 {
     Datacenter = dc;
 }