Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetctl: list-unit-files fully populated for global units #1576

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions fleetctl/list_unit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,51 @@ func mapTargetField(u schema.Unit, full bool) string {
return machineFullLegend(*ms, full)
}

func mapStateField(u schema.Unit, full bool) string {
if suToGlobal(u) {
states, err := cAPI.UnitStates()
if err != nil {
return "-"
}
var (
inactive int
loaded int
launched int
currentStates []string
)
for _, state := range states {
if state.Name == u.Name {
if (state.SystemdActiveState == "active") || (state.SystemdSubState == "running") {
launched++
continue
}
if state.SystemdLoadState == "loaded" {
loaded++
continue
}
inactive++
}
}
if launched != 0 {
s := fmt.Sprintf("launched(%d)", launched)
currentStates = append(currentStates, s)
}
if loaded != 0 {
s := fmt.Sprintf("loaded(%d)", loaded)
currentStates = append(currentStates, s)
}
if inactive != 0 {
s := fmt.Sprintf("inactive(%d)", inactive)
currentStates = append(currentStates, s)
}
return strings.Join(currentStates, " ")
}
if u.CurrentState == "" {
return "-"
}
return u.CurrentState
}

var (
listUnitFilesFieldsFlag string
cmdListUnitFiles = &Command{
Expand All @@ -67,12 +112,7 @@ var (
},
"target": mapTargetField,
"tmachine": mapTargetField,
"state": func(u schema.Unit, full bool) string {
if suToGlobal(u) || u.CurrentState == "" {
return "-"
}
return u.CurrentState
},
"state": mapStateField,
"hash": func(u schema.Unit, full bool) string {
uf := schema.MapSchemaUnitOptionsToUnitFile(u.Options)
if !full {
Expand Down