本文整理汇总了Golang中github.com/juju/juju/api/agent.NewState函数的典型用法代码示例。如果您正苦于以下问题:Golang NewState函数的具体用法?Golang NewState怎么用?Golang NewState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewState函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newWorker
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
cfg := a.CurrentConfig()
// Grab the tag and ensure that it's for a machine.
tag, ok := cfg.Tag().(names.MachineTag)
if !ok {
return nil, errors.New("this manifold may only be used inside a machine agent")
}
// Get the machine agent's jobs.
// TODO(fwereade): this functionality should be on the
// deployer facade instead.
agentFacade := apiagent.NewState(apiCaller)
entity, err := agentFacade.Entity(tag)
if err != nil {
return nil, err
}
var isModelManager bool
for _, job := range entity.Jobs() {
if job == multiwatcher.JobManageModel {
isModelManager = true
break
}
}
if !isModelManager {
return nil, dependency.ErrMissing
}
return NewResumer(apiresumer.NewAPI(apiCaller)), nil
}
开发者ID:makyo,项目名称:juju,代码行数:30,代码来源:manifold.go
示例2: TestEntitySetPassword
func (s *machineSuite) TestEntitySetPassword(c *gc.C) {
entity, err := apiagent.NewState(s.st).Entity(s.machine.Tag())
c.Assert(err, jc.ErrorIsNil)
err = entity.SetPassword("foo")
c.Assert(err, gc.ErrorMatches, "password is only 3 bytes long, and is not a valid Agent password")
err = entity.SetPassword("foo-12345678901234567890")
c.Assert(err, jc.ErrorIsNil)
err = entity.ClearReboot()
c.Assert(err, jc.ErrorIsNil)
err = s.machine.Refresh()
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.machine.PasswordValid("bar"), jc.IsFalse)
c.Assert(s.machine.PasswordValid("foo-12345678901234567890"), jc.IsTrue)
// Check that we cannot log in to mongo with the correct password.
// This is because there's no mongo password set for s.machine,
// which has JobHostUnits
info := s.MongoInfo(c)
// TODO(dfc) this entity.Tag should return a Tag
tag, err := names.ParseTag(entity.Tag())
c.Assert(err, jc.ErrorIsNil)
info.Tag = tag
info.Password = "foo-12345678901234567890"
err = tryOpenState(s.State.ModelTag(), info)
c.Assert(errors.Cause(err), jc.Satisfies, errors.IsUnauthorized)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:28,代码来源:machine_test.go
示例3: newWorker
// newWorker trivially wraps NewWorker for use in a engine.AgentAPIManifold.
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
cfg := a.CurrentConfig()
// Grab the tag and ensure that it's for a machine.
tag, ok := cfg.Tag().(names.MachineTag)
if !ok {
return nil, errors.New("this manifold may only be used inside a machine agent")
}
// Get the machine agent's jobs.
entity, err := apiagent.NewState(apiCaller).Entity(tag)
if err != nil {
return nil, err
}
var isModelManager bool
for _, job := range entity.Jobs() {
if job == multiwatcher.JobManageModel {
isModelManager = true
break
}
}
if !isModelManager {
return nil, dependency.ErrMissing
}
return NewWorker(cfg)
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:manifold.go
示例4: TestIsMasterPermission
func (s *servingInfoSuite) TestIsMasterPermission(c *gc.C) {
st, _ := s.OpenAPIAsNewMachine(c)
_, err := apiagent.NewState(st).IsMaster()
c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
Message: "permission denied",
Code: "unauthorized access",
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:machine_test.go
示例5: manifoldStart
// manifoldStart creates a *Tracker given a base.APICaller.
func manifoldStart(apiCaller base.APICaller) (worker.Worker, error) {
w, err := NewTracker(Config{
Observer: agent.NewState(apiCaller),
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
开发者ID:exekias,项目名称:juju,代码行数:10,代码来源:manifold.go
示例6: SetUpTest
func (s *modelSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
conn, _ := s.OpenAPIAsNewMachine(c)
agentAPI := apiagent.NewState(conn)
c.Assert(agentAPI, gc.NotNil)
s.ModelWatcherTests = apitesting.NewModelWatcherTests(
agentAPI, s.BackingState, apitesting.NoSecrets)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:10,代码来源:proxyupdater_test.go
示例7: ServingInfoSetterManifold
// ServingInfoSetterManifold defines a simple start function which
// runs after the API connection has come up. If the machine agent is
// a controller, it grabs the state serving info over the API and
// records it to agent configuration, and then stops.
func ServingInfoSetterManifold(config ServingInfoSetterConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
// Get the agent.
var agent coreagent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
// Grab the tag and ensure that it's for a machine.
tag, ok := agent.CurrentConfig().Tag().(names.MachineTag)
if !ok {
return nil, errors.New("agent's tag is not a machine tag")
}
// Get API connection.
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
apiState := apiagent.NewState(apiCaller)
// If the machine needs State, grab the state serving info
// over the API and write it to the agent configuration.
machine, err := apiState.Entity(tag)
if err != nil {
return nil, err
}
for _, job := range machine.Jobs() {
if job.NeedsState() {
info, err := apiState.StateServingInfo()
if err != nil {
return nil, errors.Errorf("cannot get state serving info: %v", err)
}
err = agent.ChangeConfig(func(config coreagent.ConfigSetter) error {
config.SetStateServingInfo(info)
return nil
})
if err != nil {
return nil, err
}
}
}
// All is well - we're done (no actual worker is actually returned).
return nil, dependency.ErrUninstall
},
}
}
开发者ID:makyo,项目名称:juju,代码行数:57,代码来源:servinginfo_setter.go
示例8: isModelManager
// isModelManager returns whether the agent has JobManageModel,
// or an error.
func isModelManager(a agent.Agent, apiCaller base.APICaller) (bool, error) {
agentFacade := apiagent.NewState(apiCaller)
entity, err := agentFacade.Entity(a.CurrentConfig().Tag())
if err != nil {
return false, errors.Trace(err)
}
for _, job := range entity.Jobs() {
if job == multiwatcher.JobManageModel {
return true, nil
}
}
return false, nil
}
开发者ID:bac,项目名称:juju,代码行数:15,代码来源:manifold.go
示例9: TestMachineEntity
func (s *machineSuite) TestMachineEntity(c *gc.C) {
tag := names.NewMachineTag("42")
m, err := apiagent.NewState(s.st).Entity(tag)
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
c.Assert(m, gc.IsNil)
m, err = apiagent.NewState(s.st).Entity(s.machine.Tag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.Tag(), gc.Equals, s.machine.Tag().String())
c.Assert(m.Life(), gc.Equals, params.Alive)
c.Assert(m.Jobs(), gc.DeepEquals, []multiwatcher.MachineJob{multiwatcher.JobHostUnits})
err = s.machine.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
err = s.machine.Remove()
c.Assert(err, jc.ErrorIsNil)
m, err = apiagent.NewState(s.st).Entity(s.machine.Tag())
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("machine %s not found", s.machine.Id()))
c.Assert(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(m, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:23,代码来源:machine_test.go
示例10: TestUnitEntity
func (s *unitSuite) TestUnitEntity(c *gc.C) {
tag := names.NewUnitTag("wordpress/1")
m, err := apiagent.NewState(s.st).Entity(tag)
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
c.Assert(m, gc.IsNil)
m, err = apiagent.NewState(s.st).Entity(s.unit.Tag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(m.Tag(), gc.Equals, s.unit.Tag().String())
c.Assert(m.Life(), gc.Equals, params.Alive)
c.Assert(m.Jobs(), gc.HasLen, 0)
err = s.unit.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
err = s.unit.Remove()
c.Assert(err, jc.ErrorIsNil)
m, err = apiagent.NewState(s.st).Entity(s.unit.Tag())
c.Assert(err, gc.ErrorMatches, fmt.Sprintf("unit %q not found", s.unit.Name()))
c.Assert(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(m, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:23,代码来源:unit_test.go
示例11: TestIsMaster
func (s *servingInfoSuite) TestIsMaster(c *gc.C) {
calledIsMaster := false
var fakeMongoIsMaster = func(session *mgo.Session, m mongo.WithAddresses) (bool, error) {
calledIsMaster = true
return true, nil
}
s.PatchValue(&apiserveragent.MongoIsMaster, fakeMongoIsMaster)
st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
expected := true
result, err := apiagent.NewState(st).IsMaster()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.Equals, expected)
c.Assert(calledIsMaster, jc.IsTrue)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:16,代码来源:machine_test.go
示例12: Manifold
// Manifold returns a dependency manifold that runs a deployer worker,
// using the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {
// newWorker trivially wraps NewDeployer for use in a util.PostUpgradeManifold.
//
// It's not tested at the moment, because the scaffolding
// necessary is too unwieldy/distracting to introduce at this point.
newWorker := func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
cfg := a.CurrentConfig()
// Grab the tag and ensure that it's for a machine.
tag, ok := cfg.Tag().(names.MachineTag)
if !ok {
return nil, errors.New("agent's tag is not a machine tag")
}
// Get the machine agent's jobs.
// TODO(fwereade): this functionality should be on the
// deployer facade instead.
agentFacade := apiagent.NewState(apiCaller)
entity, err := agentFacade.Entity(tag)
if err != nil {
return nil, err
}
var isUnitHoster bool
for _, job := range entity.Jobs() {
if job == multiwatcher.JobHostUnits {
isUnitHoster = true
break
}
}
if !isUnitHoster {
return nil, dependency.ErrUninstall
}
deployerFacade := apideployer.NewState(apiCaller)
context := config.NewDeployContext(deployerFacade, cfg)
w, err := NewDeployer(deployerFacade, context)
if err != nil {
return nil, errors.Annotate(err, "cannot start unit agent deployer worker")
}
return w, nil
}
return util.PostUpgradeManifold(config.PostUpgradeManifoldConfig, newWorker)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:48,代码来源:manifold.go
示例13: TestClearReboot
func (s *machineSuite) TestClearReboot(c *gc.C) {
err := s.machine.SetRebootFlag(true)
c.Assert(err, jc.ErrorIsNil)
rFlag, err := s.machine.GetRebootFlag()
c.Assert(err, jc.ErrorIsNil)
c.Assert(rFlag, jc.IsTrue)
entity, err := apiagent.NewState(s.st).Entity(s.machine.Tag())
c.Assert(err, jc.ErrorIsNil)
err = entity.ClearReboot()
c.Assert(err, jc.ErrorIsNil)
rFlag, err = s.machine.GetRebootFlag()
c.Assert(err, jc.ErrorIsNil)
c.Assert(rFlag, jc.IsFalse)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:17,代码来源:machine_test.go
示例14: Manifold
// Manifold returns a dependency manifold that runs a log forwarding
// worker, using the resource names defined in the supplied config.
func Manifold(config ManifoldConfig) dependency.Manifold {
openLogStream := config.OpenLogStream
if openLogStream == nil {
openLogStream = func(caller base.APICaller, cfg params.LogStreamConfig, controllerUUID string) (LogStream, error) {
return logstream.Open(caller, cfg, controllerUUID)
}
}
openForwarder := config.OpenLogForwarder
if openForwarder == nil {
openForwarder = NewLogForwarder
}
return dependency.Manifold{
Inputs: []string{
config.StateName, // ...just to force it to run only on the controller.
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
agentFacade := apiagent.NewState(apiCaller)
controllerCfg, err := agentFacade.ControllerConfig()
if err != nil {
return nil, errors.Annotate(err, "cannot read controller config")
}
orchestrator, err := newOrchestratorForController(OrchestratorArgs{
ControllerUUID: controllerCfg.ControllerUUID(),
LogForwardConfig: agentFacade,
Caller: apiCaller,
Sinks: config.Sinks,
OpenLogStream: openLogStream,
OpenLogForwarder: openForwarder,
})
return orchestrator, errors.Annotate(err, "creating log forwarding orchestrator")
},
}
}
开发者ID:bac,项目名称:juju,代码行数:44,代码来源:manifold.go
示例15: TestStateServingInfo
func (s *servingInfoSuite) TestStateServingInfo(c *gc.C) {
st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
ssi := state.StateServingInfo{
PrivateKey: "some key",
Cert: "Some cert",
SharedSecret: "really, really secret",
APIPort: 33,
StatePort: 44,
}
expected := params.StateServingInfo{
PrivateKey: ssi.PrivateKey,
Cert: ssi.Cert,
SharedSecret: ssi.SharedSecret,
APIPort: ssi.APIPort,
StatePort: ssi.StatePort,
}
s.State.SetStateServingInfo(ssi)
info, err := apiagent.NewState(st).StateServingInfo()
c.Assert(err, jc.ErrorIsNil)
c.Assert(info, jc.DeepEquals, expected)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:22,代码来源:machine_test.go
示例16: newWorker
// newWorker trivially wraps NewDeployer for use in a engine.AgentApiManifold.
//
// It's not tested at the moment, because the scaffolding
// necessary is too unwieldy/distracting to introduce at this point.
func (config ManifoldConfig) newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
cfg := a.CurrentConfig()
// Grab the tag and ensure that it's for a machine.
tag, ok := cfg.Tag().(names.MachineTag)
if !ok {
return nil, errors.New("agent's tag is not a machine tag")
}
// Get the machine agent's jobs.
// TODO(fwereade): this functionality should be on the
// deployer facade instead.
agentFacade := apiagent.NewState(apiCaller)
entity, err := agentFacade.Entity(tag)
if err != nil {
return nil, err
}
var isUnitHoster bool
for _, job := range entity.Jobs() {
if job == multiwatcher.JobHostUnits {
isUnitHoster = true
break
}
}
if !isUnitHoster {
return nil, dependency.ErrUninstall
}
deployerFacade := apideployer.NewState(apiCaller)
context := config.NewDeployContext(deployerFacade, cfg)
w, err := NewDeployer(deployerFacade, context)
if err != nil {
return nil, errors.Annotate(err, "cannot start unit agent deployer worker")
}
return w, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:41,代码来源:manifold.go
示例17: Agent
// Agent returns a version of the state that provides
// functionality required by the agent code.
func (st *State) Agent() *agent.State {
return agent.NewState(st)
}
开发者ID:Pankov404,项目名称:juju,代码行数:5,代码来源:state.go
示例18: ServingInfoSetterManifold
// ServingInfoSetterManifold defines a simple start function which
// runs after the API connection has come up. If the machine agent is
// a controller, it grabs the state serving info over the API and
// records it to agent configuration, and then stops.
func ServingInfoSetterManifold(config ServingInfoSetterConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
// Get the agent.
var agent coreagent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
// Grab the tag and ensure that it's for a machine.
tag, ok := agent.CurrentConfig().Tag().(names.MachineTag)
if !ok {
return nil, errors.New("agent's tag is not a machine tag")
}
// Get API connection.
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
apiState := apiagent.NewState(apiCaller)
// If the machine needs State, grab the state serving info
// over the API and write it to the agent configuration.
if controller, err := isController(apiState, tag); err != nil {
return nil, errors.Annotate(err, "checking controller status")
} else if !controller {
// Not a controller, nothing to do.
return nil, dependency.ErrUninstall
}
info, err := apiState.StateServingInfo()
if err != nil {
return nil, errors.Annotate(err, "getting state serving info")
}
err = agent.ChangeConfig(func(config coreagent.ConfigSetter) error {
existing, hasInfo := config.StateServingInfo()
if hasInfo {
// Use the existing cert and key as they appear to
// have been already updated by the cert updater
// worker to have this machine's IP address as
// part of the cert. This changed cert is never
// put back into the database, so it isn't
// reflected in the copy we have got from
// apiState.
info.Cert = existing.Cert
info.PrivateKey = existing.PrivateKey
}
config.SetStateServingInfo(info)
return nil
})
if err != nil {
return nil, errors.Trace(err)
}
// All is well - we're done (no actual worker is actually returned).
return nil, dependency.ErrUninstall
},
}
}
开发者ID:bac,项目名称:juju,代码行数:68,代码来源:servinginfo_setter.go
示例19: Agent
func (f *fakeAPIConn) Agent() *apiagent.State {
return apiagent.NewState(f)
}
开发者ID:makyo,项目名称:juju,代码行数:3,代码来源:manifold_machine_test.go
示例20: ServingInfoSetterManifold
// ServingInfoSetterManifold defines a simple start function which
// runs after the API connection has come up. If the machine agent is
// a controller, it grabs the state serving info over the API and
// records it to agent configuration, and then stops.
func ServingInfoSetterManifold(config ServingInfoSetterConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
config.APICallerName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
// Get the agent.
var agent coreagent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
// Grab the tag and ensure that it's for a machine.
tag, ok := agent.CurrentConfig().Tag().(names.MachineTag)
if !ok {
return nil, errors.New("agent's tag is not a machine tag")
}
// Get API connection.
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, err
}
apiState := apiagent.NewState(apiCaller)
// If the machine needs State, grab the state serving info
// over the API and write it to the agent configuration.
machine, err := apiState.Entity(tag)
if err != nil {
return nil, err
}
existing, hasInfo := agent.CurrentConfig().StateServingInfo()
for _, job := range machine.Jobs() {
if job.NeedsState() {
info, err := apiState.StateServingInfo()
if err != nil {
return nil, errors.Errorf("cannot get state serving info: %v", err)
}
if hasInfo {
// Use the existing Cert as it may have been updated already
// by the cert updater worker to have this machine's IP address
// as part of the cert. This changed cert is never put back into
// the database, so it isn't reflected in the copy we have got
// from apiState.
info.Cert = existing.Cert
}
err = agent.ChangeConfig(func(config coreagent.ConfigSetter) error {
config.SetStateServingInfo(info)
return nil
})
if err != nil {
return nil, err
}
}
}
// All is well - we're done (no actual worker is actually returned).
return nil, dependency.ErrUninstall
},
}
}
开发者ID:kat-co,项目名称:juju,代码行数:66,代码来源:servinginfo_setter.go
注:本文中的github.com/juju/juju/api/agent.NewState函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论