/// <summary>
        /// Create an Azure storage account that we can use to upload our
        /// package when creating and deploying a service.
        /// </summary>
        private void CreateStorageAccount()
        {
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.ServiceSettings.StorageAccountName),
                "StorageAccountName cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.Label),
                "Label cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.ServiceSettings.Location),
                "Location cannot be null or empty.");

            CreateStorageServiceInput storageServiceInput = new CreateStorageServiceInput
            {
                ServiceName = _deploymentSettings.ServiceSettings.StorageAccountName,
                Label       = ServiceManagementHelper.EncodeToBase64String(_deploymentSettings.Label),
                Location    = _deploymentSettings.ServiceSettings.Location
            };

            InvokeInOperationContext(() =>
            {
                RetryCall(subscription =>
                          Channel.CreateStorageAccount(subscription, storageServiceInput));

                StorageService storageService = null;
                do
                {
                    storageService = RetryCall(subscription =>
                                               Channel.GetStorageService(subscription, storageServiceInput.ServiceName));
                }while (storageService.StorageServiceProperties.Status != StorageAccountStatus.Created);
            });
        }
示例#2
0
        /// <summary>
        /// Creates storage service if it does not exist.
        /// </summary>
        /// <param name="name">The storage service name</param>
        /// <param name="label">The storage service label</param>
        /// <param name="location">The location name. If not provided default one will be used</param>
        /// <param name="affinityGroup">The affinity group name</param>
        public void CreateStorageServiceIfNotExist(
            string name,
            string label         = null,
            string location      = null,
            string affinityGroup = null)
        {
            if (!StorageServiceExists(name))
            {
                CreateStorageServiceInput storageServiceInput = new CreateStorageServiceInput
                {
                    ServiceName = name,
                    Label       = label,
                };

                if (!string.IsNullOrEmpty(affinityGroup))
                {
                    storageServiceInput.AffinityGroup = affinityGroup;
                }
                else
                {
                    location = string.IsNullOrEmpty(location) ? GetDefaultLocation() : location;
                    storageServiceInput.Location = location;
                }

                CallSync(() => ServiceManagementChannel.CreateStorageService(subscriptionId, storageServiceInput));
            }
        }
示例#3
0
        internal void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Label))
            {
                Label = StorageAccountName;
            }
            var createStorageServiceInput = new CreateStorageServiceInput()
            {
                ServiceName   = this.StorageAccountName,
                Label         = this.Label,
                Description   = this.Description,
                AffinityGroup = this.AffinityGroup,
                Location      = this.Location
            };

            ExecuteClientActionInOCS(createStorageServiceInput, CommandRuntime.ToString(), s => this.Channel.CreateStorageService(s, createStorageServiceInput));
        }
        private void CreateStorageAccount()
        {
            WriteObject("Creating storage account: " + _storageAccount);
            WriteObject("This may take a few minutes.");

            CreateStorageServiceInput input = new CreateStorageServiceInput();

            input.ServiceName = this.StorageAccount;
            input.Label       = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(this.StorageAccount));
            if (string.IsNullOrEmpty(this.Location) == false)
            {
                input.Location = this.Location;
            }
            else if (string.IsNullOrEmpty(this.AffinityGroup) == false)
            {
                input.AffinityGroup = this.AffinityGroup;
            }
            else  // Randomly use "North Central US" or "South Central US"
            {
                int randomLocation = new Random().Next(0, 1);
                input.Location = randomLocation == 0 ? "North Central US" : "South Central US";
            }

            try
            {
                _createRequestToken = ServiceManagementHelpers.CreateStorageAcc(this._subscriptionId, input, this._cert);
            }
            catch (Exception)
            {
                if (IsStorageAccountLimitExceeded() == true)
                {
                    throw new ApplicationFailedException(Resources.StorageAccLimitReached);
                }
                else
                {
                    throw;
                }
            }
            WaitTillCreationComplete();
        }
