github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/cloudconfig/providerinit/renderers/common.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 renderers 6 7 import ( 8 "encoding/base64" 9 "fmt" 10 11 "github.com/juju/juju/cloudconfig" 12 "github.com/juju/utils" 13 ) 14 15 // ToBase64 just transforms whatever userdata it gets to base64 format 16 func ToBase64(data []byte) []byte { 17 buf := make([]byte, base64.StdEncoding.EncodedLen(len(data))) 18 base64.StdEncoding.Encode(buf, data) 19 return buf 20 } 21 22 // WinEmbedInScript for now is used on windows and it returns a powershell script 23 // which has the userdata embedded as base64(gzip(userdata)) 24 func WinEmbedInScript(udata []byte) []byte { 25 encUserdata := ToBase64(utils.Gzip(udata)) 26 return []byte(fmt.Sprintf(cloudconfig.UserdataScript, encUserdata)) 27 } 28 29 // AddPowershellTags adds <powershell>...</powershell> to it's input 30 func AddPowershellTags(udata []byte) []byte { 31 return []byte(`<powershell>` + 32 string(udata) + 33 `</powershell>`) 34 }