本文整理匯總了Golang中github.com/wallyworld/core/cloudinit.Config.RunCmds方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.RunCmds方法的具體用法?Golang Config.RunCmds怎麽用?Golang Config.RunCmds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wallyworld/core/cloudinit.Config
的用法示例。
在下文中一共展示了Config.RunCmds方法的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
}