本文整理匯總了Golang中github.com/juju/juju/cloudconfig/cloudinit.CloudConfig.AddScripts方法的典型用法代碼示例。如果您正苦於以下問題:Golang CloudConfig.AddScripts方法的具體用法?Golang CloudConfig.AddScripts怎麽用?Golang CloudConfig.AddScripts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/cloudconfig/cloudinit.CloudConfig
的用法示例。
在下文中一共展示了CloudConfig.AddScripts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}