示例#5
0
        public void NewStorageAccountProcess()
        {
            Action <string>           action = null;
            CreateStorageServiceInput createStorageServiceInput = new CreateStorageServiceInput();

            createStorageServiceInput.ServiceName   = this.StorageAccountName;
            createStorageServiceInput.Label         = ServiceManagementHelper.EncodeToBase64String(this.Label);
            createStorageServiceInput.Description   = this.Description;
            createStorageServiceInput.AffinityGroup = this.AffinityGroup;
            createStorageServiceInput.Location      = this.Location;
            CreateStorageServiceInput createStorageServiceInput1 = createStorageServiceInput;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    CmdletExtensions.WriteVerboseOutputForObject(this, createStorageServiceInput1);
                    NewAzureStorageAccountCommand newAzureStorageAccountCommand = this;
                    if (action == null)
                    {
                        action = (string s) => base.Channel.CreateStorageService(s, createStorageServiceInput1);
                    }
                    ((CmdletBase <IServiceManagement>)newAzureStorageAccountCommand).RetryCall(action);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    ManagementOperationContext managementOperationContext = new ManagementOperationContext();
                    managementOperationContext.set_OperationDescription(base.CommandRuntime.ToString());
                    managementOperationContext.set_OperationId(operation.OperationTrackingId);
                    managementOperationContext.set_OperationStatus(operation.Status);
                    ManagementOperationContext managementOperationContext1 = managementOperationContext;
                    base.WriteObject(managementOperationContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
        /// <summary>
        /// Creates storage service if it does not exist.
        /// </summary>
        /// <param name="name">The storage service name</param>
        /// <param name="label">The storage service label</param>
        /// <param name="location">The location name. If not provided default one will be used</param>
        /// <param name="affinityGroup">The affinity group name</param>
        public void CreateStorageServiceIfNotExist(
            string name,
            string label = null,
            string location = null,
            string affinityGroup = null)
        {
            if (!StorageServiceExists(name))
            {
                CreateStorageServiceInput storageServiceInput = new CreateStorageServiceInput
                {
                    ServiceName = name,
                    Label = label,
                };

                if (!string.IsNullOrEmpty(affinityGroup))
                {
                    storageServiceInput.AffinityGroup = affinityGroup;
                }
                else
                {
                    location = string.IsNullOrEmpty(location) ? GetDefaultLocation() : location;
                    storageServiceInput.Location = location;
                }

                CallSync(() => ServiceManagementChannel.CreateStorageService(subscriptionId, storageServiceInput));
            }
        }
        internal void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Label))
            {
                Label = StorageAccountName;
            }
            var createStorageServiceInput = new CreateStorageServiceInput()
            {
                ServiceName = this.StorageAccountName,
                Label = ServiceManagementHelper.EncodeToBase64String(this.Label),
                Description = this.Description,
                AffinityGroup = this.AffinityGroup,
                Location = this.Location
            };

            ExecuteClientActionInOCS(createStorageServiceInput, CommandRuntime.ToString(), s => this.Channel.CreateStorageService(s, createStorageServiceInput), WaitForOperation);
        }
 public static void CreateStorageService(this IServiceManagement proxy, string subscriptionId, CreateStorageServiceInput input)
 {
     proxy.EndCreateStorageService(proxy.BeginCreateStorageService(subscriptionId, input, null, null));
 }
        /// <summary>
        /// Create an Azure storage account that we can use to upload our
        /// package when creating and deploying a service.
        /// </summary>
        private void CreateStorageAccount(string name, string label, string location, string affinityGroup)
        {
            CreateStorageServiceInput storageServiceInput = new CreateStorageServiceInput
            {
                ServiceName = name,
                Label = label,
            };

            if (!string.IsNullOrEmpty(affinityGroup))
            {
                storageServiceInput.AffinityGroup = affinityGroup;
            }
            else
            {
                storageServiceInput.Location = location;
            }

            WriteVerboseWithTimestamp(String.Format(Resources.PublishVerifyingStorageMessage, name));

            InvokeInOperationContext(() =>
            {
                RetryCall(subscription =>
                    Channel.CreateStorageService(subscription, storageServiceInput));

                StorageService storageService = null;
                do
                {
                    try
                    {
                        storageService = RetryCall<StorageService>(subscription =>
                        Channel.GetStorageService(subscription, storageServiceInput.ServiceName));
                    }
                    catch (Exception)
                    {
                        // Ignore the exception, keep getting the status.
                    }
                }
                while (storageService.StorageServiceProperties.Status != StorageServiceStatus.Created);
            });
        }
 public static void CreateStorageService(this IServiceManagement proxy, string subscriptionId, CreateStorageServiceInput input)
 {
     proxy.EndCreateStorageService(proxy.BeginCreateStorageService(subscriptionId, input, null, null));
 }
 public IAsyncResult BeginCreateStorageService(string subscriptionId, CreateStorageServiceInput createStorageServiceInput, AsyncCallback callback, object state)
 {
     SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
     result.Values["subscriptionId"] = subscriptionId;
     result.Values["createStorageServiceInput"] = createStorageServiceInput;
     result.Values["callback"] = callback;
     result.Values["state"] = state;
     return result;
 }
        /// <summary>
        /// Create an Azure storage account that we can use to upload our
        /// package when creating and deploying a service.
        /// </summary>
        private void CreateStorageAccount()
        {
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.ServiceSettings.StorageAccountName),
                "StorageAccountName cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.Label),
                "Label cannot be null or empty.");
            Debug.Assert(
                !string.IsNullOrEmpty(_deploymentSettings.ServiceSettings.Location),
                "Location cannot be null or empty.");

            CreateStorageServiceInput storageServiceInput = new CreateStorageServiceInput
            {
                ServiceName = _deploymentSettings.ServiceSettings.StorageAccountName,
                Label = ServiceManagementHelper.EncodeToBase64String(_deploymentSettings.Label),
                Location = _deploymentSettings.ServiceSettings.Location
            };

            InvokeInOperationContext(() =>
            {
                RetryCall(subscription =>
                    Channel.CreateStorageAccount(subscription, storageServiceInput));

                StorageService storageService = null;
                do
                {
                    storageService = RetryCall<StorageService>(subscription =>
                        Channel.GetStorageService(subscription, storageServiceInput.ServiceName));
                }
                while (storageService.StorageServiceProperties.Status != StorageAccountStatus.Created);
            });
        }