github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/gce/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 gce 6 7 import ( 8 "github.com/juju/errors" 9 "github.com/juju/utils" 10 jujuos "github.com/juju/utils/os" 11 12 "github.com/juju/juju/cloudconfig/cloudinit" 13 "github.com/juju/juju/cloudconfig/providerinit/renderers" 14 ) 15 16 type GCERenderer struct{} 17 18 func (GCERenderer) Render(cfg cloudinit.CloudConfig, os jujuos.OSType) ([]byte, error) { 19 switch os { 20 case jujuos.Ubuntu, jujuos.CentOS: 21 return renderers.RenderYAML(cfg, utils.Gzip, renderers.ToBase64) 22 case jujuos.Windows: 23 return renderers.RenderYAML(cfg, renderers.WinEmbedInScript) 24 default: 25 return nil, errors.Errorf("Cannot encode userdata for OS: %s", os.String()) 26 } 27 } 28 29 // The hostname on windows GCE instances is taken from 30 // the instance id. This is bad because windows only 31 // uses the first 15 characters in certain instances, 32 // which are not unique for the GCE provider. 33 // As a result, we have to send this small script as 34 // a sysprep script, to change the hostname inside 35 // the sysprep step, simplyfing the userdata and 36 // saving a reboot 37 var winSetHostnameScript = ` 38 Rename-Computer %q 39 `