Example #1
0
func (utilsSuite) TestCompression(c *C) {
	cdata := utils.Gzip(data)
	c.Assert(len(cdata) < len(data), Equals, true)
	data1, err := utils.Gunzip(cdata)
	c.Assert(err, IsNil)
	c.Assert(data1, DeepEquals, data)

	data1, err = utils.Gunzip(compressedData)
	c.Assert(err, IsNil)
	c.Assert(data1, DeepEquals, data)
}
Example #2
0
// ComposeUserData puts together a binary (gzipped) blob of user data.
// The additionalScripts are additional command lines that you need cloudinit
// to run on the instance.  Use with care.
func ComposeUserData(cfg *cloudinit.MachineConfig, additionalScripts ...string) ([]byte, error) {
	cloudcfg := coreCloudinit.New()
	for _, script := range additionalScripts {
		cloudcfg.AddRunCmd(script)
	}
	cloudcfg, err := cloudinit.Configure(cfg, cloudcfg)
	if err != nil {
		return nil, err
	}
	data, err := cloudcfg.Render()
	if err != nil {
		return nil, err
	}
	return utils.Gzip(data), nil
}