2017-02-15 2 views
0

Il existe un commandlet powershell pour les extensions de script personnalisées qui semble prendre en charge de nombreuses options de paramètres, mais l'API client .net pour les extensions VM n'a pas un ensemble de paramètres fortement typé à configurer et nécessite l'utilisation de publicSettings. privateSettings choses ... quelle est la bonne façon de le faire avec les API .net?Comment créer une extension CustomScript Azure avec le SDK .net?

Répondre

0

Utilisation du nouveau SDK couramment c'est ma meilleure tentative à ce jour ...:

var blobClient = new CloudBlobClient(
    new Uri(tenantStorageAccount.EndPoints.Primary.Blob), 
    new StorageCredentials(tenantStorageAccount.Name, tenantStorageKeys.First().Value)); 

var scriptText = @"Write-Host ""Success!"" 

« ;

var bootContainer = blobClient.GetContainerReference("boot"); 
await bootContainer.CreateIfNotExistsAsync(); 
var bootstrapBlob = bootContainer.GetBlockBlobReference("bootstrap.ps1"); 
await bootstrapBlob.UploadTextAsync(scriptText); 

var sasToken = bootstrapBlob.GetSharedAccessSignature(
    new SharedAccessBlobPolicy 
    { 
     SharedAccessExpiryTime = DateTime.UtcNow.AddYears(1), 
     Permissions = SharedAccessBlobPermissions.Read 
    }); 

string bootstrapBlobSasUri = bootstrapBlob.Uri + sasToken; 

var extensionTasks = new List<Task<IVirtualMachine>>(); 
await vms.ForEachAsync(async vm => 
{ 
    await vm.Update().DefineNewExtension("bootstrapper") 
     .WithPublisher("Microsoft.Compute") 
     .WithType("CustomScriptExtension") 
     .WithVersion("1.8") 
     .WithPublicSetting("fileUris", new string[] { bootstrapBlobSasUri }) 
     .WithProtectedSetting("storageAccountName", tenantStorageAccount.Name) 
     .WithProtectedSetting("storageAccountKey", tenantStorageKeys[0]) 
     .WithProtectedSetting("commandToExecute", "powershell -ExecutionPolicy Unrestricted -File bootstrap.ps1") 
     .Attach().ApplyAsync(); 
});