本文整理汇总了Golang中github.com/juju/juju/apiserver/common.NewToolsSetter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewToolsSetter函数的具体用法?Golang NewToolsSetter怎么用?Golang NewToolsSetter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewToolsSetter函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewUpgraderAPI
// NewUpgraderAPI creates a new server-side UpgraderAPI facade.
func NewUpgraderAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*UpgraderAPI, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
getCanReadWrite := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
env, err := st.Model()
if err != nil {
return nil, err
}
urlGetter := common.NewToolsURLGetter(env.UUID(), st)
configGetter := stateenvirons.EnvironConfigGetter{st}
return &UpgraderAPI{
ToolsGetter: common.NewToolsGetter(st, configGetter, st, urlGetter, getCanReadWrite),
ToolsSetter: common.NewToolsSetter(st, getCanReadWrite),
st: st,
resources: resources,
authorizer: authorizer,
}, nil
}
示例2: TestToolsSetError
func (s *toolsSuite) TestToolsSetError(c *gc.C) {
getCanWrite := func() (common.AuthFunc, error) {
return nil, fmt.Errorf("splat")
}
ts := common.NewToolsSetter(s.State, getCanWrite)
args := params.EntitiesVersion{
AgentTools: []params.EntityVersion{{
Tag: "machine-42",
Tools: ¶ms.Version{
Version: current,
},
}},
}
result, err := ts.SetTools(args)
c.Assert(err, gc.ErrorMatches, "splat")
c.Assert(result.Results, gc.HasLen, 1)
}
示例3: NewUpgraderAPI
// NewUpgraderAPI creates a new client-side UpgraderAPI facade.
func NewUpgraderAPI(
st *state.State,
resources *common.Resources,
authorizer common.Authorizer,
) (*UpgraderAPI, error) {
if !authorizer.AuthMachineAgent() {
return nil, common.ErrPerm
}
getCanReadWrite := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
return &UpgraderAPI{
ToolsGetter: common.NewToolsGetter(st, getCanReadWrite),
ToolsSetter: common.NewToolsSetter(st, getCanReadWrite),
st: st,
resources: resources,
authorizer: authorizer,
}, nil
}
示例4: NewUnitUpgraderAPI
// NewUnitUpgraderAPI creates a new server-side UnitUpgraderAPI facade.
func NewUnitUpgraderAPI(
st *state.State,
resources facade.Resources,
authorizer facade.Authorizer,
) (*UnitUpgraderAPI, error) {
if !authorizer.AuthUnitAgent() {
return nil, common.ErrPerm
}
getCanWrite := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
return &UnitUpgraderAPI{
ToolsSetter: common.NewToolsSetter(st, getCanWrite),
st: st,
resources: resources,
authorizer: authorizer,
}, nil
}
示例5: TestSetTools
func (s *toolsSuite) TestSetTools(c *gc.C) {
getCanWrite := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return tag == names.NewMachineTag("0") || tag == names.NewMachineTag("42")
}, nil
}
ts := common.NewToolsSetter(s.State, getCanWrite)
c.Assert(ts, gc.NotNil)
err := s.machine0.SetAgentVersion(current)
c.Assert(err, jc.ErrorIsNil)
args := params.EntitiesVersion{
AgentTools: []params.EntityVersion{{
Tag: "machine-0",
Tools: ¶ms.Version{
Version: current,
},
}, {
Tag: "machine-1",
Tools: ¶ms.Version{
Version: current,
},
}, {
Tag: "machine-42",
Tools: ¶ms.Version{
Version: current,
},
}},
}
result, err := ts.SetTools(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Results, gc.HasLen, 3)
c.Assert(result.Results[0].Error, gc.IsNil)
agentTools, err := s.machine0.AgentTools()
c.Assert(err, jc.ErrorIsNil)
c.Assert(agentTools.Version, gc.DeepEquals, current)
c.Assert(result.Results[1].Error, gc.DeepEquals, apiservertesting.ErrUnauthorized)
c.Assert(result.Results[2].Error, gc.DeepEquals, apiservertesting.NotFoundError("machine 42"))
}