github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/azure/userdata.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Copyright 2015 Cloudbase Solutions SRL 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package azure 6 7 import ( 8 "github.com/juju/errors" 9 "github.com/juju/utils" 10 "github.com/juju/utils/os" 11 12 "github.com/juju/juju/cloudconfig/providerinit/renderers" 13 ) 14 15 const ( 16 // The userdata on windows will arrive as CustomData.bin 17 // We need to execute that as a powershell script and then remove it 18 bootstrapUserdataScript = `#ps1_sysnative 19 mv C:\AzureData\CustomData.bin C:\AzureData\CustomData.ps1 20 & C:\AzureData\CustomData.ps1 21 rm C:\AzureData\CustomData.ps1 22 ` 23 bootstrapUserdataScriptFilename = "juju-userdata.ps1" 24 ) 25 26 type AzureRenderer struct{} 27 28 func (AzureRenderer) EncodeUserdata(udata []byte, vers os.OSType) ([]byte, error) { 29 switch vers { 30 case os.Ubuntu, os.CentOS: 31 return renderers.ToBase64(utils.Gzip(udata)), nil 32 case os.Windows: 33 return renderers.ToBase64(renderers.WinEmbedInScript(udata)), nil 34 default: 35 return nil, errors.Errorf("Cannot encode userdata for OS: %s", vers) 36 } 37 }