func (u *UpgraderAPI) oneAgentTools(tag string, agentVersion version.Number, env environs.Environ) (*tools.Tools, error) { if !u.authorizer.AuthOwner(tag) { return nil, common.ErrPerm } entity0, err := u.findEntity(tag) if err != nil { return nil, err } entity, ok := entity0.(state.AgentTooler) if !ok { return nil, common.NotSupportedError(tag, "agent tools") } existingTools, err := entity.AgentTools() if err != nil { return nil, err } requested := version.Binary{ Number: agentVersion, Series: existingTools.Version.Series, Arch: existingTools.Version.Arch, } // TODO(jam): Avoid searching the provider for every machine // that wants to upgrade. The information could just be cached // in state, or even in the API servers return environs.FindExactTools(env, requested) }
func (c *Client) findEntity(tag string) (state.Annotator, error) { entity0, err := c.api.state.FindEntity(tag) if err != nil { return nil, err } entity, ok := entity0.(state.Annotator) if !ok { return nil, common.NotSupportedError(tag, "annotations") } return entity, nil }
func (u *UpgraderAPI) findEntity(tag string) (state.AgentTooler, error) { entity0, err := u.st.FindEntity(tag) if err != nil { return nil, err } entity, ok := entity0.(state.AgentTooler) if !ok { return nil, common.NotSupportedError(tag, "agent tools") } return entity, nil }
func (api *API) getEntity(tag string) (result params.AgentGetEntitiesResult, err error) { // Allow only for the owner agent. // Note: having a bulk API call for this is utter madness, given that // this check means we can only ever return a single object. if !api.auth.AuthOwner(tag) { err = common.ErrPerm return } entity0, err := api.st.FindEntity(tag) if err != nil { return } entity, ok := entity0.(state.Lifer) if !ok { err = common.NotSupportedError(tag, "life cycles") return } result.Life = params.Life(entity.Life().String()) if machine, ok := entity.(*state.Machine); ok { result.Jobs = stateJobsToAPIParamsJobs(machine.Jobs()) } return }