本文整理汇总了Golang中github.com/wallyworld/core/cloudinit.Config.BootCmds方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.BootCmds方法的具体用法?Golang Config.BootCmds怎么用?Golang Config.BootCmds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/cloudinit.Config
的用法示例。
在下文中一共展示了Config.BootCmds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ConfigureScript
// ConfigureScript generates the bash script that applies
// the specified cloud-config.
func ConfigureScript(cloudcfg *cloudinit.Config) (string, error) {
// TODO(axw): 2013-08-23 bug 1215777
// Carry out configuration for ssh-keys-per-user,
// machine-updates-authkeys, using cloud-init config.
//
// We should work with smoser to get a supported
// command in (or next to) cloud-init for manually
// invoking cloud-config. This would address the
// above comment by removing the need to generate a
// script "by hand".
// Bootcmds must be run before anything else,
// as they may affect package installation.
bootcmds, err := cmdlist(cloudcfg.BootCmds())
if err != nil {
return "", err
}
// Add package sources and packages.
pkgcmds, err := addPackageCommands(cloudcfg)
if err != nil {
return "", err
}
// Runcmds come last.
runcmds, err := cmdlist(cloudcfg.RunCmds())
if err != nil {
return "", err
}
// We prepend "set -xe". This is already in runcmds,
// but added here to avoid relying on that to be
// invariant.
script := []string{"#!/bin/bash", "set -e"}
// We must initialise progress reporting before entering
// the subshell and redirecting stderr.
script = append(script, cloudinit.InitProgressCmd())
stdout, stderr := cloudcfg.Output(cloudinit.OutAll)
script = append(script, "(")
if stderr != "" {
script = append(script, "(")
}
script = append(script, bootcmds...)
script = append(script, pkgcmds...)
script = append(script, runcmds...)
if stderr != "" {
script = append(script, ") "+stdout)
script = append(script, ") "+stderr)
} else {
script = append(script, ") "+stdout+" 2>&1")
}
return strings.Join(script, "\n"), nil
}