本文整理汇总了Golang中github.com/juju/juju/api.Connection.ControllerTag方法的典型用法代码示例。如果您正苦于以下问题:Golang Connection.ControllerTag方法的具体用法?Golang Connection.ControllerTag怎么用?Golang Connection.ControllerTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api.Connection
的用法示例。
在下文中一共展示了Connection.ControllerTag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: cacheConnectionInfo
func (c *loginCommand) cacheConnectionInfo(serverDetails envcmd.ServerFile, apiState api.Connection) (configstore.EnvironInfo, error) {
store, err := configstore.Default()
if err != nil {
return nil, errors.Trace(err)
}
controllerInfo := store.CreateInfo(c.Name)
controllerTag, err := apiState.ControllerTag()
if err != nil {
return nil, errors.Wrap(err, errors.New("juju controller too old to support login"))
}
connectedAddresses, err := network.ParseHostPorts(apiState.Addr())
if err != nil {
// Should never happen, since we've just connected with it.
return nil, errors.Annotatef(err, "invalid API address %q", apiState.Addr())
}
addressConnectedTo := connectedAddresses[0]
addrs, hosts, changed := juju.PrepareEndpointsForCaching(controllerInfo, apiState.APIHostPorts(), addressConnectedTo)
if !changed {
logger.Infof("api addresses: %v", apiState.APIHostPorts())
logger.Infof("address connected to: %v", addressConnectedTo)
return nil, errors.New("no addresses returned from prepare for caching")
}
controllerInfo.SetAPICredentials(
configstore.APICredentials{
User: serverDetails.Username,
Password: serverDetails.Password,
})
controllerInfo.SetAPIEndpoint(configstore.APIEndpoint{
Addresses: addrs,
Hostnames: hosts,
CACert: serverDetails.CACert,
ServerUUID: controllerTag.Id(),
})
if err = controllerInfo.Write(); err != nil {
return nil, errors.Trace(err)
}
return controllerInfo, nil
}