Skip to content
Snippets Groups Projects
Commit 1636ecca authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Classes.

parent 7369fe2f
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,8 @@ type HostList struct{} ...@@ -20,6 +20,8 @@ type HostList struct{}
// list of all known puppet classes // list of all known puppet classes
type ClassList struct{} type ClassList struct{}
type PuppetClass struct{ name string }
// directory for a single host (machine) // directory for a single host (machine)
type Host struct{ hostname string } type Host struct{ hostname string }
...@@ -141,7 +143,32 @@ func (ClassList) Attr(ctx context.Context, a *fuse.Attr) error { ...@@ -141,7 +143,32 @@ func (ClassList) Attr(ctx context.Context, a *fuse.Attr) error {
return nil return nil
} }
func (ClassList) Lookup(ctx context.Context, name string) (fs.Node, error) {
for key, _ := range fetch.AllClasses {
if key == name {
return PuppetClass{name}, nil
}
}
return nil, syscall.ENOENT
}
func (ClassList) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
var dirents []fuse.Dirent
for key, _ := range fetch.AllClasses {
dirents = append(dirents, fuse.Dirent{Inode: 0, Name: key, Type: fuse.DT_Dir})
}
return dirents, nil
}
// -------------------------------------------------- // --------------------------------------------------
func (PuppetClass) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = 0
a.Mode = os.ModeDir | 0o555
return nil
}
// -------------------------------------------------- // --------------------------------------------------
// -------------------------------------------------- // --------------------------------------------------
// -------------------------------------------------- // --------------------------------------------------
...@@ -16,7 +16,7 @@ const apiurl = "https://chapman.lysator.liu.se/api/" ...@@ -16,7 +16,7 @@ const apiurl = "https://chapman.lysator.liu.se/api/"
// which classes a given host has // which classes a given host has
var hostClasses map[float64][]Puppetclass var hostClasses map[float64][]Puppetclass
var AllClasses map[string][]Puppetclass var AllClasses map[string]Puppetclass
// password for foreman access, TODO replace with API key // password for foreman access, TODO replace with API key
var password string var password string
...@@ -34,6 +34,7 @@ func Init(pw string) { ...@@ -34,6 +34,7 @@ func Init(pw string) {
password = pw password = pw
hostClasses = map[float64][]Puppetclass{} hostClasses = map[float64][]Puppetclass{}
AllClasses = map[string]Puppetclass{}
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
...@@ -48,7 +49,17 @@ func Init(pw string) { ...@@ -48,7 +49,17 @@ func Init(pw string) {
Hosts[record.Name] = Host{record} Hosts[record.Name] = Host{record}
} }
var m2 PuppetclassMessage
fff("puppetclasses", &m2)
for group, entries := range m2.Results {
log.Print("Handling ", group)
for _, entry := range entries {
// e := entry.(map[string]interface{})
AllClasses[entry.Name] = entry
}
}
} }
func fff (url string, message interface{}) { func fff (url string, message interface{}) {
......
...@@ -13,3 +13,9 @@ func (PuppetClass) Attr(ctx context.Context, a *fuse.Attr) error { ...@@ -13,3 +13,9 @@ func (PuppetClass) Attr(ctx context.Context, a *fuse.Attr) error {
a.Mode = os.ModeSymlink | 0o444 a.Mode = os.ModeSymlink | 0o444
return nil return nil
} }
func (c PuppetClass) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) {
return "../../../classes/" + c.Classname, nil
// return "[empty]", nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment