本文整理匯總了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"))
}