コード例 #1
0
        public static string GetStorageAccountName(this IAzureSubscription subscription)
        {
            if (subscription == null || !subscription.IsPropertySet(AzureSubscription.Property.StorageAccount))
            {
                return(null);
            }

            var result = subscription.GetProperty(AzureSubscription.Property.StorageAccount);

            if (!string.IsNullOrWhiteSpace(result))
            {
                try
                {
                    var pairs = result.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var pair in pairs)
                    {
                        var sides = pair.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                        if (string.Equals("AccountName", sides[0].Trim(), StringComparison.OrdinalIgnoreCase))
                        {
                            result = sides[1].Trim();
                            break;
                        }
                    }
                }
                catch
                {
                    // if there are any errors, return the unchanged account name
                }
            }

            return(result);
        }
コード例 #2
0
 public PSAzureSubscription(IAzureSubscription subscription, AzureSMProfile profile)
 {
     SubscriptionId            = subscription.Id.ToString();
     SubscriptionName          = subscription.Name;
     Environment               = subscription.GetEnvironment();
     DefaultAccount            = subscription.GetAccount();
     Accounts                  = profile.AccountTable.Values.Where(a => a.HasSubscription(subscription.GetId())).ToArray();
     IsDefault                 = subscription.IsPropertySet(AzureSubscription.Property.Default);
     IsCurrent                 = profile.Context != null && profile.Context.Subscription.Id == subscription.Id;
     CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
     TenantId                  = subscription.GetTenant();
 }
コード例 #3
0
        private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(IAzureSubscription subscription, IClientFactory clientFactory)
        {
            using (var client = clientFactory.CreateClient <ManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement))
            {
                var  response                      = client.Subscriptions.Get();
                var  environment                   = ProfileClient.GetEnvironmentOrDefault(subscription.GetEnvironment());
                var  account                       = ProfileClient.Profile.AccountTable[subscription.GetAccount()];
                bool isCert                        = account.Type == AzureAccount.AccountType.Certificate;
                var  psAzureSubscription           = new PSAzureSubscription(subscription, ProfileClient.Profile);
                PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(psAzureSubscription)
                {
                    AccountAdminLiveEmailId    = response.AccountAdminLiveEmailId,
                    ActiveDirectoryUserId      = subscription.GetAccount(),
                    CurrentCoreCount           = response.CurrentCoreCount,
                    CurrentHostedServices      = response.CurrentHostedServices,
                    CurrentDnsServers          = response.CurrentDnsServers,
                    CurrentLocalNetworkSites   = response.CurrentLocalNetworkSites,
                    CurrentStorageAccounts     = response.CurrentStorageAccounts,
                    CurrentVirtualNetworkSites = response.CurrentVirtualNetworkSites,
                    MaxCoreCount            = response.MaximumCoreCount,
                    MaxDnsServers           = response.MaximumDnsServers,
                    MaxHostedServices       = response.MaximumHostedServices,
                    MaxLocalNetworkSites    = response.MaximumLocalNetworkSites,
                    MaxStorageAccounts      = response.MaximumStorageAccounts,
                    MaxVirtualNetworkSites  = response.MaximumVirtualNetworkSites,
                    ServiceAdminLiveEmailId = response.ServiceAdminLiveEmailId,
                    SubscriptionRealName    = response.SubscriptionName,
                    SubscriptionStatus      = response.SubscriptionStatus.ToString(),
                    ServiceEndpoint         = environment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement),
                    ResourceManagerEndpoint = environment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager),
                    IsDefault   = subscription.GetProperty(AzureSubscription.Property.Default) != null,
                    Account     = account,
                    Certificate = isCert ? AzureSession.Instance.DataStore.GetCertificate(subscription.GetAccount()) : null,
                    CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount)
                };

                return(result);
            }
        }
コード例 #4
0
        protected void ValidateParameters()
        {
            IAzureSubscription currentSubscription = Profile.Context.Subscription;

            if ((currentSubscription == null || string.IsNullOrEmpty(currentSubscription.GetProperty(AzureSubscription.Property.StorageAccount))) && string.IsNullOrEmpty(MediaLocation))
            {
                throw new ArgumentException(Resources.MustSpecifyMediaLocationOrHaveCurrentStorageAccount);
            }

            if (string.IsNullOrEmpty(Label))
            {
                Label = Name;
            }
        }
