/// <summary>
 /// Create the configuration identified by configuration name.  (see
 /// http://aka.ms/azureautomationsdk/configurationoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IDscConfigurationOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create or update parameters for configuration.
 /// </param>
 /// <returns>
 /// The response model for the configuration create response.
 /// </returns>
 public static Task <DscConfigurationCreateOrUpdateResponse> CreateOrUpdateAsync(this IDscConfigurationOperations operations, string resourceGroupName, string automationAccount, DscConfigurationCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None));
 }
 /// <summary>
 /// Create the configuration identified by configuration name.  (see
 /// http://aka.ms/azureautomationsdk/configurationoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IDscConfigurationOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create or update parameters for configuration.
 /// </param>
 /// <returns>
 /// The response model for the configuration create response.
 /// </returns>
 public static DscConfigurationCreateOrUpdateResponse CreateOrUpdate(this IDscConfigurationOperations operations, string resourceGroupName, string automationAccount, DscConfigurationCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDscConfigurationOperations)s).CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Create the configuration identified by configuration name.
 /// <see href="http://aka.ms/azureautomationsdk/configurationoperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='configurationName'>
 /// The create or update parameters for configuration.
 /// </param>
 /// <param name='parameters'>
 /// The create or update parameters for configuration.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DscConfiguration> CreateOrUpdateAsync(this IDscConfigurationOperations operations, string resourceGroupName, string automationAccountName, string configurationName, DscConfigurationCreateOrUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, automationAccountName, configurationName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
예제 #4
0
        public static async Task UploadConfigurationAsDraft(AutomationDSC configuration, AutomationManagementClient automationManagementClient, string resourceGroupName, AutomationAccount account)
        {
            string fileContent = null;

            try
            {
                if (File.Exists(Path.GetFullPath(configuration.localFileInfo.FullName)))
                {
                    fileContent = System.IO.File.ReadAllText(configuration.localFileInfo.FullName);
                }
            }
            catch (Exception)
            {
                // exception in accessing the file path
                throw new FileNotFoundException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Resources.LocalConfigurationFileNotFound));
            }

            DscConfigurationCreateOrUpdateProperties draftProperties;

            draftProperties = new DscConfigurationCreateOrUpdateProperties();
            // Get current properties if is not a new configuration and set these on the draft also so they are preserved.
            DscConfigurationGetResponse response = null;
            CancellationTokenSource     cts      = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            if (configuration.SyncStatus != AutomationAuthoringItem.Constants.SyncStatus.LocalOnly)
            {
                response = await automationManagementClient.Configurations.GetAsync(resourceGroupName, account.Name, configuration.Name, cts.Token);
            }

            // Create properties
            DscConfigurationCreateOrUpdateParameters draftParams = new DscConfigurationCreateOrUpdateParameters(draftProperties);

            draftParams.Name     = configuration.Name;
            draftParams.Location = account.Location;
            draftParams.Properties.Description = configuration.Description;

            // If this is not a new configuration, set the existing properties of the configuration
            if (response != null)
            {
                draftParams.Tags     = response.Configuration.Tags;
                draftParams.Location = response.Configuration.Location;
                draftParams.Properties.LogVerbose  = response.Configuration.Properties.LogVerbose;
                draftParams.Properties.Description = response.Configuration.Properties.Description;
            }
            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            /* Update the configuration content from .ps1 file */
            DscConfigurationCreateOrUpdateParameters draftUpdateParams = new DscConfigurationCreateOrUpdateParameters()
            {
                Name       = configuration.Name,
                Location   = draftParams.Location,
                Tags       = draftParams.Tags,
                Properties = new DscConfigurationCreateOrUpdateProperties()
                {
                    Description = draftParams.Properties.Description,
                    LogVerbose  = draftParams.Properties.LogVerbose,
                    Source      = new Microsoft.Azure.Management.Automation.Models.ContentSource()
                    {
                        ContentType = ContentSourceType.EmbeddedContent,
                        Value       = fileContent
                    }
                }
            };

            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            await automationManagementClient.Configurations.CreateOrUpdateAsync(resourceGroupName, account.Name, draftUpdateParams, cts.Token);

            /* Ensure the correct sync status is detected */
            DscConfiguration draft = await GetConfigurationDraft(configuration.Name, automationManagementClient, resourceGroupName, account.Name);

            configuration.localFileInfo.LastWriteTime = draft.Properties.LastModifiedTime.LocalDateTime;
            configuration.LastModifiedLocal           = draft.Properties.LastModifiedTime.LocalDateTime;
            configuration.LastModifiedCloud           = draft.Properties.LastModifiedTime.LocalDateTime;
        }
 /// <summary>
 /// Create the configuration identified by configuration name.
 /// <see href="http://aka.ms/azureautomationsdk/configurationoperations" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure Resource group.
 /// </param>
 /// <param name='automationAccountName'>
 /// The name of the automation account.
 /// </param>
 /// <param name='configurationName'>
 /// The create or update parameters for configuration.
 /// </param>
 /// <param name='parameters'>
 /// The create or update parameters for configuration.
 /// </param>
 public static DscConfiguration CreateOrUpdate(this IDscConfigurationOperations operations, string resourceGroupName, string automationAccountName, string configurationName, DscConfigurationCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, automationAccountName, configurationName, parameters).GetAwaiter().GetResult());
 }