本文整理汇总了Golang中github.com/juju/juju/environs/configstore.APIEndpoint.Addresses方法的典型用法代码示例。如果您正苦于以下问题:Golang APIEndpoint.Addresses方法的具体用法?Golang APIEndpoint.Addresses怎么用?Golang APIEndpoint.Addresses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/environs/configstore.APIEndpoint
的用法示例。
在下文中一共展示了APIEndpoint.Addresses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWriteSmallerFile
func (*diskStoreSuite) TestWriteSmallerFile(c *gc.C) {
dir := c.MkDir()
store, err := configstore.NewDisk(dir)
c.Assert(err, gc.IsNil)
info := store.CreateInfo("someenv")
endpoint := configstore.APIEndpoint{
Addresses: []string{"this", "is", "never", "validated", "here"},
EnvironUUID: "90168e4c-2f10-4e9c-83c2-feedfacee5a9",
}
info.SetAPIEndpoint(endpoint)
err = info.Write()
c.Assert(err, gc.IsNil)
newInfo, err := store.ReadInfo("someenv")
c.Assert(err, gc.IsNil)
// Now change the number of addresses to be shorter.
endpoint.Addresses = []string{"just one"}
newInfo.SetAPIEndpoint(endpoint)
err = newInfo.Write()
c.Assert(err, gc.IsNil)
// We should be able to read in in fine.
yaInfo, err := store.ReadInfo("someenv")
c.Assert(err, gc.IsNil)
c.Assert(yaInfo.APIEndpoint().Addresses, gc.DeepEquals, []string{"just one"})
}
示例2: TestWriteSmallerFile
func (*diskStoreSuite) TestWriteSmallerFile(c *gc.C) {
dir := c.MkDir()
store, err := configstore.NewDisk(dir)
c.Assert(err, jc.ErrorIsNil)
info := store.CreateInfo("somemodel")
endpoint := configstore.APIEndpoint{
Addresses: []string{"this", "is", "never", "validated", "here"},
Hostnames: []string{"neither", "is", "this"},
ModelUUID: testing.ModelTag.Id(),
}
info.SetAPIEndpoint(endpoint)
err = info.Write()
c.Assert(err, jc.ErrorIsNil)
newInfo, err := store.ReadInfo("somemodel")
c.Assert(err, jc.ErrorIsNil)
// Now change the number of addresses to be shorter.
endpoint.Addresses = []string{"just one"}
endpoint.Hostnames = []string{"just this"}
newInfo.SetAPIEndpoint(endpoint)
err = newInfo.Write()
c.Assert(err, jc.ErrorIsNil)
// We should be able to read in in fine.
yaInfo, err := store.ReadInfo("somemodel")
c.Assert(err, jc.ErrorIsNil)
c.Assert(yaInfo.APIEndpoint().Addresses, gc.DeepEquals, []string{"just one"})
c.Assert(yaInfo.APIEndpoint().Hostnames, gc.DeepEquals, []string{"just this"})
}
示例3: cacheAPIInfo
// cacheAPIInfo updates the local environment settings (.jenv file)
// with the provided apiInfo, assuming we've just successfully
// connected to the API server.
func cacheAPIInfo(st apiState, info configstore.EnvironInfo, apiInfo *api.Info) (err error) {
defer errors.DeferredAnnotatef(&err, "failed to cache API credentials")
var environUUID string
if names.IsValidEnvironment(apiInfo.EnvironTag.Id()) {
environUUID = apiInfo.EnvironTag.Id()
} else {
// For backwards-compatibility, we have to allow connections
// with an empty UUID. Login will work for the same reasons.
logger.Warningf("ignoring invalid cached API endpoint environment UUID %v", apiInfo.EnvironTag.Id())
}
hostPorts, err := network.ParseHostPorts(apiInfo.Addrs...)
if err != nil {
return errors.Annotatef(err, "invalid API addresses %v", apiInfo.Addrs)
}
addrConnectedTo, err := network.ParseHostPorts(st.Addr())
if err != nil {
// Should never happen, since we've just connected with it.
return errors.Annotatef(err, "invalid API address %q", st.Addr())
}
addrs, hostnames, addrsChanged := PrepareEndpointsForCaching(
info, [][]network.HostPort{hostPorts}, addrConnectedTo[0],
)
endpoint := configstore.APIEndpoint{
CACert: string(apiInfo.CACert),
EnvironUUID: environUUID,
}
if addrsChanged {
endpoint.Addresses = addrs
endpoint.Hostnames = hostnames
}
info.SetAPIEndpoint(endpoint)
tag, ok := apiInfo.Tag.(names.UserTag)
if !ok {
return errors.Errorf("apiInfo.Tag was of type %T, expecting names.UserTag", apiInfo.Tag)
}
info.SetAPICredentials(configstore.APICredentials{
// This looks questionable. We have a tag, say "user-admin", but then only
// the Id portion of the tag is recorded, "admin", so this is really a
// username, not a tag, and cannot be reconstructed accurately.
User: tag.Id(),
Password: apiInfo.Password,
})
return info.Write()
}