コード例 #5
0
        private IAzureSubscription MergeSubscriptionProperties(IAzureSubscription subscription1, IAzureSubscription subscription2)
        {
            if (subscription1 == null || subscription2 == null)
            {
                throw new ArgumentNullException("subscription1");
            }
            if (subscription1.Id != subscription2.Id)
            {
                throw new ArgumentException("Subscription Ids do not match.");
            }
            AzureSubscription mergedSubscription = new AzureSubscription
            {
                Id    = subscription1.Id,
                Name  = subscription1.Name,
                State = (subscription1.State != null &&
                         subscription1.State.Equals(subscription2.State, StringComparison.OrdinalIgnoreCase)) ?
                        subscription1.State : null,
            };

            foreach (var property in subscription1.ExtendedProperties.Keys.Union(subscription2.ExtendedProperties.Keys))
            {
                mergedSubscription.SetProperty(property, subscription1.IsPropertySet(property) ?
                                               subscription1.GetProperty(property) : subscription2.GetProperty(property));
            }

            // Merge RegisteredResourceProviders
            var registeredProviders = subscription1.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders)
                                      .Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders), StringComparer.CurrentCultureIgnoreCase);

            mergedSubscription.SetProperty(AzureSubscription.Property.RegisteredResourceProviders, registeredProviders.ToArray());

            // Merge Tenants
            var tenants = subscription1.GetPropertyAsArray(AzureSubscription.Property.Tenants)
                          .Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.Tenants), StringComparer.CurrentCultureIgnoreCase);

            mergedSubscription.SetProperty(AzureSubscription.Property.Tenants, tenants.ToArray());

            return(mergedSubscription);
        }
コード例 #6
0
 /// <summary>
 /// Get the current storage account for the given subscription
 /// </summary>
 /// <param name="subscription">The subscription to check</param>
 /// <returns>The current storage accoutn in the subscription, or null if no current storage account is set</returns>
 public static string GetStorageAccount(this IAzureSubscription subscription)
 {
     return(subscription.GetProperty(AzureSubscription.Property.StorageAccount));
 }
コード例 #7
0
 /// <summary>
 /// Get the environment this subscription resides in
 /// </summary>
 /// <param name="subscription">The subscription to check</param>
 /// <returns>The name of the environment contianing the given subscription</returns>
 public static string GetEnvironment(this IAzureSubscription subscription)
 {
     return(subscription.GetProperty(AzureSubscription.Property.Environment));
 }
コード例 #8
0
        /// <summary>
        /// Get the tags associated with this subscription
        /// </summary>
        /// <param name="subscription">The subscription to check</param>
        /// <returns>The tags of the subscription</returns>
        public static Dictionary <string, string> GetTags(this IAzureSubscription subscription)
        {
            var tags = subscription.GetProperty(AzureSubscription.Property.Tags);

            return(string.IsNullOrEmpty(tags) ? null : JsonConvert.DeserializeObject <Dictionary <string, string> >(tags));
        }
コード例 #9
0
 /// <summary>
 /// Get the subscription polices associated with this subscription
 /// </summary>
 /// <param name="subscription">The subscription to check</param>
 /// <returns>The subscription polices</returns>
 public static string GetSubscriptionPolicies(this IAzureSubscription subscription)
 {
     return(subscription.GetProperty(AzureSubscription.Property.SubscriptionPolices));
 }
コード例 #10
0
 public static string GetHomeTenant(this IAzureSubscription subscription)
 {
     return(subscription.GetProperty(AzureSubscription.Property.HomeTenant));
 }
コード例 #11
0
 /// <summary>
 /// RDFE only: determines if this subscription is the default
 /// </summary>
 /// <param name="subscription">The subscription to check</param>
 /// <returns>True if it is the default subscription, false otherwise</returns>
 public static bool IsDefault(this IAzureSubscription subscription)
 {
     return(subscription.IsPropertySet(AzureSubscription.Property.Default) &&
            string.Equals("True", subscription.GetProperty(AzureSubscription.Property.Default), System.StringComparison.OrdinalIgnoreCase));
 }