本文整理匯總了Golang中github.com/juju/juju/apiserver/params.UserEnvironmentList.UserEnvironments方法的典型用法代碼示例。如果您正苦於以下問題:Golang UserEnvironmentList.UserEnvironments方法的具體用法?Golang UserEnvironmentList.UserEnvironments怎麽用?Golang UserEnvironmentList.UserEnvironments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/apiserver/params.UserEnvironmentList
的用法示例。
在下文中一共展示了UserEnvironmentList.UserEnvironments方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AllEnvironments
// AllEnvironments allows controller administrators to get the list of all the
// environments in the controller.
func (s *ControllerAPI) AllEnvironments() (params.UserEnvironmentList, error) {
result := params.UserEnvironmentList{}
// 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.EnvironmentsForUser(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.UserEnvironments = append(result.UserEnvironments, params.UserEnvironment{
Environment: params.Environment{
Name: env.Name(),
UUID: env.UUID(),
OwnerTag: env.Owner().String(),
},
LastConnection: &lastConn,
})
}
allEnvs, err := s.state.AllEnvironments()
if err != nil {
return result, errors.Trace(err)
}
for _, env := range allEnvs {
if !visibleEnvironments.Contains(env.UUID()) {
result.UserEnvironments = append(result.UserEnvironments, params.UserEnvironment{
Environment: params.Environment{
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(orderedUserEnvironments(result.UserEnvironments))
return result, nil
}
示例2: ListEnvironments
// ListEnvironments returns the environments that the specified user
// has access to in the current server. Only that state server owner
// can list environments for any user (at this stage). Other users
// can only ask about their own environments.
func (em *EnvironmentManagerAPI) ListEnvironments(user params.Entity) (params.UserEnvironmentList, error) {
result := params.UserEnvironmentList{}
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)
}
environments, err := em.state.EnvironmentsForUser(userTag)
if err != nil {
return result, errors.Trace(err)
}
for _, env := range environments {
result.UserEnvironments = append(result.UserEnvironments, params.UserEnvironment{
Environment: params.Environment{
Name: env.Name(),
UUID: env.UUID(),
OwnerTag: env.Owner().String(),
},
LastConnection: env.LastConnection,
})
logger.Debugf("list env: %s, %s, %s", env.Name(), env.UUID(), env.Owner())
}
return result, nil
}