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