本文整理汇总了Golang中github.com/juju/juju/state/apiserver/common.ServerError函数的典型用法代码示例。如果您正苦于以下问题:Golang ServerError函数的具体用法?Golang ServerError怎么用?Golang ServerError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ServerError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: SetRsyslogCert
// SetRsyslogCert sets the rsyslog CACert.
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
}
示例5: 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
}
示例6: 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
}
示例7: ActionFail
// ActionFail saves the result of a completed Action
func (u *UniterAPI) ActionFail(args params.ActionResult) (params.BoolResult, error) {
action, err := u.actionIfPermitted(args.ActionTag)
if err == nil {
err = action.Fail(args.Output)
}
return params.BoolResult{Error: common.ServerError(err), Result: err == nil}, err
}
示例8: UpdateSettings
// UpdateSettings persists all changes made to the local settings of
// all given pairs of relation and unit. Keys with empty values are
// considered a signal to delete these values.
func (u *UniterAPI) UpdateSettings(args params.RelationUnitsSettings) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.RelationUnits)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ErrorResults{}, err
}
for i, arg := range args.RelationUnits {
relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.Unit)
if err == nil {
var settings *state.Settings
settings, err = relUnit.Settings()
if err == nil {
for k, v := range arg.Settings {
if v == "" {
settings.Delete(k)
} else {
settings.Set(k, v)
}
}
_, err = settings.Write()
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例9: 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 networks []string
networks, 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].Networks = networks
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例10: 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
}
示例11: ConfigSettings
// ConfigSettings returns the complete set of service charm config
// settings available to each given unit.
func (u *UniterAPI) ConfigSettings(args params.Entities) (params.ConfigSettingsResults, error) {
result := params.ConfigSettingsResults{
Results: make([]params.ConfigSettingsResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ConfigSettingsResults{}, 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 {
var settings charm.Settings
settings, err = unit.ConfigSettings()
if err == nil {
result.Results[i].Settings = params.ConfigSettings(settings)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例12: 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
}
示例13: SetCharmURL
// SetCharmURL sets the charm URL for each given unit. An error will
// be returned if a unit is dead, or the charm URL is not know.
func (u *UniterAPI) SetCharmURL(args params.EntitiesCharmURL) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Entities)),
}
canAccess, err := u.accessUnit()
if err != nil {
return params.ErrorResults{}, 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 {
var curl *charm.URL
curl, err = charm.ParseURL(entity.CharmURL)
if err == nil {
err = unit.SetCharmURL(curl)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例14: 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.NewUnitTag(principal).String()
}
result.Results[i].Ok = ok
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例15: 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
}