本文整理汇总了Golang中github.com/juju/juju/apiserver/params.UserModelList.UserModels方法的典型用法代码示例。如果您正苦于以下问题:Golang UserModelList.UserModels方法的具体用法?Golang UserModelList.UserModels怎么用?Golang UserModelList.UserModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/params.UserModelList
的用法示例。
在下文中一共展示了UserModelList.UserModels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AllModels
// AllModels allows controller administrators to get the list of all the
// environments in the controller.
func (s *ControllerAPI) AllModels() (params.UserModelList, error) {
result := params.UserModelList{}
if err := s.checkHasAdmin(); err != nil {
return result, errors.Trace(err)
}
// Get all the environments that the authenticated user can see, and
// supplement that with the other environments that exist that the user
// cannot see. The reason we do this is to get the LastConnection time for
// the environments that the user is able to see, so we have consistent
// output when listing with or without --all when an admin user.
environments, err := s.state.ModelsForUser(s.apiUser)
if err != nil {
return result, errors.Trace(err)
}
visibleEnvironments := set.NewStrings()
for _, env := range environments {
lastConn, err := env.LastConnection()
if err != nil && !state.IsNeverConnectedError(err) {
return result, errors.Trace(err)
}
visibleEnvironments.Add(env.UUID())
result.UserModels = append(result.UserModels, params.UserModel{
Model: params.Model{
Name: env.Name(),
UUID: env.UUID(),
OwnerTag: env.Owner().String(),
},
LastConnection: &lastConn,
})
}
allEnvs, err := s.state.AllModels()
if err != nil {
return result, errors.Trace(err)
}
for _, env := range allEnvs {
if !visibleEnvironments.Contains(env.UUID()) {
result.UserModels = append(result.UserModels, params.UserModel{
Model: params.Model{
Name: env.Name(),
UUID: env.UUID(),
OwnerTag: env.Owner().String(),
},
// No LastConnection as this user hasn't.
})
}
}
// Sort the resulting sequence by environment name, then owner.
sort.Sort(orderedUserModels(result.UserModels))
return result, nil
}
示例2: ListModels
// ListModels returns the models that the specified user
// has access to in the current server. Only that controller owner
// can list models for any user (at this stage). Other users
// can only ask about their own models.
func (em *ModelManagerAPI) ListModels(user params.Entity) (params.UserModelList, error) {
result := params.UserModelList{}
userTag, err := names.ParseUserTag(user.Tag)
if err != nil {
return result, errors.Trace(err)
}
err = em.authCheck(userTag)
if err != nil {
return result, errors.Trace(err)
}
models, err := em.state.ModelsForUser(userTag)
if err != nil {
return result, errors.Trace(err)
}
for _, model := range models {
var lastConn *time.Time
userLastConn, err := model.LastConnection()
if err != nil {
if !state.IsNeverConnectedError(err) {
return result, errors.Trace(err)
}
} else {
lastConn = &userLastConn
}
result.UserModels = append(result.UserModels, params.UserModel{
Model: params.Model{
Name: model.Name(),
UUID: model.UUID(),
OwnerTag: model.Owner().String(),
},
LastConnection: lastConn,
})
logger.Debugf("list models: %s, %s, %s", model.Name(), model.UUID(), model.Owner())
}
return result, nil
}