本文整理汇总了Golang中github.com/juju/juju/cloudconfig/instancecfg.NewInstanceConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewInstanceConfig函数的具体用法?Golang NewInstanceConfig怎么用?Golang NewInstanceConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewInstanceConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestStartInstanceWithEmptyNonceFails
// Check that we get a consistent error when asking for an instance without
// a valid machine config.
func (t *LiveTests) TestStartInstanceWithEmptyNonceFails(c *gc.C) {
machineId := "4"
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, "", "released", "quantal", "", true, nil, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
t.PrepareOnce(c)
possibleTools := coretools.List(envtesting.AssertUploadFakeToolsVersions(
c, t.toolsStorage, "released", "released", version.MustParseBinary("5.4.5-trusty-amd64"),
))
params := environs.StartInstanceParams{
Tools: possibleTools,
InstanceConfig: instanceConfig,
}
err = jujutesting.SetImageMetadata(
t.Env,
possibleTools.AllSeries(),
possibleTools.Arches(),
¶ms.ImageMetadata,
)
c.Check(err, jc.ErrorIsNil)
result, err := t.Env.StartInstance(params)
if result != nil && result.Instance != nil {
err := t.Env.StopInstances(result.Instance.Id())
c.Check(err, jc.ErrorIsNil)
}
c.Assert(result, gc.IsNil)
c.Assert(err, gc.ErrorMatches, ".*missing machine nonce")
}
示例2: makeStartInstanceParams
func makeStartInstanceParams(c *gc.C, controllerUUID, series string) environs.StartInstanceParams {
machineTag := names.NewMachineTag("0")
apiInfo := &api.Info{
Addrs: []string{"localhost:17777"},
CACert: testing.CACert,
Password: "admin",
Tag: machineTag,
ModelTag: testing.ModelTag,
}
icfg, err := instancecfg.NewInstanceConfig(
names.NewControllerTag(controllerUUID),
machineTag.Id(), "yanonce", imagemetadata.ReleasedStream,
series, apiInfo,
)
c.Assert(err, jc.ErrorIsNil)
icfg.Tags = map[string]string{
tags.JujuModel: testing.ModelTag.Id(),
tags.JujuController: controllerUUID,
}
return environs.StartInstanceParams{
ControllerUUID: controllerUUID,
Tools: makeToolsList(series),
InstanceConfig: icfg,
}
}
示例3: makeStartInstanceParams
func makeStartInstanceParams(c *gc.C, series string) environs.StartInstanceParams {
machineTag := names.NewMachineTag("0")
stateInfo := &mongo.MongoInfo{
Info: mongo.Info{
CACert: testing.CACert,
Addrs: []string{"localhost:123"},
},
Password: "password",
Tag: machineTag,
}
apiInfo := &api.Info{
Addrs: []string{"localhost:246"},
CACert: testing.CACert,
Password: "admin",
Tag: machineTag,
ModelTag: testing.ModelTag,
}
const secureServerConnections = true
icfg, err := instancecfg.NewInstanceConfig(
machineTag.Id(), "yanonce", imagemetadata.ReleasedStream,
series, "", secureServerConnections, stateInfo, apiInfo,
)
c.Assert(err, jc.ErrorIsNil)
return environs.StartInstanceParams{
Tools: makeToolsList(series),
InstanceConfig: icfg,
}
}
示例4: constructInstanceConfig
func (task *provisionerTask) constructInstanceConfig(
machine *apiprovisioner.Machine,
auth authentication.AuthenticationProvider,
pInfo *params.ProvisioningInfo,
) (*instancecfg.InstanceConfig, error) {
stateInfo, apiInfo, err := auth.SetupAuthentication(machine)
if err != nil {
return nil, errors.Annotate(err, "failed to setup authentication")
}
// Generated a nonce for the new instance, with the format: "machine-#:UUID".
// The first part is a badge, specifying the tag of the machine the provisioner
// is running on, while the second part is a random UUID.
uuid, err := utils.NewUUID()
if err != nil {
return nil, errors.Annotate(err, "failed to generate a nonce for machine "+machine.Id())
}
nonce := fmt.Sprintf("%s:%s", task.machineTag, uuid)
return instancecfg.NewInstanceConfig(
machine.Id(),
nonce,
task.imageStream,
pInfo.Series,
task.secureServerConnection,
nil,
stateInfo,
apiInfo,
)
}
示例5: getCloudConfig
func (s *configureSuite) getCloudConfig(c *gc.C, controller bool, vers version.Binary) cloudinit.CloudConfig {
var icfg *instancecfg.InstanceConfig
var err error
modelConfig := testConfig(c, controller, vers)
if controller {
icfg, err = instancecfg.NewBootstrapInstanceConfig(
coretesting.FakeControllerConfig(),
constraints.Value{}, constraints.Value{},
vers.Series, "",
)
c.Assert(err, jc.ErrorIsNil)
icfg.APIInfo = &api.Info{
Password: "password",
CACert: coretesting.CACert,
ModelTag: coretesting.ModelTag,
}
icfg.Controller.MongoInfo = &mongo.MongoInfo{
Password: "password", Info: mongo.Info{CACert: coretesting.CACert},
}
icfg.Bootstrap.ControllerModelConfig = modelConfig
icfg.Bootstrap.BootstrapMachineInstanceId = "instance-id"
icfg.Bootstrap.HostedModelConfig = map[string]interface{}{
"name": "hosted-model",
}
icfg.Bootstrap.StateServingInfo = params.StateServingInfo{
Cert: coretesting.ServerCert,
PrivateKey: coretesting.ServerKey,
CAPrivateKey: coretesting.CAKey,
StatePort: 123,
APIPort: 456,
}
icfg.Jobs = []multiwatcher.MachineJob{multiwatcher.JobManageModel, multiwatcher.JobHostUnits}
icfg.Bootstrap.StateServingInfo = params.StateServingInfo{
Cert: coretesting.ServerCert,
PrivateKey: coretesting.ServerKey,
CAPrivateKey: coretesting.CAKey,
StatePort: 123,
APIPort: 456,
}
} else {
icfg, err = instancecfg.NewInstanceConfig(coretesting.ControllerTag, "0", "ya", imagemetadata.ReleasedStream, vers.Series, nil)
c.Assert(err, jc.ErrorIsNil)
icfg.Jobs = []multiwatcher.MachineJob{multiwatcher.JobHostUnits}
}
err = icfg.SetTools(tools.List{
&tools.Tools{
Version: vers,
URL: "http://testing.invalid/tools.tar.gz",
},
})
err = instancecfg.FinishInstanceConfig(icfg, modelConfig)
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := cloudinit.New(icfg.Series)
c.Assert(err, jc.ErrorIsNil)
udata, err := cloudconfig.NewUserdataConfig(icfg, cloudcfg)
c.Assert(err, jc.ErrorIsNil)
err = udata.Configure()
c.Assert(err, jc.ErrorIsNil)
return cloudcfg
}
示例6: createContainer
func createContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance {
machineNonce := "fake-nonce"
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, imagemetadata.ReleasedStream, "quantal", "", true, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
network := container.BridgeNetworkConfig("virbr0", 0, nil)
err = instanceConfig.SetTools(tools.List{
&tools.Tools{
Version: version.MustParseBinary("2.3.4-foo-bar"),
URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz",
},
})
c.Assert(err, jc.ErrorIsNil)
environConfig := dummyConfig(c)
err = instancecfg.FinishInstanceConfig(instanceConfig, environConfig)
c.Assert(err, jc.ErrorIsNil)
callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil }
inst, hardware, err := manager.CreateContainer(instanceConfig, "precise", network, nil, callback)
c.Assert(err, jc.ErrorIsNil)
c.Assert(hardware, gc.NotNil)
expected := fmt.Sprintf("arch=%s cpu-cores=1 mem=512M root-disk=8192M", arch.HostArch())
c.Assert(hardware.String(), gc.Equals, expected)
return inst
}
示例7: getCloudConfig
func (s *configureSuite) getCloudConfig(c *gc.C, stateServer bool, vers version.Binary) cloudinit.CloudConfig {
var icfg *instancecfg.InstanceConfig
var err error
if stateServer {
icfg, err = instancecfg.NewBootstrapInstanceConfig(constraints.Value{}, vers.Series)
c.Assert(err, jc.ErrorIsNil)
icfg.InstanceId = "instance-id"
icfg.Jobs = []multiwatcher.MachineJob{multiwatcher.JobManageEnviron, multiwatcher.JobHostUnits}
} else {
icfg, err = instancecfg.NewInstanceConfig("0", "ya", imagemetadata.ReleasedStream, vers.Series, true, nil, nil, nil)
c.Assert(err, jc.ErrorIsNil)
icfg.Jobs = []multiwatcher.MachineJob{multiwatcher.JobHostUnits}
}
icfg.Tools = &tools.Tools{
Version: vers,
URL: "http://testing.invalid/tools.tar.gz",
}
environConfig := testConfig(c, stateServer, vers)
err = instancecfg.FinishInstanceConfig(icfg, environConfig)
c.Assert(err, jc.ErrorIsNil)
cloudcfg, err := cloudinit.New(icfg.Series)
c.Assert(err, jc.ErrorIsNil)
udata, err := cloudconfig.NewUserdataConfig(icfg, cloudcfg)
c.Assert(err, jc.ErrorIsNil)
err = udata.Configure()
c.Assert(err, jc.ErrorIsNil)
return cloudcfg
}
示例8: StartInstanceWithParams
// StartInstanceWithParams is a test helper function that starts an instance
// with the given parameters, and a plausible but invalid configuration, and
// returns the result of Environ.StartInstance. The provided params's
// InstanceConfig and Tools field values will be ignored.
func StartInstanceWithParams(
env environs.Environ, machineId string,
params environs.StartInstanceParams,
networks []string,
) (
*environs.StartInstanceResult, error,
) {
preferredSeries := config.PreferredSeries(env.Config())
agentVersion, ok := env.Config().AgentVersion()
if !ok {
return nil, errors.New("missing agent version in model config")
}
filter := coretools.Filter{
Number: agentVersion,
Series: preferredSeries,
}
if params.Constraints.Arch != nil {
filter.Arch = *params.Constraints.Arch
}
stream := tools.PreferredStream(&agentVersion, env.Config().Development(), env.Config().AgentStream())
possibleTools, err := tools.FindTools(env, -1, -1, stream, filter)
if err != nil {
return nil, errors.Trace(err)
}
if params.ImageMetadata == nil {
if err := SetImageMetadata(
env,
possibleTools.AllSeries(),
possibleTools.Arches(),
¶ms.ImageMetadata,
); err != nil {
return nil, errors.Trace(err)
}
}
machineNonce := "fake_nonce"
stateInfo := FakeStateInfo(machineId)
apiInfo := FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(
machineId,
machineNonce,
imagemetadata.ReleasedStream,
preferredSeries,
"",
true,
networks,
stateInfo,
apiInfo,
)
if err != nil {
return nil, errors.Trace(err)
}
eUUID, _ := env.Config().UUID()
instanceConfig.Tags[tags.JujuModel] = eUUID
params.Tools = possibleTools
params.InstanceConfig = instanceConfig
return env.StartInstance(params)
}
示例9: instanceConfig
func (s *lxdBrokerSuite) instanceConfig(c *gc.C, machineId string) *instancecfg.InstanceConfig {
machineNonce := "fake-nonce"
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, "released", "quantal", "", true, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
return instanceConfig
}
示例10: makeInstanceConfig
func makeInstanceConfig(c *gc.C, s patcher, machineId string) *instancecfg.InstanceConfig {
machineNonce := "fake-nonce"
// To isolate the tests from the host's architecture, we override it here.
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(coretesting.ControllerTag, machineId, machineNonce, "released", "quantal", apiInfo)
c.Assert(err, jc.ErrorIsNil)
return instanceConfig
}
示例11: instanceConfig
func (s *kvmBrokerSuite) instanceConfig(c *gc.C, machineId string) *instancecfg.InstanceConfig {
machineNonce := "fake-nonce"
// To isolate the tests from the host's architecture, we override it here.
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, "released", "quantal", true, nil, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
return instanceConfig
}
示例12: constructInstanceConfig
func (task *provisionerTask) constructInstanceConfig(
machine *apiprovisioner.Machine,
auth authentication.AuthenticationProvider,
pInfo *params.ProvisioningInfo,
) (*instancecfg.InstanceConfig, error) {
stateInfo, apiInfo, err := auth.SetupAuthentication(machine)
if err != nil {
return nil, errors.Annotate(err, "failed to setup authentication")
}
// Generated a nonce for the new instance, with the format: "machine-#:UUID".
// The first part is a badge, specifying the tag of the machine the provisioner
// is running on, while the second part is a random UUID.
uuid, err := utils.NewUUID()
if err != nil {
return nil, errors.Annotate(err, "failed to generate a nonce for machine "+machine.Id())
}
nonce := fmt.Sprintf("%s:%s", task.machineTag, uuid)
instanceConfig, err := instancecfg.NewInstanceConfig(
names.NewControllerTag(controller.Config(pInfo.ControllerConfig).ControllerUUID()),
machine.Id(),
nonce,
task.imageStream,
pInfo.Series,
apiInfo,
)
if err != nil {
return nil, errors.Trace(err)
}
instanceConfig.Tags = pInfo.Tags
if len(pInfo.Jobs) > 0 {
instanceConfig.Jobs = pInfo.Jobs
}
if multiwatcher.AnyJobNeedsState(instanceConfig.Jobs...) {
publicKey, err := simplestreams.UserPublicSigningKey()
if err != nil {
return nil, err
}
instanceConfig.Controller = &instancecfg.ControllerConfig{
PublicImageSigningKey: publicKey,
MongoInfo: stateInfo,
}
instanceConfig.Controller.Config = make(map[string]interface{})
for k, v := range pInfo.ControllerConfig {
instanceConfig.Controller.Config[k] = v
}
}
return instanceConfig, nil
}
示例13: instanceConfig
func (s *lxcBrokerSuite) instanceConfig(c *gc.C, machineId string) *instancecfg.InstanceConfig {
machineNonce := "fake-nonce"
// To isolate the tests from the host's architecture, we override it here.
s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, "released", "quantal", "", true, nil, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
// Ensure the <rootfs>/etc/network path exists.
containertesting.EnsureLXCRootFSEtcNetwork(c, "juju-"+names.NewMachineTag(machineId).String())
return instanceConfig
}
示例14: MockMachineConfig
func MockMachineConfig(machineId string) (*instancecfg.InstanceConfig, error) {
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, "fake-nonce", imagemetadata.ReleasedStream, "quantal", "", true, nil, stateInfo, apiInfo)
if err != nil {
return nil, err
}
instanceConfig.Tools = &tools.Tools{
Version: version.MustParseBinary("2.3.4-quantal-amd64"),
URL: "http://tools.testing.invalid/2.3.4-quantal-amd64.tgz",
}
return instanceConfig, nil
}
示例15: createInstanceConfig
func (*cloudinitSuite) createInstanceConfig(c *gc.C, environConfig *config.Config) *instancecfg.InstanceConfig {
machineId := "42"
machineNonce := "fake-nonce"
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, imagemetadata.ReleasedStream, "quantal", "", true, nil, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
instanceConfig.Tools = &tools.Tools{
Version: version.MustParseBinary("2.3.4-quantal-amd64"),
URL: "http://tools.testing.invalid/2.3.4-quantal-amd64.tgz",
}
err = instancecfg.FinishInstanceConfig(instanceConfig, environConfig)
c.Assert(err, jc.ErrorIsNil)
return instanceConfig
}