Skip to content

Commit

Permalink
Add package (pkg) resource
Browse files Browse the repository at this point in the history
This is based on PackageKit, which means events, *and* we automatically
get support for any of the backends that PackageKit supports. This means
dpkg, and rpm are both first class citizens! Many other backends will
surely work, although thorough testing is left as an exercise to the
reader, or to someone who would like to write more test cases!

Unfortunately at the moment, there are a few upstream PackageKit bugs
which cause us issues, but those have been apparently resolved upstream.
If you experience issues with an old version of PackageKit, test if it
is working correctly before blaming mgmt :)

In parallel, mgmt might increase the testing surface for PackageKit, so
hopefully this makes it more robust for everyone involved!

Lastly, I'd like to point out that many great things that are typically
used for servers do start in the GNOME desktop world. Help support your
GNOME GNU/Linux desktop today!
  • Loading branch information
purpleidea committed Feb 23, 2016
1 parent 82ff342 commit 3b5678d
Show file tree
Hide file tree
Showing 9 changed files with 937 additions and 1 deletion.
14 changes: 14 additions & 0 deletions config.go
Expand Up @@ -45,6 +45,7 @@ type GraphConfig struct {
Graph string `yaml:"graph"`
Resources struct {
Noop []NoopRes `yaml:"noop"`
Pkg []PkgRes `yaml:"pkg"`
File []FileRes `yaml:"file"`
Svc []SvcRes `yaml:"svc"`
Exec []ExecRes `yaml:"exec"`
Expand Down Expand Up @@ -94,12 +95,14 @@ func ParseConfigFromFile(filename string) *GraphConfig {
func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO *EtcdWObject) bool {

var NoopMap = make(map[string]*Vertex)
var PkgMap = make(map[string]*Vertex)
var FileMap = make(map[string]*Vertex)
var SvcMap = make(map[string]*Vertex)
var ExecMap = make(map[string]*Vertex)

var lookup = make(map[string]map[string]*Vertex)
lookup["noop"] = NoopMap
lookup["pkg"] = PkgMap
lookup["file"] = FileMap
lookup["svc"] = SvcMap
lookup["exec"] = ExecMap
Expand All @@ -121,6 +124,17 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
keep = append(keep, v) // append
}

for _, t := range config.Resources.Pkg {
obj := NewPkgRes(t.Name, t.State, false, false, false)
v := g.GetVertexMatch(obj)
if v == nil { // no match found
v = NewVertex(obj)
g.AddVertex(v) // call standalone in case not part of an edge
}
PkgMap[obj.Name] = v // used for constructing edges
keep = append(keep, v) // append
}

for _, t := range config.Resources.File {
// XXX: should we export based on a @@ prefix, or a metaparam
// like exported => true || exported => (host pattern)||(other pattern?)
Expand Down
7 changes: 7 additions & 0 deletions examples/pkg1.yaml
@@ -0,0 +1,7 @@
---
graph: mygraph
resources:
pkg:
- name: powertop
state: installed
edges: []
7 changes: 7 additions & 0 deletions examples/pkg2.yaml
@@ -0,0 +1,7 @@
---
graph: mygraph
resources:
pkg:
- name: powertop
state: uninstalled
edges: []
20 changes: 20 additions & 0 deletions misc.go
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"encoding/base64"
"encoding/gob"
"github.com/godbus/dbus"
"path"
"strings"
"time"
Expand Down Expand Up @@ -120,3 +121,22 @@ func TimeAfterOrBlock(t int) <-chan time.Time {
}
return time.After(time.Duration(t) * time.Second)
}

// making using the private bus usable, should be upstream:
// TODO: https://github.com/godbus/dbus/issues/15
func SystemBusPrivateUsable() (conn *dbus.Conn, err error) {
conn, err = dbus.SystemBusPrivate()
if err != nil {
return nil, err
}
if err = conn.Auth(nil); err != nil {
conn.Close()
conn = nil
return
}
if err = conn.Hello(); err != nil {
conn.Close()
conn = nil
}
return conn, nil // success
}

0 comments on commit 3b5678d

Please sign in to comment.