本文整理汇总了Golang中github.com/juju/juju/cloudinit.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
enablePackageUpdates bool,
enableOSUpgrades bool,
) ([]byte, error) {
config := corecloudinit.New()
config.AddScripts(
"set -xe", // ensure we run all the scripts or abort.
)
config.AddSSHAuthorizedKeys(authorizedKeys)
if enablePackageUpdates {
cloudinit.MaybeAddCloudArchiveCloudTools(config, series)
}
cloudinit.AddAptCommands(aptProxy, config, enablePackageUpdates, enableOSUpgrades)
config.AddScripts(
fmt.Sprintf(
"printf '%%s\n' %s > %s",
utils.ShQuote(templateShutdownUpstartScript),
templateShutdownUpstartFilename,
))
renderer, err := corecloudinit.NewRenderer(series)
if err != nil {
return nil, err
}
data, err := renderer.Render(config)
if err != nil {
return nil, err
}
return data, nil
}
开发者ID:kapilt,项目名称:juju,代码行数:37,代码来源:clonetemplate.go
示例2: TestWindowsCloudInit
func (*cloudinitSuite) TestWindowsCloudInit(c *gc.C) {
for i, test := range windowsCloudinitTests {
c.Logf("test %d", i)
dataDir, err := paths.DataDir(test.cfg.Series)
c.Assert(err, gc.IsNil)
logDir, err := paths.LogDir(test.cfg.Series)
c.Assert(err, gc.IsNil)
test.cfg.DataDir = dataDir
test.cfg.LogDir = path.Join(logDir, "juju")
ci := coreCloudinit.New()
udata, err := cloudinit.NewUserdataConfig(&test.cfg, ci)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Assert(err, gc.IsNil)
c.Check(ci, gc.NotNil)
data, err := udata.Render()
c.Assert(err, gc.IsNil)
stringData := strings.Replace(string(data), "\r\n", "\n", -1)
stringData = strings.Replace(stringData, "\t", " ", -1)
stringData = strings.TrimSpace(stringData)
compareString := strings.Replace(string(test.expectScripts), "\r\n", "\n", -1)
compareString = strings.Replace(compareString, "\t", " ", -1)
compareString = strings.TrimSpace(compareString)
c.Assert(stringData, gc.Equals, compareString)
}
}
开发者ID:kapilt,项目名称:juju,代码行数:34,代码来源:cloudinit_test.go
示例3: cloudInitUserData
func cloudInitUserData(machineConfig *cloudinit.MachineConfig) ([]byte, error) {
cloudConfig := coreCloudinit.New()
udata, err := cloudinit.NewUserdataConfig(machineConfig, cloudConfig)
if err != nil {
return nil, err
}
err = udata.Configure()
if err != nil {
return nil, err
}
// Run ifconfig to get the addresses of the internal container at least
// logged in the host.
cloudConfig.AddRunCmd("ifconfig")
renderer, err := coreCloudinit.NewRenderer(machineConfig.Series)
if err != nil {
return nil, err
}
data, err := renderer.Render(cloudConfig)
if err != nil {
return nil, err
}
return data, nil
}
开发者ID:kapilt,项目名称:juju,代码行数:25,代码来源:userdata.go
示例4: getCloudConfig
func (s *configureSuite) getCloudConfig(c *gc.C, stateServer bool, vers version.Binary) *cloudinit.Config {
var mcfg *envcloudinit.MachineConfig
var err error
if stateServer {
mcfg, err = environs.NewBootstrapMachineConfig(constraints.Value{}, vers.Series)
c.Assert(err, gc.IsNil)
mcfg.InstanceId = "instance-id"
mcfg.Jobs = []params.MachineJob{params.JobManageEnviron, params.JobHostUnits}
} else {
mcfg, err = environs.NewMachineConfig("0", "ya", imagemetadata.ReleasedStream, vers.Series, nil, nil, nil)
c.Assert(err, gc.IsNil)
mcfg.Jobs = []params.MachineJob{params.JobHostUnits}
}
mcfg.Tools = &tools.Tools{
Version: vers,
URL: "http://testing.invalid/tools.tar.gz",
}
environConfig := testConfig(c, stateServer, vers)
err = environs.FinishMachineConfig(mcfg, environConfig)
c.Assert(err, gc.IsNil)
cloudcfg := cloudinit.New()
udata, err := envcloudinit.NewUserdataConfig(mcfg, cloudcfg)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Assert(err, gc.IsNil)
return cloudcfg
}
开发者ID:kapilt,项目名称:juju,代码行数:27,代码来源:configure_test.go
示例5: ConfigureMachine
func ConfigureMachine(ctx environs.BootstrapContext, client ssh.Client, host string, machineConfig *cloudinit.MachineConfig) error {
// Bootstrap is synchronous, and will spawn a subprocess
// to complete the procedure. If the user hits Ctrl-C,
// SIGINT is sent to the foreground process attached to
// the terminal, which will be the ssh subprocess at this
// point. For that reason, we do not call StopInterruptNotify
// until this function completes.
cloudcfg := coreCloudinit.New()
cloudcfg.SetAptUpdate(machineConfig.EnableOSRefreshUpdate)
cloudcfg.SetAptUpgrade(machineConfig.EnableOSUpgrade)
udata, err := cloudinit.NewUserdataConfig(machineConfig, cloudcfg)
if err != nil {
return err
}
if err := udata.ConfigureJuju(); err != nil {
return err
}
configScript, err := sshinit.ConfigureScript(cloudcfg)
if err != nil {
return err
}
script := shell.DumpFileOnErrorScript(machineConfig.CloudInitOutputLog) + configScript
return sshinit.RunConfigureScript(script, sshinit.ConfigureParams{
Host: "[email protected]" + host,
Client: client,
Config: cloudcfg,
ProgressWriter: ctx.GetStderr(),
})
}
开发者ID:kapilt,项目名称:juju,代码行数:30,代码来源:bootstrap.go
示例6: ProvisioningScript
// ProvisioningScript generates a bash script that can be
// executed on a remote host to carry out the cloud-init
// configuration.
func ProvisioningScript(mcfg *cloudinit.MachineConfig) (string, error) {
cloudcfg := coreCloudinit.New()
cloudcfg.SetAptUpdate(mcfg.EnableOSRefreshUpdate)
cloudcfg.SetAptUpgrade(mcfg.EnableOSUpgrade)
udata, err := cloudinit.NewUserdataConfig(mcfg, cloudcfg)
if err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
if err := udata.ConfigureJuju(); err != nil {
return "", errors.Annotate(err, "error generating cloud-config")
}
configScript, err := sshinit.ConfigureScript(cloudcfg)
if err != nil {
return "", errors.Annotate(err, "error converting cloud-config to script")
}
var buf bytes.Buffer
// Always remove the cloud-init-output.log file first, if it exists.
fmt.Fprintf(&buf, "rm -f %s\n", utils.ShQuote(mcfg.CloudInitOutputLog))
// If something goes wrong, dump cloud-init-output.log to stderr.
buf.WriteString(shell.DumpFileOnErrorScript(mcfg.CloudInitOutputLog))
buf.WriteString(configScript)
return buf.String(), nil
}
开发者ID:kapilt,项目名称:juju,代码行数:30,代码来源:provisioner.go
示例7: TestSetOutput
func (S) TestSetOutput(c *gc.C) {
type test struct {
kind cloudinit.OutputKind
stdout string
stderr string
}
tests := []test{{
cloudinit.OutAll, "a", "",
}, {
cloudinit.OutAll, "", "b",
}, {
cloudinit.OutInit, "a", "b",
}, {
cloudinit.OutAll, "a", "b",
}, {
cloudinit.OutAll, "", "",
}}
cfg := cloudinit.New()
stdout, stderr := cfg.Output(cloudinit.OutAll)
c.Assert(stdout, gc.Equals, "")
c.Assert(stderr, gc.Equals, "")
for i, t := range tests {
c.Logf("test %d: %+v", i, t)
cfg.SetOutput(t.kind, t.stdout, t.stderr)
stdout, stderr = cfg.Output(t.kind)
c.Assert(stdout, gc.Equals, t.stdout)
c.Assert(stderr, gc.Equals, t.stderr)
}
}
开发者ID:rogpeppe,项目名称:juju,代码行数:30,代码来源:cloudinit_test.go
示例8: TestProvisioningScript
func (s *provisionerSuite) TestProvisioningScript(c *gc.C) {
const series = "precise"
const arch = "amd64"
defer fakeSSH{
Series: series,
Arch: arch,
InitUbuntuUser: true,
}.install(c).Restore()
machineId, err := manual.ProvisionMachine(s.getArgs(c))
c.Assert(err, gc.IsNil)
mcfg, err := client.MachineConfig(s.State, machineId, agent.BootstrapNonce, "/var/lib/juju")
c.Assert(err, gc.IsNil)
script, err := manual.ProvisioningScript(mcfg)
c.Assert(err, gc.IsNil)
cloudcfg := coreCloudinit.New()
err = cloudinit.ConfigureJuju(mcfg, cloudcfg)
c.Assert(err, gc.IsNil)
cloudcfg.SetAptUpgrade(false)
sshinitScript, err := sshinit.ConfigureScript(cloudcfg)
c.Assert(err, gc.IsNil)
removeLogFile := "rm -f '/var/log/cloud-init-output.log'\n"
expectedScript := removeLogFile + shell.DumpFileOnErrorScript("/var/log/cloud-init-output.log") + sshinitScript
c.Assert(script, gc.Equals, expectedScript)
}
开发者ID:jiasir,项目名称:juju,代码行数:27,代码来源:provisioner_test.go
示例9: TestAptGetWrapper
func (s *configureSuite) TestAptGetWrapper(c *gc.C) {
aptgetRegexp := "(.|\n)* $(which eatmydata || true) " + regexp.QuoteMeta(sshinit.Aptget)
cfg := cloudinit.New()
cfg.SetAptUpdate(true)
cfg.SetAptGetWrapper("eatmydata")
assertScriptMatches(c, cfg, aptgetRegexp, false)
}
开发者ID:kapilt,项目名称:juju,代码行数:7,代码来源:configure_test.go
示例10: TestCloudInit
// TestCloudInit checks that the output from the various tests
// in cloudinitTests is well formed.
func (*cloudinitSuite) TestCloudInit(c *gc.C) {
for i, test := range cloudinitTests {
c.Logf("test %d", i)
if test.setEnvConfig {
test.cfg.Config = minimalConfig(c)
}
ci := coreCloudinit.New()
udata, err := cloudinit.NewUserdataConfig(&test.cfg, ci)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Assert(err, gc.IsNil)
c.Check(ci, gc.NotNil)
// render the cloudinit config to bytes, and then
// back to a map so we can introspect it without
// worrying about internal details of the cloudinit
// package.
data, err := udata.Render()
c.Assert(err, gc.IsNil)
configKeyValues := make(map[interface{}]interface{})
err = goyaml.Unmarshal(data, &configKeyValues)
c.Assert(err, gc.IsNil)
c.Check(configKeyValues["apt_get_wrapper"], gc.DeepEquals, map[interface{}]interface{}{
"command": "eatmydata",
"enabled": "auto",
})
if test.cfg.EnableOSRefreshUpdate {
c.Check(configKeyValues["apt_update"], gc.Equals, true)
} else {
c.Check(configKeyValues["apt_update"], gc.IsNil)
}
if test.cfg.EnableOSUpgrade {
c.Check(configKeyValues["apt_upgrade"], gc.Equals, true)
} else {
c.Check(configKeyValues["apt_upgrade"], gc.IsNil)
}
scripts := getScripts(configKeyValues)
assertScriptMatch(c, scripts, test.expectScripts, !test.inexactMatch)
if test.cfg.Config != nil {
checkEnvConfig(c, test.cfg.Config, configKeyValues, scripts)
}
checkPackage(c, configKeyValues, "curl", test.cfg.EnableOSRefreshUpdate)
tag := names.NewMachineTag(test.cfg.MachineId).String()
acfg := getAgentConfig(c, tag, scripts)
c.Assert(acfg, jc.Contains, "AGENT_SERVICE_NAME: jujud-"+tag)
c.Assert(acfg, jc.Contains, "upgradedToVersion: 1.2.3\n")
source := "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/cloud-tools main"
needCloudArchive := test.cfg.Series == "precise"
checkAptSource(c, configKeyValues, source, cloudinit.CanonicalCloudArchiveSigningKey, needCloudArchive)
}
}
开发者ID:kapilt,项目名称:juju,代码行数:60,代码来源:cloudinit_test.go
示例11: TestAptUpgrade
func (s *configureSuite) TestAptUpgrade(c *gc.C) {
// apt-get upgrade is only run if AptUpgrade is set.
aptGetUpgradePattern := aptgetRegexp + "upgrade(.|\n)*"
cfg := cloudinit.New()
cfg.SetAptUpdate(true)
cfg.AddAptSource("source", "key", nil)
assertScriptMatches(c, cfg, aptGetUpgradePattern, false)
cfg.SetAptUpgrade(true)
assertScriptMatches(c, cfg, aptGetUpgradePattern, true)
}
开发者ID:kapilt,项目名称:juju,代码行数:10,代码来源:configure_test.go
示例12: TestOutput
func (S) TestOutput(c *gc.C) {
for _, t := range ctests {
cfg := cloudinit.New()
t.setOption(cfg)
data, err := cfg.Render()
c.Assert(err, gc.IsNil)
c.Assert(data, gc.NotNil)
c.Assert(string(data), gc.Equals, header+t.expect, gc.Commentf("test %q output differs", t.name))
}
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:cloudinit_test.go
示例13: TestRunCmds
func (S) TestRunCmds(c *gc.C) {
cfg := cloudinit.New()
c.Assert(cfg.RunCmds(), gc.HasLen, 0)
cfg.AddScripts("a", "b")
cfg.AddRunCmdArgs("c", "d")
cfg.AddRunCmd("e")
c.Assert(cfg.RunCmds(), gc.DeepEquals, []interface{}{
"a", "b", []string{"c", "d"}, "e",
})
}
开发者ID:rogpeppe,项目名称:juju,代码行数:10,代码来源:cloudinit_test.go
示例14: TestPackages
func (S) TestPackages(c *gc.C) {
cfg := cloudinit.New()
c.Assert(cfg.Packages(), gc.HasLen, 0)
cfg.AddPackage("a b c")
cfg.AddPackage("d!")
expectedPackages := []string{"a b c", "d!"}
c.Assert(cfg.Packages(), gc.DeepEquals, expectedPackages)
cfg.AddPackageFromTargetRelease("package", "series")
expectedPackages = append(expectedPackages, "--target-release 'series' 'package'")
c.Assert(cfg.Packages(), gc.DeepEquals, expectedPackages)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:11,代码来源:cloudinit_test.go
示例15: ExampleConfig
//#cloud-config
//packages:
//- juju
//- ubuntu
func ExampleConfig() {
cfg := cloudinit.New()
cfg.AddPackage("juju")
cfg.AddPackage("ubuntu")
data, err := cfg.Render()
if err != nil {
fmt.Printf("render error: %v", err)
return
}
fmt.Printf("%s", data)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:15,代码来源:cloudinit_test.go
示例16: TestWindowsRender
func (S) TestWindowsRender(c *gc.C) {
compareOutput := "#ps1_sysnative\r\n\r\npowershell"
cfg := cloudinit.New()
cfg.AddRunCmd("powershell")
render, err := cloudinit.NewRenderer("win8")
c.Assert(err, gc.IsNil)
data, err := render.Render(cfg)
c.Assert(err, gc.IsNil)
c.Assert(data, gc.NotNil)
c.Assert(string(data), gc.Equals, compareOutput, gc.Commentf("test %q output differs", "windows renderer"))
}
开发者ID:kapilt,项目名称:juju,代码行数:11,代码来源:cloudinit_test.go
示例17: TestCloudInitVerify
// TestCloudInitVerify checks that required fields are appropriately
// checked for by NewCloudInit.
func (*cloudinitSuite) TestCloudInitVerify(c *gc.C) {
cfg := &cloudinit.MachineConfig{
Bootstrap: true,
StateServingInfo: stateServingInfo,
MachineId: "99",
Tools: newSimpleTools("9.9.9-quantal-arble"),
AuthorizedKeys: "sshkey1",
Series: "quantal",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
MongoInfo: &mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{"host:98765"},
CACert: testing.CACert,
},
Password: "password",
},
APIInfo: &api.Info{
Addrs: []string{"host:9999"},
CACert: testing.CACert,
},
Config: minimalConfig(c),
DataDir: environs.DataDir,
LogDir: agent.DefaultLogDir,
Jobs: normalMachineJobs,
CloudInitOutputLog: cloudInitOutputLog,
InstanceId: "i-bootstrap",
MachineNonce: "FAKE_NONCE",
MachineAgentServiceName: "jujud-machine-99",
}
// check that the base configuration does not give an error
ci := coreCloudinit.New()
for i, test := range verifyTests {
// check that the base configuration does not give an error
// and that a previous test hasn't mutated it accidentially.
udata, err := cloudinit.NewUserdataConfig(cfg, ci)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Assert(err, gc.IsNil)
c.Logf("test %d. %s", i, test.err)
cfg1 := *cfg
test.mutate(&cfg1)
udata, err = cloudinit.NewUserdataConfig(&cfg1, ci)
c.Assert(err, gc.IsNil)
err = udata.Configure()
c.Check(err, gc.ErrorMatches, "invalid machine configuration: "+test.err)
}
}
开发者ID:kapilt,项目名称:juju,代码行数:54,代码来源:cloudinit_test.go
示例18: 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(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config) ([]byte, error) {
if cloudcfg == nil {
cloudcfg = coreCloudinit.New()
}
if err := configureCloudinit(mcfg, cloudcfg); err != nil {
return nil, err
}
data, err := cloudcfg.Render()
logger.Tracef("Generated cloud init:\n%s", string(data))
if err != nil {
return nil, err
}
return utils.Gzip(data), nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:19,代码来源:cloudinit.go
示例19: TestAptUpdate
func (s *configureSuite) TestAptUpdate(c *gc.C) {
// apt-get update is run if either AptUpdate is set,
// or apt sources are defined.
aptGetUpdatePattern := aptgetRegexp + "update(.|\n)*"
cfg := cloudinit.New()
c.Assert(cfg.AptUpdate(), gc.Equals, false)
c.Assert(cfg.AptSources(), gc.HasLen, 0)
assertScriptMatches(c, cfg, aptGetUpdatePattern, false)
cfg.SetAptUpdate(true)
assertScriptMatches(c, cfg, aptGetUpdatePattern, true)
cfg.SetAptUpdate(false)
cfg.AddAptSource("source", "key", nil)
assertScriptMatches(c, cfg, aptGetUpdatePattern, true)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:14,代码来源:configure_test.go
示例20: cloudInitUserData
func cloudInitUserData(machineConfig *cloudinit.MachineConfig) ([]byte, error) {
cloudConfig := coreCloudinit.New()
err := cloudinit.Configure(machineConfig, cloudConfig)
if err != nil {
return nil, err
}
// Run ifconfig to get the addresses of the internal container at least
// logged in the host.
cloudConfig.AddRunCmd("ifconfig")
data, err := cloudConfig.Render()
if err != nil {
return nil, err
}
return data, nil
}
开发者ID:jiasir,项目名称:juju,代码行数:17,代码来源:userdata.go
注:本文中的github.com/juju/juju/cloudinit.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论