Exemple #1
0
        public static Role AddCustomScriptExtension(this Role role,
                                                    CloudStorageAccount storageAccount, string containerName, string filename, string arguments)
        {
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlockBlob  script     = blobClient.GetContainerReference(containerName).GetBlockBlobReference(filename);


            dynamic publicCfg = new ExpandoObject();

            publicCfg.fileUris = new string[]
            {
                string.Format("{0}{1}",
                              script.Uri.ToString(),
                              script.GetSharedAccessSignature(
                                  new SharedAccessBlobPolicy
                {
                    Permissions            = SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = DateTime.UtcNow.Add(TimeSpan.FromMinutes(55))
                }))
            };
            publicCfg.commandToExecute = string.Format(
                "powershell -ExecutionPolicy Unrestricted -file {0} {1}",
                script.Name, arguments);
            string customScriptExtensionPublicConfigParameter = JsonConvert.SerializeObject(publicCfg);


            dynamic privateCfg = new ExpandoObject();

            privateCfg.storageAccountName = storageAccount.Credentials.AccountName;
            privateCfg.storageAccountKey  = storageAccount.Credentials.ExportBase64EncodedKey();
            var customScriptExtensionPrivateConfigParameter = JsonConvert.SerializeObject(privateCfg);


            return(role.AddExtension(new ResourceExtensionReference
            {
                Publisher = "Microsoft.Compute",
                ReferenceName = "CustomScriptExtension",
                Name = "CustomScriptExtension",
                Version = "1.*",
                State = "Enable",
                ResourceExtensionParameterValues = new List <ResourceExtensionParameterValue>
                {
                    new ResourceExtensionParameterValue
                    {
                        Type = "Public",
                        Key = "CustomScriptExtensionPublicConfigParameter",
                        Value = customScriptExtensionPublicConfigParameter
                    },
                    new ResourceExtensionParameterValue
                    {
                        Type = "Private",
                        Key = "CustomScriptExtensionPrivateConfigParameter",
                        Value = customScriptExtensionPrivateConfigParameter
                    }
                }
            }));
        }
Exemple #2
0
 public static Role AddBGInfoExtension(this Role role)
 {
     return(role.AddExtension(new ResourceExtensionReference
     {
         State = "Enable",
         Name = "BGInfo",
         ReferenceName = "BGInfo",
         Publisher = "Microsoft.Compute",
         Version = "1.*"
     }));
 }