本文整理汇总了Golang中github.com/juju/juju/apiserver/params.Life函数的典型用法代码示例。如果您正苦于以下问题:Golang Life函数的具体用法?Golang Life怎么用?Golang Life使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Life函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateAllMachines
// updateAllMachines finds all machines and resets the stored state address
// in each of them. The address does not include the port.
func updateAllMachines(apiState *api.State, stateAddr string) error {
client := apiState.Client()
status, err := client.Status(nil)
if err != nil {
return errors.Annotate(err, "cannot get status")
}
pendingMachineCount := 0
done := make(chan error)
for _, machineStatus := range status.Machines {
// A newly resumed state server requires no updating, and more
// than one state server is not yet support by this plugin.
if machineStatus.HasVote || machineStatus.WantsVote || params.Life(machineStatus.Life) == params.Dead {
continue
}
pendingMachineCount++
machine := machineStatus
go func() {
err := runMachineUpdate(client, machine.Id, setAgentAddressScript(stateAddr))
if err != nil {
logger.Errorf("failed to update machine %s: %v", machine.Id, err)
} else {
progress("updated machine %s", machine.Id)
}
done <- err
}()
}
err = nil
for ; pendingMachineCount > 0; pendingMachineCount-- {
if updateErr := <-done; updateErr != nil && err == nil {
err = errors.Annotate(updateErr, "machine update failed")
}
}
return err
}
示例2: ModelInfo
// ModelInfo returns information about the current model.
func (c *Client) ModelInfo() (params.ModelInfo, error) {
if err := c.checkCanWrite(); err != nil {
return params.ModelInfo{}, err
}
state := c.api.stateAccessor
conf, err := state.ModelConfig()
if err != nil {
return params.ModelInfo{}, err
}
model, err := state.Model()
if err != nil {
return params.ModelInfo{}, err
}
info := params.ModelInfo{
DefaultSeries: config.PreferredSeries(conf),
CloudTag: names.NewCloudTag(model.Cloud()).String(),
CloudRegion: model.CloudRegion(),
ProviderType: conf.Type(),
Name: conf.Name(),
UUID: model.UUID(),
OwnerTag: model.Owner().String(),
Life: params.Life(model.Life().String()),
}
if tag, ok := model.CloudCredential(); ok {
info.CloudCredentialTag = tag.String()
}
return info, nil
}
示例3: oneLife
func (lg *LifeGetter) oneLife(tag names.Tag) (params.Life, error) {
entity0, err := lg.st.FindEntity(tag)
if err != nil {
return "", err
}
entity, ok := entity0.(state.Lifer)
if !ok {
return "", NotSupportedError(tag, "life cycles")
}
return params.Life(entity.Life().String()), nil
}
示例4: EnvironInfo
func (m *mockClient) EnvironInfo() (params.UndertakerEnvironInfoResult, error) {
defer m.mockCall("EnvironInfo")
result := params.UndertakerEnvironInfo{
Life: params.Life(m.mockEnviron.Life.String()),
UUID: m.mockEnviron.UUID,
Name: "dummy",
GlobalName: "bob/dummy",
IsSystem: m.mockEnviron.IsSystem,
TimeOfDeath: m.mockEnviron.TimeOfDeath,
}
return params.UndertakerEnvironInfoResult{Result: result}, nil
}
示例5: TestLifeNotFound
func (*FacadeSuite) TestLifeNotFound(c *gc.C) {
backend := &mockBackend{}
facade, err := lifeflag.NewFacade(backend, nil, auth(true))
c.Assert(err, jc.ErrorIsNil)
results, err := facade.Life(modelEntity())
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
result := results.Results[0]
c.Check(result.Life, gc.Equals, params.Life(""))
c.Check(result.Error, jc.Satisfies, params.IsCodeNotFound)
}
示例6: TestLifeAuthFailure
func (*FacadeSuite) TestLifeAuthFailure(c *gc.C) {
backend := &mockBackend{}
facade, err := lifeflag.NewFacade(backend, nil, auth(true))
c.Assert(err, jc.ErrorIsNil)
results, err := facade.Life(entities("unit-foo-1"))
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
result := results.Results[0]
c.Check(result.Life, gc.Equals, params.Life(""))
c.Check(result.Error, jc.Satisfies, params.IsCodeUnauthorized)
}
示例7: modelStatus
func (c *ModelStatusAPI) modelStatus(tag string) (params.ModelStatus, error) {
var status params.ModelStatus
modelTag, err := names.ParseModelTag(tag)
if err != nil {
return status, errors.Trace(err)
}
st := c.backend
if modelTag != c.backend.ModelTag() {
if st, err = c.backend.ForModel(modelTag); err != nil {
return status, errors.Trace(err)
}
defer st.Close()
}
model, err := st.Model()
if err != nil {
return status, errors.Trace(err)
}
if err := c.modelAuthCheck(modelTag, model.Owner()); err != nil {
return status, errors.Trace(err)
}
machines, err := st.AllMachines()
if err != nil {
return status, errors.Trace(err)
}
var hostedMachines []Machine
for _, m := range machines {
if !m.IsManager() {
hostedMachines = append(hostedMachines, m)
}
}
applications, err := st.AllApplications()
if err != nil {
return status, errors.Trace(err)
}
modelMachines, err := ModelMachineInfo(st)
if err != nil {
return status, errors.Trace(err)
}
return params.ModelStatus{
ModelTag: tag,
OwnerTag: model.Owner().String(),
Life: params.Life(model.Life().String()),
HostedMachineCount: len(hostedMachines),
ApplicationCount: len(applications),
Machines: modelMachines,
}, nil
}
示例8: updated
func (svc *backingService) updated(st *State, store *multiwatcher.Store, id interface{}) error {
if svc.CharmURL == nil {
return errors.Errorf("charm url is nil")
}
env, err := st.Environment()
if err != nil {
return errors.Trace(err)
}
info := ¶ms.ServiceInfo{
Name: svc.Name,
Exposed: svc.Exposed,
CharmURL: svc.CharmURL.String(),
OwnerTag: svc.fixOwnerTag(env),
Life: params.Life(svc.Life.String()),
MinUnits: svc.MinUnits,
}
oldInfo := store.Get(info.EntityId())
needConfig := false
if oldInfo == nil {
// We're adding the entry for the first time,
// so fetch the associated child documents.
c, err := readConstraints(st, serviceGlobalKey(svc.Name))
if err != nil {
return err
}
info.Constraints = c
needConfig = true
} else {
// The entry already exists, so preserve the current status.
oldInfo := oldInfo.(*params.ServiceInfo)
info.Constraints = oldInfo.Constraints
if info.CharmURL == oldInfo.CharmURL {
// The charm URL remains the same - we can continue to
// use the same config settings.
info.Config = oldInfo.Config
} else {
// The charm URL has changed - we need to fetch the
// settings from the new charm's settings doc.
needConfig = true
}
}
if needConfig {
var err error
info.Config, _, err = readSettingsDoc(st, serviceSettingsKey(svc.Name, svc.CharmURL))
if err != nil {
return err
}
}
store.Update(info)
return nil
}
示例9: modelStatus
func (c *ControllerAPI) modelStatus(tag string) (params.ModelStatus, error) {
var status params.ModelStatus
modelTag, err := names.ParseModelTag(tag)
if err != nil {
return status, errors.Trace(err)
}
st, err := c.state.ForModel(modelTag)
if err != nil {
return status, errors.Trace(err)
}
defer st.Close()
machines, err := st.AllMachines()
if err != nil {
return status, errors.Trace(err)
}
var hostedMachines []*state.Machine
for _, m := range machines {
if !m.IsManager() {
hostedMachines = append(hostedMachines, m)
}
}
applications, err := st.AllApplications()
if err != nil {
return status, errors.Trace(err)
}
model, err := st.Model()
if err != nil {
return status, errors.Trace(err)
}
if err != nil {
return status, errors.Trace(err)
}
modelMachines, err := common.ModelMachineInfo(common.NewModelManagerBackend(st))
if err != nil {
return status, errors.Trace(err)
}
return params.ModelStatus{
ModelTag: tag,
OwnerTag: model.Owner().String(),
Life: params.Life(model.Life().String()),
HostedMachineCount: len(hostedMachines),
ApplicationCount: len(applications),
Machines: modelMachines,
}, nil
}
示例10: TestMachineCallsLife
func (s *InstancePollerSuite) TestMachineCallsLife(c *gc.C) {
// We have tested separately the Life method, here we just check
// it's called internally.
var called int
expectedResults := params.LifeResults{
Results: []params.LifeResult{{Life: "working"}},
}
apiCaller := successAPICaller(c, "Life", entitiesArgs, expectedResults, &called)
api := instancepoller.NewAPI(apiCaller)
m, err := api.Machine(names.NewMachineTag("42"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
c.Assert(m.Life(), gc.Equals, params.Life("working"))
c.Assert(m.Id(), gc.Equals, "42")
}
示例11: TestLifeBadEntity
func (*FacadeSuite) TestLifeBadEntity(c *gc.C) {
backend := &mockBackend{}
facade, err := lifeflag.NewFacade(backend, nil, auth(true))
c.Assert(err, jc.ErrorIsNil)
results, err := facade.Life(entities("archibald snookums"))
c.Check(err, jc.ErrorIsNil)
c.Assert(results.Results, gc.HasLen, 1)
result := results.Results[0]
c.Check(result.Life, gc.Equals, params.Life(""))
// TODO(fwereade): this is DUMB. should just be a parse error.
// but I'm not fixing the underlying implementation as well.
c.Check(result.Error, jc.Satisfies, params.IsCodeUnauthorized)
}
示例12: environStatus
func (c *ControllerAPI) environStatus(tag string) (params.EnvironmentStatus, error) {
var status params.EnvironmentStatus
envTag, err := names.ParseEnvironTag(tag)
if err != nil {
return status, errors.Trace(err)
}
st, err := c.state.ForEnviron(envTag)
if err != nil {
return status, errors.Trace(err)
}
defer st.Close()
machines, err := st.AllMachines()
if err != nil {
return status, errors.Trace(err)
}
var hostedMachines []*state.Machine
for _, m := range machines {
if !m.IsManager() {
hostedMachines = append(hostedMachines, m)
}
}
services, err := st.AllServices()
if err != nil {
return status, errors.Trace(err)
}
env, err := st.Environment()
if err != nil {
return status, errors.Trace(err)
}
if err != nil {
return status, errors.Trace(err)
}
return params.EnvironmentStatus{
EnvironTag: tag,
OwnerTag: env.Owner().String(),
Life: params.Life(env.Life().String()),
HostedMachineCount: len(hostedMachines),
ServiceCount: len(services),
}, nil
}
示例13: ModelInfo
// ModelInfo returns information on the model needed by the undertaker worker.
func (u *UndertakerAPI) ModelInfo() (params.UndertakerModelInfoResult, error) {
result := params.UndertakerModelInfoResult{}
env, err := u.st.Model()
if err != nil {
return result, errors.Trace(err)
}
result.Result = params.UndertakerModelInfo{
UUID: env.UUID(),
GlobalName: env.Owner().String() + "/" + env.Name(),
Name: env.Name(),
IsSystem: u.st.IsController(),
Life: params.Life(env.Life().String()),
}
return result, nil
}
示例14: prepareRelationResult
func (u *UniterAPI) prepareRelationResult(rel *state.Relation, unit *state.Unit) (params.RelationResult, error) {
nothing := params.RelationResult{}
ep, err := rel.Endpoint(unit.ServiceName())
if err != nil {
// An error here means the unit's service is not part of the
// relation.
return nothing, err
}
return params.RelationResult{
Id: rel.Id(),
Key: rel.String(),
Life: params.Life(rel.Life().String()),
Endpoint: params.Endpoint{
ServiceName: ep.ServiceName,
Relation: ep.Relation,
},
}, nil
}
示例15: prepareRelationResult
func (u *UniterAPIV3) prepareRelationResult(rel *state.Relation, unit *state.Unit) (params.RelationResult, error) {
nothing := params.RelationResult{}
ep, err := rel.Endpoint(unit.ApplicationName())
if err != nil {
// An error here means the unit's service is not part of the
// relation.
return nothing, err
}
return params.RelationResult{
Id: rel.Id(),
Key: rel.String(),
Life: params.Life(rel.Life().String()),
Endpoint: multiwatcher.Endpoint{
ApplicationName: ep.ApplicationName,
Relation: multiwatcher.NewCharmRelation(ep.Relation),
},
}, nil
}