本文整理汇总了Golang中github.com/juju/juju/apiserver/client.InstanceConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang InstanceConfig函数的具体用法?Golang InstanceConfig怎么用?Golang InstanceConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InstanceConfig函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSecureConnectionDisallowed
func (s *machineConfigSuite) TestSecureConnectionDisallowed(c *gc.C) {
// StateServingInfo without CAPrivateKey will not allow secure connections.
servingInfo := state.StateServingInfo{
PrivateKey: jujutesting.ServerKey,
Cert: jujutesting.ServerCert,
SharedSecret: "really, really secret",
APIPort: 4321,
StatePort: 1234,
}
s.State.SetStateServingInfo(servingInfo)
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "false")
}
示例2: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
envConfig, err := s.State.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
mongoAddrs := s.State.MongoConnectionInfo().Addrs
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(envConfig.APIPort()))}
c.Check(instanceConfig.MongoInfo.Addrs, gc.DeepEquals, mongoAddrs)
c.Check(instanceConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/environment/%s/tools/%s",
apiAddrs[0], jujutesting.EnvironmentTag.Id(), instanceConfig.Tools.Version)
c.Assert(instanceConfig.Tools.URL, gc.Equals, toolsURL)
c.Assert(instanceConfig.AgentEnvironment[agent.AllowsSecureConnection], gc.Equals, "true")
}
示例3: TestMachineConfig
func (s *machineConfigSuite) TestMachineConfig(c *gc.C) {
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs...),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
instanceConfig, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
cfg, err := s.State.ControllerConfig()
c.Assert(err, jc.ErrorIsNil)
apiAddrs := []string{net.JoinHostPort("localhost", strconv.Itoa(cfg.APIPort()))}
c.Check(instanceConfig.APIInfo.Addrs, gc.DeepEquals, apiAddrs)
toolsURL := fmt.Sprintf("https://%s/model/%s/tools/%s",
apiAddrs[0], jujutesting.ModelTag.Id(), instanceConfig.AgentVersion())
c.Assert(instanceConfig.ToolsList().URLs(), jc.DeepEquals, map[version.Binary][]string{
instanceConfig.AgentVersion(): []string{toolsURL},
})
}
示例4: TestMachineConfigNoArch
func (s *machineConfigSuite) TestMachineConfigNoArch(c *gc.C) {
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
_, err = client.InstanceConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine))
}
示例5: TestMachineConfigNoTools
func (s *machineConfigSuite) TestMachineConfigNoTools(c *gc.C) {
s.PatchValue(&envtools.DefaultBaseURL, "")
addrs := network.NewAddresses("1.2.3.4")
hc := instance.MustParseHardware("mem=4G arch=amd64")
apiParams := params.AddMachineParams{
Series: "quantal",
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: hc,
Addrs: params.FromNetworkAddresses(addrs),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
_, err = client.InstanceConfig(s.State, machines[0].Machine, apiParams.Nonce, "")
c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error())
}
示例6: TestFinishInstancConfig
func (s *provisionerSuite) TestFinishInstancConfig(c *gc.C) {
var series = series.LatestLts()
const arch = "amd64"
defer fakeSSH{
Series: series,
Arch: arch,
InitUbuntuUser: true,
}.install(c).Restore()
machineId, err := manual.ProvisionMachine(s.getArgs(c))
c.Assert(err, jc.ErrorIsNil)
// Now check what we would've configured it with.
icfg, err := client.InstanceConfig(s.State, machineId, agent.BootstrapNonce, "/var/lib/juju")
c.Assert(err, jc.ErrorIsNil)
c.Check(icfg, gc.NotNil)
c.Check(icfg.APIInfo, gc.NotNil)
apiInfo := s.APIInfo(c)
c.Check(icfg.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs)
}
示例7: TestProvisioningScript
func (s *clientSuite) TestProvisioningScript(c *gc.C) {
// Inject a machine and then call the ProvisioningScript API.
// The result should be the same as when calling MachineConfig,
// converting it to a cloudinit.MachineConfig, and disabling
// apt_upgrade.
apiParams := params.AddMachineParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
InstanceId: instance.Id("1234"),
Nonce: "foo",
HardwareCharacteristics: instance.MustParseHardware("arch=amd64"),
}
machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams})
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 1)
machineId := machines[0].Machine
// Call ProvisioningScript. Normally ProvisioningScript and
// MachineConfig are mutually exclusive; both of them will
// allocate a api password for the machine agent.
script, err := s.APIState.Client().ProvisioningScript(params.ProvisioningScriptParams{
MachineId: machineId,
Nonce: apiParams.Nonce,
})
c.Assert(err, jc.ErrorIsNil)
icfg, err := client.InstanceConfig(s.State, machineId, apiParams.Nonce, "")
c.Assert(err, jc.ErrorIsNil)
provisioningScript, err := manual.ProvisioningScript(icfg)
c.Assert(err, jc.ErrorIsNil)
// ProvisioningScript internally calls MachineConfig,
// which allocates a new, random password. Everything
// about the scripts should be the same other than
// the line containing "oldpassword" from agent.conf.
scriptLines := strings.Split(script, "\n")
provisioningScriptLines := strings.Split(provisioningScript, "\n")
c.Assert(scriptLines, gc.HasLen, len(provisioningScriptLines))
for i, line := range scriptLines {
if strings.Contains(line, "oldpassword") {
continue
}
c.Assert(line, gc.Equals, provisioningScriptLines[i])
}
}
示例8: TestProvisioningScript
func (s *provisionerSuite) TestProvisioningScript(c *gc.C) {
var series = series.LatestLts()
const arch = "amd64"
defer fakeSSH{
Series: series,
Arch: arch,
InitUbuntuUser: true,
}.install(c).Restore()
machineId, err := manual.ProvisionMachine(s.getArgs(c))
c.Assert(err, jc.ErrorIsNil)
err = s.State.UpdateModelConfig(
map[string]interface{}{
"enable-os-upgrade": false,
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
icfg, err := client.InstanceConfig(s.State, machineId, agent.BootstrapNonce, "/var/lib/juju")
c.Assert(err, jc.ErrorIsNil)
script, err := manual.ProvisioningScript(icfg)
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := cloudinit.New(series)
c.Assert(err, jc.ErrorIsNil)
udata, err := cloudconfig.NewUserdataConfig(icfg, cloudcfg)
c.Assert(err, jc.ErrorIsNil)
err = udata.ConfigureJuju()
c.Assert(err, jc.ErrorIsNil)
cloudcfg.SetSystemUpgrade(false)
provisioningScript, err := cloudcfg.RenderScript()
c.Assert(err, jc.ErrorIsNil)
removeLogFile := "rm -f '/var/log/cloud-init-output.log'\n"
expectedScript := removeLogFile + shell.DumpFileOnErrorScript("/var/log/cloud-init-output.log") + provisioningScript
c.Assert(script, gc.Equals, expectedScript)
}