/// <summary> /// Processes the Push-CloudServices commandlet synchronously. /// </summary> protected override void ProcessRecord() { var azureSubscription = new AzureSubscription(SettingsPath, SubscriptionId); var azureCert = new X509Certificate2(Convert.FromBase64String(azureSubscription.ManagementCertificate)); var credentials = new CertificateCloudCredentials(SubscriptionId, azureCert); FlexStreams.UseThreadQueue(ThreadAdapter); using (EventStream.Subscribe(e => WriteObject(e.Message))) using (var computeClient = new ComputeManagementClient(credentials)) using (var storageClient = new StorageManagementClient(credentials)) { var targetSlot = VipSwap ? DeploymentSlot.Staging : DeploymentSlot.Production; var storageAccount = storageClient.CreateContainerIfNotExistsAsync( StorageAccountName, StorageContainer, BlobContainerPublicAccessType.Off, SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.List).Result; var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(StorageContainer); ProcessAsyncWork(ServiceNames.Select((t, i) => DeployCloudServiceAsync(computeClient, container, t, PackagePaths[i], ConfigurationPaths[i], DiagnosticsConfigurationPaths?[i], targetSlot)) .ToArray()); } WriteObject("Push-CloudServices completed!"); base.ProcessRecord(); }
/// <summary> /// Provisions all the storage containers in the <see cref="IEnumerable{T}"/> of <see cref="AzureStorageContainer"/>. /// </summary> /// <param name="containers">The list of <see cref="AzureStorageContainer"/> to provision.</param> /// <param name="client">The <see cref="StorageManagementClient"/> that is performing the operation.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static IEnumerable <Task> ProvisionAllAsync(this IEnumerable <AzureStorageContainer> containers, StorageManagementClient client) { Contract.Requires(containers != null); Contract.Requires(client != null); return(containers.Select(c => Task.Factory.StartNew(() => client.CreateContainerIfNotExistsAsync(c).Wait()))); }
/// <summary> /// Provisions all the storage containers in the <see cref="IEnumerable{T}"/> of <see cref="AzureStorageContainer"/>. /// </summary> /// <param name="containers">The list of <see cref="AzureStorageContainer"/> to provision.</param> /// <param name="client">The <see cref="StorageManagementClient"/> that is performing the operation.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static async Task ProvisionAllAsync(this IEnumerable <AzureStorageContainer> containers, StorageManagementClient client) { Contract.Requires(containers != null); Contract.Requires(client != null); var tasks = containers.Select( async c => { await client.CreateContainerIfNotExistsAsync(c); }); await Task.WhenAll(tasks); }
/// <summary> /// Checks for the existence of a specific storage container, if it doesn't exist it will create it. /// It also checks for a specific storage account that suits the system, if it doesn't exist in the subscription /// it will create it before attempting to create the container. /// </summary> /// <param name="client">The <see cref="StorageManagementClient"/> that is performing the operation.</param> /// <param name="model">The DevOpsFlex rich model object that contains everything there is to know about this database spec.</param> /// <returns>The async <see cref="Task"/> wrapper.</returns> public static async Task CreateContainerIfNotExistsAsync(this StorageManagementClient client, AzureStorageContainer model) { Contract.Requires(client != null); Contract.Requires(model != null); Contract.Requires(model.System != null); string accountName; lock (StorageAccountGate) { FlexStreams.BuildEventsObserver.OnNext(new CheckForParentResourceEvent(AzureResource.StorageAccount, AzureResource.StorageContainer, model.Name)); accountName = FlexConfiguration.StorageAccountChooser.Choose(client, model.System.StorageType.GetEnumDescription()).Result; StorageAccountGetResponse account = null; try { account = client.StorageAccounts.Get(accountName); } catch { // ignored } if (account == null) { accountName = (model.System.LogicalName + FlexDataConfiguration.StorageAccountString + FlexDataConfiguration.Branch).ToLower(); client.StorageAccounts.Create( new StorageAccountCreateParameters { Name = accountName, Location = model.System.Location.GetEnumDescription(), AccountType = model.System.StorageType.GetEnumDescription() }); FlexStreams.BuildEventsObserver.OnNext(new ProvisionEvent(AzureResource.StorageAccount, accountName)); } else { accountName = account.StorageAccount.Name; FlexStreams.BuildEventsObserver.OnNext(new FoundExistingEvent(AzureResource.StorageAccount, accountName)); } } await client.CreateContainerIfNotExistsAsync( accountName, FlexConfiguration.GetNaming <AzureStorageContainer>() .GetSlotName(model, FlexDataConfiguration.Branch, FlexDataConfiguration.Configuration), model.PublicAccess, model.Acl); }