本文整理汇总了Golang中github.com/juju/juju/cloudconfig/cloudinit.CloudConfig.RenderYAML方法的典型用法代码示例。如果您正苦于以下问题:Golang CloudConfig.RenderYAML方法的具体用法?Golang CloudConfig.RenderYAML怎么用?Golang CloudConfig.RenderYAML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/cloudconfig/cloudinit.CloudConfig
的用法示例。
在下文中一共展示了CloudConfig.RenderYAML方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ComposeUserData
// ComposeUserData fills out the provided cloudinit configuration structure
// so it is suitable for initialising a machine with the given configuration,
// and then renders it and encodes it using the supplied renderer.
// When calling ComposeUserData a encoding implementation must be chosen from
// the providerinit/encoders package according to the need of the provider.
//
// If the provided cloudcfg is nil, a new one will be created internally.
func ComposeUserData(icfg *instancecfg.InstanceConfig, cloudcfg cloudinit.CloudConfig, renderer renderers.ProviderRenderer) ([]byte, error) {
if cloudcfg == nil {
var err error
cloudcfg, err = cloudinit.New(icfg.Series)
if err != nil {
return nil, errors.Trace(err)
}
}
_, err := configureCloudinit(icfg, cloudcfg)
if err != nil {
return nil, errors.Trace(err)
}
operatingSystem, err := series.GetOSFromSeries(icfg.Series)
if err != nil {
return nil, errors.Trace(err)
}
// This might get replaced by a renderer.RenderUserdata which will either
// render it as YAML or Bash since some CentOS images might ship without cloudnit
udata, err := cloudcfg.RenderYAML()
if err != nil {
return nil, errors.Trace(err)
}
udata, err = renderer.EncodeUserdata(udata, operatingSystem)
if err != nil {
return nil, errors.Trace(err)
}
logger.Tracef("Generated cloud init:\n%s", string(udata))
return udata, err
}
示例2: TemplateUserData
// TemplateUserData returns a minimal user data necessary for the template.
// This should have the authorized keys, base packages, the cloud archive if
// necessary, initial apt proxy config, and it should do the apt-get
// update/upgrade initially.
func TemplateUserData(
series string,
authorizedKeys string,
aptProxy proxy.Settings,
aptMirror string,
enablePackageUpdates bool,
enableOSUpgrades bool,
networkConfig *container.NetworkConfig,
) ([]byte, error) {
var config cloudinit.CloudConfig
var err error
if networkConfig != nil {
config, err = newCloudInitConfigWithNetworks(series, networkConfig)
if err != nil {
return nil, errors.Trace(err)
}
} else {
config, err = cloudinit.New(series)
if err != nil {
return nil, errors.Trace(err)
}
}
cloudconfig.SetUbuntuUser(config, authorizedKeys)
config.AddScripts(
"set -xe", // ensure we run all the scripts or abort.
)
// For LTS series which need support for the cloud-tools archive,
// we need to enable apt-get update regardless of the environ
// setting, otherwise provisioning will fail.
if series == "precise" && !enablePackageUpdates {
logger.Warningf("series %q requires cloud-tools archive: enabling updates", series)
enablePackageUpdates = true
}
if enablePackageUpdates && config.RequiresCloudArchiveCloudTools() {
config.AddCloudArchiveCloudTools()
}
config.AddPackageCommands(aptProxy, aptMirror, enablePackageUpdates, enableOSUpgrades)
initSystem, err := service.VersionInitSystem(series)
if err != nil {
return nil, errors.Trace(err)
}
cmds, err := shutdownInitCommands(initSystem, series)
if err != nil {
return nil, errors.Trace(err)
}
config.AddScripts(strings.Join(cmds, "\n"))
data, err := config.RenderYAML()
if err != nil {
return nil, err
}
return data, nil
}
示例3: assertUserData
func assertUserData(c *gc.C, cloudConf cloudinit.CloudConfig, expected string) {
data, err := cloudConf.RenderYAML()
c.Assert(err, jc.ErrorIsNil)
c.Assert(string(data), gc.Equals, expected)
// Make sure it's valid YAML as well.
out := make(map[string]interface{})
err = yaml.Unmarshal(data, &out)
c.Assert(err, jc.ErrorIsNil)
if len(cloudConf.BootCmds()) > 0 {
outcmds := out["bootcmd"].([]interface{})
confcmds := cloudConf.BootCmds()
c.Assert(len(outcmds), gc.Equals, len(confcmds))
for i, _ := range outcmds {
c.Assert(outcmds[i].(string), gc.Equals, confcmds[i])
}
} else {
c.Assert(out["bootcmd"], gc.IsNil)
}
}
示例4: ComposeUserData
// ComposeUserData fills out the provided cloudinit configuration structure
// so it is suitable for initialising a machine with the given configuration,
// and then renders it and returns it as a binary (gzipped) blob of user data.
//
// If the provided cloudcfg is nil, a new one will be created internally.
func ComposeUserData(icfg *instancecfg.InstanceConfig, cloudcfg cloudinit.CloudConfig) ([]byte, error) {
if cloudcfg == nil {
var err error
cloudcfg, err = cloudinit.New(icfg.Series)
if err != nil {
return nil, err
}
}
_, err := configureCloudinit(icfg, cloudcfg)
if err != nil {
return nil, err
}
data, err := cloudcfg.RenderYAML()
logger.Tracef("Generated cloud init:\n%s", string(data))
if err != nil {
return nil, err
}
return utils.Gzip(data), nil
}