本文整理汇总了Golang中github.com/coreos/fleet/schema.Unit.DesiredState方法的典型用法代码示例。如果您正苦于以下问题:Golang Unit.DesiredState方法的具体用法?Golang Unit.DesiredState怎么用?Golang Unit.DesiredState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/fleet/schema.Unit
的用法示例。
在下文中一共展示了Unit.DesiredState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deployUnit
func (d *deployer) deployUnit(wantedUnit *schema.Unit) error {
currentUnit, err := d.fleetapi.Unit(wantedUnit.Name)
if err != nil {
return err
}
if currentUnit == nil {
err := d.fleetapi.CreateUnit(wantedUnit)
if err != nil {
return err
}
return nil
}
wuf := schema.MapSchemaUnitOptionsToUnitFile(wantedUnit.Options)
cuf := schema.MapSchemaUnitOptionsToUnitFile(currentUnit.Options)
if wuf.Hash() != cuf.Hash() {
log.Printf("INFO Service %s differs from the cluster version", wantedUnit.Name)
wantedUnit.DesiredState = "inactive"
err = d.fleetapi.DestroyUnit(wantedUnit.Name)
if err != nil {
return err
}
err = d.fleetapi.CreateUnit(wantedUnit)
if err != nil {
return err
}
}
return nil
}
示例2: mapJobToSchema
func mapJobToSchema(j *job.Job) (*schema.Unit, error) {
su := schema.Unit{
Name: j.Name,
FileHash: j.Unit.Hash().String(),
FileContents: encodeUnitContents(&j.Unit),
TargetMachineID: j.TargetMachineID,
}
if j.State != nil {
su.CurrentState = string(*(j.State))
}
if j.UnitState != nil {
su.Systemd = &schema.SystemdState{
LoadState: j.UnitState.LoadState,
ActiveState: j.UnitState.ActiveState,
SubState: j.UnitState.SubState,
}
if j.UnitState.MachineState != nil {
su.Systemd.MachineID = j.UnitState.MachineState.ID
}
}
if j.TargetState != nil {
su.DesiredState = string(*j.TargetState)
}
return &su, nil
}