Skip to content

Snesha/azure-linux-extensions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux extensions for Microsoft Azure IaaS

This project provides the source code of Linux extensions for Microsoft Azure IaaS

Extension List

Custom Script Extension

Allow the owner of the Azure VM to run script stored in Azure storage during or after VM provisioning

Features

  • It can be installed using Azure PowerShell Cmdlets, xPlat scripts or Azure Management Portal
  • It supports major Linux and FreeBSD distro
  • Windows style newline in Shell and Python scripts is converted automatically
  • BOM in Shell and Python scripts is removed automatically
  • The scripts can be located on Azure Storage or external public storage (e.g. Github)
  • The status of the extension is reported back to Azure so that user can see the status on Azure Portal
  • Support inline command
  • All the execution output and error of the scripts are logged into the download directory of the scripts, and the tail of the output is logged into the log directory specified in HandlerEnvironment.json and reported back to Azure

Requirement

Python 2.7+

Usage

PowerShell Sample

$ExtensionName = 'CustomScriptForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version = '1.3'

$VmName = '<vm_name>'
Write-Host ('Retrieving the VM ' + $VmName + '.....................')
$vm = Get-AzureVM -ServiceName $VmName -Name $VmName

$PublicConf = '{
    "fileUris":["<url>"],
    "commandToExecute": "<command>"
}'
$PrivateConf = '{
    "storageAccountName": "<storage_account_name>",
    "storageAccountKey":"<storage_account_key>"
}'

Write-Host ('Deploying the extension ' + $ExtensionName + ' with Version ' + $Version + ' on ' + $VmName + '.....................')
Set-AzureVMExtension -ExtensionName $ExtensionName -VM  $vm -Publisher $Publisher -Version $Version -PrivateConfiguration $PrivateConf -PublicConfiguration $PublicConf | Update-AzureVM

Xplat Sample

azure vm extension set <vm_name> CustomScriptForLinux Microsoft.OSTCExtensions 1.3 -i '{"fileUris":["<url>"], "commandToExecute": "<command>" }' -t '{"storageAccountName":"<storage_account_name>","storageAccountKey":"<storage_account_key>"}'

Limitation

  • To run a script, you need to specify interpreter in "commandToExecute" field, or you can use "./myscript.sh" if Shebang("#!") is specified in the script.
-PublicConfiguration '{"fileUris":["<url>"], "commandToExecute": "sh myscript.sh"}'
-PublicConfiguration '{"fileUris":["<url>"], "commandToExecute": "python myscript.py"}'
  • Here is some examples to run inline commands. You need to specify "python -c" if they are Python commands.
-PublicConfiguration '{"commandToExecute": "echo Hello"}'
-PublicConfiguration '{"commandToExecute": "python -c \"print 1.3\""}'
  • If you need to run the same script repeatly, you have to add a timestamp in the "-PublicConfiguration" parameter.
$TimeStamp = (Get-Date).Ticks
-PublicConfiguration '{"fileUris":["<url>"], "commandToExecute": "<command>", "timestamp": $TimeStamp}'

More Information

http://azure.microsoft.com/blog/2014/08/20/automate-linux-vm-customization-tasks-using-customscript-extension/

VM Access Extension

Provide several ways to allow owner of the VM to get the SSH access back

Features

  • it can be installed through Azure RESTFUL API for extension
  • it supports major Linux and FreeBSD distro
  • it can reset the password of the original sudo user
  • it can create a new sudo user with the password specified
  • it can set the public host key with the key given or it can reset the public host key provided during VM provisioning if host key not provided
  • it can open the SSH port(22) and restore the sshd_config if reset_ssh is set to True
  • status of the extension is reported back to Azure so that you can see the status on Azure Portal

Usage

PowerShell script to deploy the extension on VM

$VmName = '<vm_name>'
Write-Host ('Retrieving the VM ' + $VmName + '.....................')
$vm = get-azurevm $VmName
$UserName = "<user_name>"
$Password = "<password>"
$ExtensionName = '<extension_name>'
$Publisher = '<publisher_name>'
$Version =  '<version>'
$cert = Get-Content "<cert_path>"
$PrivateConfig = '{"username":"' + $UserName + '", "password": "' +  $Password + '", "ssh_key":"' + $cert + '","reset_ssh":"True"}'	
Write-Host ('Deploying the extension ' + $ExtensionName + ' with Version ' + $Version + ' on ' + $VmName + '.....................')
Set-AzureVMExtension -ExtensionName $ExtensionName -VM  $vm -Publisher $Publisher -Version $Version -PrivateConfiguration $PrivateConfig -PublicConfiguration $PublicConfig | Update-AzureVM	

OS Patching Extension

Allow the owner of the Azure VM to configure the Linux VM patching schedule cycle. And the actual patching operation is automated based on the pre-configured schedule.

Features

  • it can be installed through Azure RESTFUL API for extension
  • it supports major Linux
  • it can be configured by the user
  • it can patch the os automatically as a scheduled task
  • it can patch the os automatically as a one-off
  • status of the extension is reported back to Azure so that you can see the status on Azure Portal
  • it can be stopped before the actual patching operation
  • the status of VM can be checked by user-defined scripts, which can be stored locally, in github or Azure Storage

Prepare

Add-Add-AzureAccount Select-AzureSubscription -SubscriptionName '<your_subscription_name>'

Usage

PowerShell script to deploy the extension on VM

$ExtensionName = 'OSPatchingForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version =  '2.0'

$VmName = '<vm_name>'
Write-Host ('Retrieving the VM ' + $VmName + '.....................')
$vm = get-azurevm $VmName

$idleTestScriptUri = '<path_to_idletestscript>'
$healthyTestScriptUri = '<path_to_healthytestscript>'

$PublicConfig = ConvertTo-Json -InputObject @{
    "disabled" = $false;
    "stop" = $true|$false;
    "rebootAfterPatch" = "RebootIfNeed|Required|NotRequired|Auto";
    "category" = "Important|ImportantAndRecommended";
    "installDuration" = "<hr:min>";
    "oneoff" = $true|$false;
    "intervalOfWeeks" = "<number>";
    "dayOfWeek" = "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Everyday";
    "startTime" = "<hr:min>";
    "vmStatusTest" = (@{
        "local" = $false;
        "idleTestScript" = $idleTestScriptUri;
        "healthyTestScript" = $healthyTestScriptUri
    })
}

# Optional
# If you use azure storage, you have to offer the key
$PrivateConfig = ConvertTo-Json -InputObject @{
    "storageAccountName" = "<storage_account_name>";
    "storageAccountKey" = "<storage_account_key>"
}

Write-Host ('Deploying the extension ' + $ExtensionName + ' with Version ' + $Version + ' on ' + $VmName + '.....................')
Set-AzureVMExtension -ExtensionName $ExtensionName -VM $vm -Publisher $Publisher -Version $Version -PrivateConfiguration $PrivateConfig -PublicConfiguration $PublicConfig | Update-AzureVM

Limitation

  • If you need to run the same script repeatly, you have to add a timestamp in the "-PublicConfiguration" parameter, for example:
$TimeStamp = (Get-Date).Ticks
$PublicConfig = ConvertTo-Json -InputObject @{
    <Other-Configuration>;
    "timestamp" = $TimeStamp
}

Test Handler Extension

This extension is an extension example

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 96.5%
  • C 1.7%
  • Other 1.8%