本文整理汇总了Golang中github.com/wallyworld/core/state/apiserver/common.ServerError函数的典型用法代码示例。如果您正苦于以下问题:Golang ServerError函数的具体用法?Golang ServerError怎么用?Golang ServerError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServerError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateLatestRevisions
// UpdateLatestRevisions retrieves the latest revision information from the charm store for all deployed charms
// and records this information in state.
func (api *CharmRevisionUpdaterAPI) UpdateLatestRevisions() (params.ErrorResult, error) {
// First get the uuid for the environment to use when querying the charm store.
env, err := api.state.Environment()
if err != nil {
return params.ErrorResult{Error: common.ServerError(err)}, nil
}
uuid := env.UUID()
deployedCharms, err := fetchAllDeployedCharms(api.state)
if err != nil {
return params.ErrorResult{Error: common.ServerError(err)}, nil
}
// Look up the revision information for all the deployed charms.
curls, err := retrieveLatestCharmInfo(deployedCharms, uuid)
if err != nil {
return params.ErrorResult{Error: common.ServerError(err)}, nil
}
// Add the charms and latest revision info to state as charm placeholders.
for _, curl := range curls {
if err = api.state.AddStoreCharmPlaceholder(curl); err != nil {
return params.ErrorResult{Error: common.ServerError(err)}, nil
}
}
return params.ErrorResult{}, nil
}
示例2: RemoveUser
func (api *UserManagerAPI) RemoveUser(args params.Entities) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
canWrite, err := api.getCanWrite()
if err != nil {
return result, err
}
for i, arg := range args.Entities {
if !canWrite(arg.Tag) {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
user, err := api.state.User(arg.Tag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
err = user.Deactivate()
if err != nil {
result.Results[i].Error = common.ServerError(fmt.Errorf("Failed to remove user: %s", err))
continue
}
}
return result, nil
}
示例3: SetSupportedContainers
// SetSupportedContainers updates the list of containers supported by the machines passed in args.
func (p *ProvisionerAPI) SetSupportedContainers(
args params.MachineContainersParams) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Params)),
}
for i, arg := range args.Params {
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
machine, err := p.getMachine(canAccess, arg.MachineTag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if len(arg.ContainerTypes) == 0 {
err = machine.SupportsNoContainers()
} else {
err = machine.SetSupportedContainers(arg.ContainerTypes)
}
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
}
示例4: WatchAuthorisedKeys
// WatchAuthorisedKeys starts a watcher to track changes to the authorised ssh keys
// for the specified machines.
// The current implementation relies on global authorised keys being stored in the environment config.
// This will change as new user management and authorisation functionality is added.
func (api *KeyUpdaterAPI) WatchAuthorisedKeys(arg params.Entities) (params.NotifyWatchResults, error) {
results := make([]params.NotifyWatchResult, len(arg.Entities))
canRead, err := api.getCanRead()
if err != nil {
return params.NotifyWatchResults{}, err
}
for i, entity := range arg.Entities {
// 1. Check permissions
if !canRead(entity.Tag) {
results[i].Error = common.ServerError(common.ErrPerm)
continue
}
// 2. Check entity exists
if _, err := api.state.FindEntity(entity.Tag); err != nil {
if errors.IsNotFound(err) {
results[i].Error = common.ServerError(common.ErrPerm)
} else {
results[i].Error = common.ServerError(err)
}
continue
}
// 3. Watch fr changes
var err error
watch := api.state.WatchForEnvironConfigChanges()
// Consume the initial event.
if _, ok := <-watch.Changes(); ok {
results[i].NotifyWatcherId = api.resources.Register(watch)
} else {
err = watcher.MustErr(watch)
}
results[i].Error = common.ServerError(err)
}
return params.NotifyWatchResults{Results: results}, nil
}
示例5: AddUser
func (api *UserManagerAPI) AddUser(args params.EntityPasswords) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Changes)),
}
if len(args.Changes) == 0 {
return result, nil
}
canWrite, err := api.getCanWrite()
if err != nil {
result.Results[0].Error = common.ServerError(err)
return result, err
}
for i, arg := range args.Changes {
if !canWrite(arg.Tag) {
result.Results[0].Error = common.ServerError(common.ErrPerm)
continue
}
_, err := api.state.AddUser(arg.Tag, arg.Password)
if err != nil {
err = fmt.Errorf("Failed to create user: %v", err)
result.Results[i].Error = common.ServerError(err)
continue
}
}
return result, nil
}
示例6: DesiredVersion
// DesiredVersion reports the Agent Version that we want that agent to be running
func (u *UpgraderAPI) DesiredVersion(args params.Entities) (params.VersionResults, error) {
results := make([]params.VersionResult, len(args.Entities))
if len(args.Entities) == 0 {
return params.VersionResults{}, nil
}
agentVersion, _, err := u.getGlobalAgentVersion()
if err != nil {
return params.VersionResults{}, common.ServerError(err)
}
// Is the desired version greater than the current API server version?
isNewerVersion := agentVersion.Compare(version.Current.Number) > 0
for i, entity := range args.Entities {
err := common.ErrPerm
if u.authorizer.AuthOwner(entity.Tag) {
if !isNewerVersion || u.entityIsManager(entity.Tag) {
results[i].Version = &agentVersion
} else {
logger.Debugf("desired version is %s, but current version is %s and agent is not a manager node", agentVersion, version.Current.Number)
results[i].Version = &version.Current.Number
}
err = nil
}
results[i].Error = common.ServerError(err)
}
return params.VersionResults{Results: results}, nil
}
示例7: SetInstanceInfo
// SetInstanceInfo sets the provider specific machine id, nonce,
// metadata and network info for each given machine. Once set, the
// instance id cannot be changed.
func (p *ProvisionerAPI) SetInstanceInfo(args params.InstancesInfo) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Machines)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, arg := range args.Machines {
machine, err := p.getMachine(canAccess, arg.Tag)
if err == nil {
var networks []state.NetworkInfo
var interfaces []state.NetworkInterfaceInfo
networks, interfaces, err = networkParamsToStateParams(arg.Networks, arg.Interfaces)
if err == nil {
err = machine.SetInstanceInfo(
arg.InstanceId, arg.Nonce, arg.Characteristics,
networks, interfaces)
}
if err != nil {
// Give the user more context about the error.
err = fmt.Errorf("aborted instance %q: %v", arg.InstanceId, err)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例8: RequestedNetworks
// RequestedNetworks returns the requested networks for each given
// machine entity. Each entry in both lists is returned with its
// provider specific id.
func (p *ProvisionerAPI) RequestedNetworks(args params.Entities) (params.RequestedNetworksResults, error) {
result := params.RequestedNetworksResults{
Results: make([]params.RequestedNetworkResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
machine, err := p.getMachine(canAccess, entity.Tag)
if err == nil {
var includeNetworks []string
var excludeNetworks []string
includeNetworks, excludeNetworks, err = machine.RequestedNetworks()
if err == nil {
// TODO(dimitern) For now, since network names and
// provider ids are the same, we return what we got
// from state. In the future, when networks can be
// added before provisioning, we should convert both
// slices from juju network names to provider-specific
// ids before returning them.
result.Results[i].IncludeNetworks = includeNetworks
result.Results[i].ExcludeNetworks = excludeNetworks
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例9: DistributionGroup
// DistributionGroup returns, for each given machine entity,
// a slice of instance.Ids that belong to the same distribution
// group as that machine. This information may be used to
// distribute instances for high availability.
func (p *ProvisionerAPI) DistributionGroup(args params.Entities) (params.DistributionGroupResults, error) {
result := params.DistributionGroupResults{
Results: make([]params.DistributionGroupResult, len(args.Entities)),
}
canAccess, err := p.getAuthFunc()
if err != nil {
return result, err
}
for i, entity := range args.Entities {
machine, err := p.getMachine(canAccess, entity.Tag)
if err == nil {
// If the machine is an environment manager, return
// environment manager instances. Otherwise, return
// instances with services in common with the machine
// being provisioned.
if machine.IsManager() {
result.Results[i].Result, err = environManagerInstances(p.st)
} else {
result.Results[i].Result, err = commonServiceInstances(p.st, machine)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例10: SetRsyslogCert
func (api *RsyslogAPI) SetRsyslogCert(args params.SetRsyslogCertParams) (params.ErrorResult, error) {
var result params.ErrorResult
if !api.canModify {
result.Error = common.ServerError(common.ErrBadCreds)
return result, nil
}
if _, err := cert.ParseCert(string(args.CACert)); err != nil {
result.Error = common.ServerError(err)
return result, nil
}
attrs := map[string]interface{}{"rsyslog-ca-cert": string(args.CACert)}
if err := api.st.UpdateEnvironConfig(attrs, nil, nil); err != nil {
result.Error = common.ServerError(err)
}
return result, nil
}
示例11: CharmURL
// CharmURL returns the charm URL for all given units or services.
func (u *UniterAPI) CharmURL(args params.Entities) (params.StringBoolResults, error) {
result := params.StringBoolResults{
Results: make([]params.StringBoolResult, len(args.Entities)),
}
accessUnitOrService := common.AuthEither(u.accessUnit, u.accessService)
canAccess, err := accessUnitOrService()
if err != nil {
return params.StringBoolResults{}, err
}
for i, entity := range args.Entities {
err := common.ErrPerm
if canAccess(entity.Tag) {
var unitOrService state.Entity
unitOrService, err = u.st.FindEntity(entity.Tag)
if err == nil {
charmURLer := unitOrService.(interface {
CharmURL() (*charm.URL, bool)
})
curl, ok := charmURLer.CharmURL()
if curl != nil {
result.Results[i].Result = curl.String()
result.Results[i].Ok = ok
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例12: ReadRemoteSettings
// ReadRemoteSettings returns the remote settings of each given set of
// relation/local unit/remote unit.
func (u *UniterAPI) ReadRemoteSettings(args params.RelationUnitPairs) (params.RelationSettingsResults, error) {
result := params.RelationSettingsResults{
Results: make([]params.RelationSettingsResult, len(args.RelationUnitPairs)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.RelationSettingsResults{}, err
}
for i, arg := range args.RelationUnitPairs {
relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.LocalUnit)
if err == nil {
remoteUnit := ""
remoteUnit, err = u.checkRemoteUnit(relUnit, arg.RemoteUnit)
if err == nil {
var settings map[string]interface{}
settings, err = relUnit.ReadSettings(remoteUnit)
if err == nil {
result.Results[i].Settings, err = convertRelationSettings(settings)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例13: GetPrincipal
// GetPrincipal returns the result of calling PrincipalName() and
// converting it to a tag, on each given unit.
func (u *UniterAPI) GetPrincipal(args params.Entities) (params.StringBoolResults, error) {
result := params.StringBoolResults{
Results: make([]params.StringBoolResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringBoolResults{}, err
}
for i, entity := range args.Entities {
err := common.ErrPerm
if canAccess(entity.Tag) {
var unit *state.Unit
unit, err = u.getUnit(entity.Tag)
if err == nil {
principal, ok := unit.PrincipalName()
if principal != "" {
result.Results[i].Result = names.UnitTag(principal)
}
result.Results[i].Ok = ok
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例14: CharmArchiveURL
// CharmArchiveURL returns the URL, corresponding to the charm archive
// (bundle) in the provider storage for each given charm URL, along
// with the DisableSSLHostnameVerification flag.
func (u *UniterAPI) CharmArchiveURL(args params.CharmURLs) (params.CharmArchiveURLResults, error) {
result := params.CharmArchiveURLResults{
Results: make([]params.CharmArchiveURLResult, len(args.URLs)),
}
// Get the SSL hostname verification environment setting.
envConfig, err := u.st.EnvironConfig()
if err != nil {
return result, err
}
// SSLHostnameVerification defaults to true, so we need to
// invert that, for backwards-compatibility (older versions
// will have DisableSSLHostnameVerification: false by default).
disableSSLHostnameVerification := !envConfig.SSLHostnameVerification()
for i, arg := range args.URLs {
curl, err := charm.ParseURL(arg.URL)
if err != nil {
err = common.ErrPerm
} else {
var sch *state.Charm
sch, err = u.st.Charm(curl)
if errors.IsNotFound(err) {
err = common.ErrPerm
}
if err == nil {
result.Results[i].Result = sch.BundleURL().String()
result.Results[i].DisableSSLHostnameVerification = disableSSLHostnameVerification
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例15: PublicAddress
// PublicAddress returns the public address for each given unit, if set.
func (u *UniterAPI) PublicAddress(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
err := common.ErrPerm
if canAccess(entity.Tag) {
var unit *state.Unit
unit, err = u.getUnit(entity.Tag)
if err == nil {
address, ok := unit.PublicAddress()
if ok {
result.Results[i].Result = address
} else {
err = common.NoAddressSetError(entity.Tag, "public")
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}