chef

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2014 License: MIT Imports: 23 Imported by: 8

README

chef-golang Build Status

This is a Go API client for Opscode's Chef.

Installation

Use go get to install chef-golang:

go get github.com/marpaia/chef-golang

Unit tests

There is a helper script in test/support/start_server.sh that will setup a goiardi server primed with unit-testing data. there is also an example knife config and a script named test/support/chef_config.sh.

If you don't have a local ~/.chef/knife.rb you can simply run these 3 commands:

./test/support/start_server.sh
./test/support/chef_config.sh
go test -v

to shutdown the server run test/support/stop_server.sh

The goiardi Server is listening on port 8443 and the keys and config are copied to /tmp/goiardi. If you want to setup your own knife.rb and not use the provided one.

External dependencies

This project has no external dependencies other than the Go standard library.

Documentation

Like most every other Golang project, this projects documentation can be found on godoc at godoc.org/github.com/marpaia/chef-golang.

Examples

package main

import (
    "fmt"
    "os"

    "github.com/marpaia/chef-golang"
)

var findNode = "neo4j.example.org"
var findCookbook = "neo4j"
var findRole = "Neo4j"

func main() {
    c, err := chef.Connect()
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    c.SSLNoVerify = true

    // Print detailed information about a specific node
    node, ok, err := c.GetNode(findNode)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    if !ok {
        fmt.Println("\nCouldn't find that node!")
    } else {
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }

        fmt.Println("\nSystem info:", node.Name, "\n")
        fmt.Println("  [+] IP Address:", node.Info.IPAddress)
        fmt.Println("  [+] MAC Address:", node.Info.MACAddress)
        fmt.Println("  [+] Operating System:", node.Info.Platform)

        fmt.Println("\n  [+] Filesystem Info")
        for partition, info := range node.Info.Filesystem {
            if info.PercentUsed != "" {
                fmt.Println("    - ", partition, "is", info.PercentUsed, "utilized")
            }
        }

        fmt.Println("\n  [+] Roles")
        for _, role := range node.Info.Roles {
            fmt.Println("    - ", role)
        }

        fmt.Println()
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }
    }

    // Print detailed information about a specific cookbook
    cookbook, ok, err := c.GetCookbook(findCookbook)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    if !ok {
        fmt.Println("\nCouldn't find that cookbook!")
    } else {
        fmt.Println("\n\nCookbook info:", findCookbook)
        for _, version := range cookbook.Versions {
            currentVersion, ok, err := c.GetCookbookVersion(findCookbook, version.Version)
            if err != nil {
                fmt.Println("Error:", err)
                os.Exit(1)
            }
            if ok {
                if len(currentVersion.Files) > 0 {
                    fmt.Println("\n  [+]", findCookbook, currentVersion.Version, "Cookbook Files")
                    for _, cookbookFile := range currentVersion.Files {
                        fmt.Println("    - ", cookbookFile.Name)
                    }
                }
            }
        }

        fmt.Println()
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }
    }

    // Print detailed information about a specific role
    role, ok, err := c.GetRole(findRole)
    if err != nil {
        fmt.Println("Error:", err)
    }
    if !ok {
        fmt.Println("\nCouldn't find that role!")
    } else {
        fmt.Println("\n\nRole information:", role.Name)
        fmt.Println("\n[+] Runlist")
        for _, recipe := range role.RunList {
            fmt.Println("  - ", recipe)
        }
    }
}

Which will output something like this:

================================================================================
System info: neo4j.example.org

  [+] IP Address: 10.100.1.2
  [+] MAC Address: AA:BB:CC:DD:EE:FF
  [+] Operating System: centos

  [+] Filesystem Info
    -  /dev/vda is 46% utilized
    -  tmpfs is 1% utilized

  [+] Roles
    -  Base
    -  Neo4j

================================================================================

Cookbook info: neo4j

  [+] neo4j 0.1.6 Cookbook Files
    -  neo4j-server.properties
    -  neo4j-service
    -  neo4j-wrapper.conf

  [+] neo4j 0.1.5 Cookbook Files
    -  neo4j-service
    -  neo4j-wrapper.conf

  [+] neo4j 0.1.4 Cookbook Files
    -  neo4j-service

  [+] neo4j 0.1.3 Cookbook Files
    -  neo4j-service

  [+] neo4j 0.1.2 Cookbook Files
    -  neo4j-service

================================================================================

Role information: Neo4j

[+] Runlist
  -  recipe[yum]
  -  recipe[ldap]
  -  recipe[system]
  -  recipe[neo4j::server]
  -  recipe[neo4j::web-ui]

Contributing

Please contribute and help improve this project!

  • Fork the repo
  • Make sure the tests pass
  • Improve the code
  • Make sure your feature has test coverage
  • Make sure the tests pass
  • Submit a pull request

Documentation

Overview

This is a Go client for Opscode's Chef.

Obviously many of the unit tests require a functioning Chef installation in order to verify the results of API requests. Edit the `TEST_CONFIG.json` file with the appropriate endpoints and information, and run `go test -v`.

This project has no external dependencies other than the Go standard library.

Like most every other Golang project, this projects documentation can be found on godoc at http://godoc.org/github.com/marpaia/chef-golang

The following is an example of a simple Go tool that displays a small amount of information about a few different pieces of a Chef infrastructure:

package main

import (
    "fmt"
    "github.com/marpaia/chef-golang"
    "os"
)

var findNode = "neo4j.example.org"
var findCookbook = "neo4j"
var findRole = "Neo4j"

func main() {
    c, err := chef.Connect()
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    c.SSLNoVerify = true

    // Print detailed information about a specific node
    node, ok, err := c.GetNode(findNode)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    if !ok {
        fmt.Println("\nCouldn't find that node!")
    } else {
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }

        fmt.Println("\nSystem info:", node.Name, "\n")
        fmt.Println("  [+] IP Address:", node.Info.IPAddress)
        fmt.Println("  [+] MAC Address:", node.Info.MACAddress)
        fmt.Println("  [+] Operating System:", node.Info.Platform)

        fmt.Println("\n  [+] Filesystem Info")
        for partition, info := range node.Info.Filesystem {
            if info.PercentUsed != "" {
                fmt.Println("    - ", partition, "is", info.PercentUsed, "utilized")
            }
        }

        fmt.Println("\n  [+] Roles")
        for _, role := range node.Info.Roles {
            fmt.Println("    - ", role)
        }

        fmt.Println()
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }
    }

    // Print detailed information about a specific cookbook
    cookbook, ok, err := c.GetCookbook(findCookbook)
    if err != nil {
        fmt.Println("Error:", err)
        os.Exit(1)
    }
    if !ok {
        fmt.Println("\nCouldn't find that cookbook!")
    } else {
        fmt.Println("\n\nCookbook info:", findCookbook)
        for _, version := range cookbook.Versions {
            currentVersion, ok, err := c.GetCookbookVersion(findCookbook, version.Version)
            if err != nil {
                fmt.Println("Error:", err)
                os.Exit(1)
            }
            if ok {
                if len(currentVersion.Files) > 0 {
                    fmt.Println("\n  [+]", findCookbook, currentVersion.Version, "Cookbook Files")
                    for _, cookbookFile := range currentVersion.Files {
                        fmt.Println("    - ", cookbookFile.Name)
                    }
                }
            }
        }

        fmt.Println()
        for i := 0; i < 80; i++ {
            fmt.Print("=")
        }
    }

    // Print detailed information about a specific role
    role, ok, err := c.GetRole(findRole)
    if err != nil {
        fmt.Println("Error:", err)
    }
    if !ok {
        fmt.Println("\nCouldn't find that role!")
    } else {
        fmt.Println("\n\nRole information:", role.Name)
        fmt.Println("\n[+] Runlist")
        for _, recipe := range role.RunList {
            fmt.Println("  - ", recipe)
        }
    }
}

Which will output something like this:

================================================================================
System info: neo4j.example.org

  [+] IP Address: 10.100.1.2
  [+] MAC Address: AA:BB:CC:DD:EE:FF
  [+] Operating System: centos

  [+] Filesystem Info
    -  /dev/vda is 46% utilized
    -  tmpfs is 1% utilized

  [+] Roles
    -  Base
    -  Neo4j

================================================================================

Cookbook info: neo4j

  [+] neo4j 0.1.6 Cookbook Files
    -  neo4j-server.properties
    -  neo4j-service
    -  neo4j-wrapper.conf

  [+] neo4j 0.1.5 Cookbook Files
    -  neo4j-service
    -  neo4j-wrapper.conf

  [+] neo4j 0.1.4 Cookbook Files
    -  neo4j-service

  [+] neo4j 0.1.3 Cookbook Files
    -  neo4j-service

  [+] neo4j 0.1.2 Cookbook Files
    -  neo4j-service

================================================================================

Role information: Neo4j

[+] Runlist
  -  recipe[yum]
  -  recipe[ldap]
  -  recipe[system]
  -  recipe[neo4j::server]
  -  recipe[neo4j::web-ui]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chef

type Chef struct {
	Host         string
	Url          string
	Port         string
	Version      string
	Key          *rsa.PrivateKey
	UserId       string
	SSLNoVerify  bool
	Organization string
}

Chef is the type that contains all of the relevant information about a Chef server connection

func Connect

func Connect(filename ...string) (*Chef, error)

Connect looks for knife/chef configuration files and gather connection info automagically

func ConnectBuilder

func ConnectBuilder(host, port, version, userid, key string, organization string) (*Chef, error)

Given the appropriate connection parameters, ConnectChef returns a pointer to a Chef type so that you can call request methods on it

func (*Chef) Delete

func (chef *Chef) Delete(endpoint string, params map[string]string) (*http.Response, error)

Delete makes an authenticated DELETE request to the Chef server for the supplied endpoint

func (*Chef) Get

func (chef *Chef) Get(endpoint string) (*http.Response, error)

Get makes an authenticated HTTP request to the Chef server for the supplied endpoint

func (*Chef) GetClient

func (chef *Chef) GetClient(name string) (*Client, bool, error)

GetClient accept a string representing the client name and returns a Client type which illustrates various information about the client. It also returns a bool indicating whether or not the client was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

    client, ok, err := chef.GetClient("clientname")
    if err != nil {
        fmt.Println(err)
		   os.Exit(1)
    }
    if !ok {
        fmt.Println("Couldn't find that client!")
    } else {
        // do what you please with the "client" variable which is of the
        // *Chef.Client type
        fmt.Printf("%#v\n", client)
    }

func (*Chef) GetClients

func (chef *Chef) GetClients() (map[string]string, error)

chef.GetClients returns a map of client name's to client REST urls as well as an error indicating if the request was successful or not.

Usage:

clients, err := chef.GetClients()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "clients" variable which is map of client
// names to client REST urls
for client := range clients {
    fmt.Println("Client:", client)
}

func (*Chef) GetCookbook

func (chef *Chef) GetCookbook(name string) (*Cookbook, bool, error)

chef.GetCookbook returns a pointer to the chef.Cookbook type for a given string that represents a cookbook name. It also returns a bool indicating whether or not the client was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

cookbook, ok, err := chef.GetCookbook("apache")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that cookbook!")
} else {
    // do what you please with the "cookbook" variable which is of the
    // *Chef.Cookbook type
    fmt.Printf("%#v\n", cookbook)
}

func (*Chef) GetCookbookVersion

func (chef *Chef) GetCookbookVersion(name, version string) (*CookbookVersion, bool, error)

chef.GetCookbookVersion returns a pointer to the chef.CookbookVersion type for a given string that represents a cookbook version. It also returns a bool indicating whether or not the client was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

cookbook, ok, err := chef.GetCookbookVersion("apache", "1.0.0")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that cookbook version!")
} else {
    // do what you please with the "cookbook" variable which is of the
    // *Chef.CookbookVersion type
    fmt.Printf("%#v\n", cookbook)
}

func (*Chef) GetCookbooks

func (chef *Chef) GetCookbooks() (map[string]*Cookbook, error)

chef.GetCookbooks returns a map of cookbook names to a pointer to the chef.Cookbook type as well as an error indicating if the request was successful or not.

Usgae:

cookbooks, err := chef.GetCookbooks()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "cookbooks" variable which is a map of
// cookbook names to chef.Cookbook types
for name, cookbook := range cookbooks {
    fmt.Println(name, cookbook.Version[0])
 }

func (*Chef) GetData

func (chef *Chef) GetData() (map[string]string, error)

chef.GetData returns a map of databag names to their related REST URL endpoint as well as an error indicating if the request was successful or not

Usage:

data, err := chef.GetData()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
for d := range data {
    fmt.Println(d)
}

func (*Chef) GetDataByName

func (chef *Chef) GetDataByName(name string) (map[string]string, bool, error)

chef.GetDataByName accept a string which represents the name of a specific databag and returns a map of information about that databag, a bool indicating whether or not the databag was found and an error indicating if the request failed or not.

Note that if the request is successful but no such data item existed, the error return value will be nil but the bool will be false

Usage:

data, ok, err := chef.GetDataByName("apache")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that databag!")
} else {
    // do what you please with the "data" variable which is of the
    // map[string]string type
    fmt.Println(data)
}

func (*Chef) GetEnvironment

func (chef *Chef) GetEnvironment(name string) (*Environment, bool, error)

chef.GetEnvironment accepts a string which represents the name of a Chef environment and returns a chef.Environment type representing that environment as well as a bool indicating whether or not the environment was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

environment, ok, err := chef.GetEnvironment("production")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that environment!")
} else {
    // do what you please with the "environment" variable which is of the
    // *Chef.Environment type
    fmt.Printf("%#v\n", environment)
}

func (*Chef) GetEnvironmentCookbook

func (chef *Chef) GetEnvironmentCookbook(env, cb string) (*Cookbook, bool, error)

chef.GetEnvironmentCookbook accepts a string which represents the name of a Chef environment as well as a string which represent the name of a cookbook and returns a *Chef.Cookbook type, a bool indicating whether or not the cookbook was found in the given environment as well as an error indicating whether or not the request failed.

Usage:

cookbook, ok, err := chef.GetEnvironmentCookbook("production", "apache")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that cookbook!")
} else {
    // do what you please with the "cookbook" variable which is of the
    // *Chef.Cookbook type
    fmt.Printf("%#v\n", cookbook)
}

func (*Chef) GetEnvironmentCookbooks

func (chef *Chef) GetEnvironmentCookbooks(name string) (map[string]*Cookbook, error)

chef.GetEnvironmentCookbooks accepts a string which represents the name of a Chef environment and returns a map of cookbook names to a *Chef.Cookbook type as well as an error indicating whether or not the request failed.

Usage:

cookbooks, err := chef.GetEnvironmentCookbooks("production")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "cookbooks" variable which is a map of
// cookbook names to chef.Cookbook types
for name, cookbook := range cookbooks {
    fmt.Println(name, cookbook.Version[0])
 }

func (*Chef) GetEnvironmentNodes

func (chef *Chef) GetEnvironmentNodes(name string) (map[string]string, error)

chef.GetEnvironmentNodes accepts a string which represents the name of a Chef environment as well as a string which represent the name of a node and returns a map of node names to their corresponding RESTful URL, a bool indicating whether or not the cookbook was found in the given environment as well as an error indicating whether or not the request failed.

Usage:

nodes, err := chef.GetEnvironmentNodes("production")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "nodes" variable which is a map of
// node names to their corresponding RESTful URL
for node := range nodes {
    fmt.Println(node)
 }

func (*Chef) GetEnvironmentRecipes

func (chef *Chef) GetEnvironmentRecipes(name string) ([]string, error)

chef.GetEnvironmentRecipes accepts a string which represents the name of a Chef environment and returns a slice of recipe names as well as an error indicating whether or not the request failed.

Usage:

recipes, err := chef.GetEnvironmentRecipes("production")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "recipes" variable which is a slice of
// recipe names
for recipe := range recipes {
    fmt.Println(recipe)
 }

func (*Chef) GetEnvironmentRole

func (chef *Chef) GetEnvironmentRole(env, rol string) (map[string][]string, bool, error)

chef.GetEnvironmentRole accepts a string which represents the name of a Chef environment as well as a string which represent the name of a role and returns a map of strings (which represent a role attribute like a runlist) to a slice of strings which represents the relevant information with regards to that attribute, a bool indicating whether or not the role was found in the given environment as well as an error indicating whether or not the request failed.

Usage:

role, ok, err := chef.GetEnvironmentRole("production", "base")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that role!")
} else {
    // do what you please with the "role" variable
    fmt.Println(role)
}

func (*Chef) GetEnvironments

func (chef *Chef) GetEnvironments() (map[string]string, error)

chef.GetEnvironments returns a map of environment names to the environment's RESTful URL as well as an error indicating if the request was successful or not.

Usage:

environments, err := chef.GetEnvironments()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "environments" variable which is a map of
// environment names to environment URLs
for environment := range environments {
    fmt.Println(environment)
 }

func (*Chef) GetNode

func (chef *Chef) GetNode(name string) (*Node, bool, error)

chef.GetNode accepts a string which represents the name of a Chef role and returns a chef.Environment type representing that role as well as a bool indicating whether or not the role was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

node, ok, err := chef.GetNode("neo4j.example.com")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that node!")
} else {
    // do what you please with the "node" variable which is of the
    // *Chef.Node type
    fmt.Printf("%#v\n", node)
}

func (*Chef) GetNodes

func (chef *Chef) GetNodes() (map[string]string, error)

chef.GetNodes returns a map of nodes names to the nodes's RESTful URL as well as an error indicating if the request was successful or not.

Usage:

nodes, err := chef.GetNodes()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "node" variable which is a map of
// node names to node URLs
for node := range nodes {
    fmt.Println(node)
 }

func (*Chef) GetPrincipal

func (chef *Chef) GetPrincipal(name string) (map[string]string, bool, error)

chef.GetPrincipal returns a map of principal item names to their corresponding RESTful url. It also returns a bool indicating whether or not the client was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

principal, ok, err := chef.GetCookbookPrincipal("neo4j.example.org")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that principal!")
} else {
    // do what you please with the "principal" variable which is of the
    // map[string]string type
    fmt.Println(principal)
}

func (*Chef) GetRole

func (chef *Chef) GetRole(name string) (*Role, bool, error)

chef.GetRole returns a pointer to the chef.Role type for a given string that represents a role name. It also returns a bool indicating whether or not the client was found and an error indicating if the request failed or not.

Note that if the request is successful but no such client existed, the error return value will be nil but the bool will be false.

Usage:

role, ok, err := chef.GetRole("neo4j")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
if !ok {
    fmt.Println("Couldn't find that role!")
} else {
    // do what you please with the "role" variable which is of the
    // *Chef.Role
    fmt.Printf("%#v\n", role)
}

func (*Chef) GetRoles

func (chef *Chef) GetRoles() (map[string]string, error)

chef.GetRoles returns a map of role names to a string which represents the role's RESTful URL as well as an error indicating if the request was successful or not.

Usgae:

roles, err := chef.GetRoles()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "roles" variable which is a map of
// role names to their RESTful URLs
for role := range roles {
    fmt.Println(role)
 }

func (*Chef) GetSearchIndexes

func (chef *Chef) GetSearchIndexes() (map[string]string, error)

chef.GetSearchIndexes returns a map of search indexes to the indexes RESTful URL as well as an error indicating if the request was successful or not.

Usage:

indexes, err := chef.GetSearchIndexes()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "indexes" variable which is a map of
// index names to index URLs
for index := range indexes {
    fmt.Println(index)
 }

func (*Chef) GetUsers

func (chef *Chef) GetUsers() (map[string]string, error)

chef.GetUsers returns a map of user names to the users RESTful URL as well as an error indicating if the request was successful or not.

Usage:

users, err := chef.GetUsers()
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "user" variable which is a map of
// user names to user URLs
for user := range users {
    fmt.Println(user)
 }

func (*Chef) GetWithParams

func (chef *Chef) GetWithParams(endpoint string, params map[string]string) (*http.Response, error)

GetWithParams makes an authenticated HTTP request to the Chef server for the supplied endpoint and also includes GET query string parameters

func (*Chef) NewSearchQuery

func (chef *Chef) NewSearchQuery(index, query string) *SearchParams

chef.NewSearchQuery accepts an index and a query and returns a struct which represents the appropriate search parameters. This is mostly just used by the chef.Search method, but you can call it yourself if you'd like some more control over your parameters

func (*Chef) Post

func (chef *Chef) Post(endpoint string, params map[string]string, body io.Reader) (*http.Response, error)

Post post to the chef api

func (*Chef) Put

func (chef *Chef) Put(endpoint string, params map[string]string) (*http.Response, error)

Put makes an authenticated PUT request to the Chef server for the supplied endpoint

func (*Chef) Search

func (chef *Chef) Search(index, query string) (*SearchResults, error)

chef.Search accepts an index and a query and returns a *Chef.Search results type as well as an error indicating if the request was successful or not

Usage:

results, err := chef.Search("nodes", "hostname:memcached*")
if err != nil {
    fmt.Println(err)
    os.Exit(1)
}
// do what you please with the "results" variable which is of the type
// *Chef.SearchResults
fmt.Println(results)

func (*Chef) SearchWithParams

func (chef *Chef) SearchWithParams(index, query string, params map[string]interface{}) (*SearchResults, error)

chef.SearchWithParams is similar to chef.Search, but you can define additional Chef search parameters

type Client

type Client struct {
	Name        string `json:"name"`
	Admin       bool   `json:"admin"`
	JSONClass   string `json:"json_class"`
	ChefType    string `json:"chef_type"`
	ClientName  string `json:"clientname"`
	Org         string `json:"orgname"`
	Validator   bool   `json:"validator"`
	Certificate string `json:"certificate"`
	PublicKey   string `json:"public_key"`
}

chef.Client defines the relevant parameters of a Chef client. This includes it's name, whether or not it's an admin, etc.

type Cookbook

type Cookbook struct {
	Url      string `json:"url"`
	Versions []struct {
		Url     string `json:"url"`
		Version string `json:"version"`
	} `json:"versions"`
}

chef.Cookbook defines the relevant parameters of a Chef cookbook. This includes the RESTful URL of a cookbook and a slice of all of the cookbooks versions. The versions each have two attributes: Url, which represents the RESTful URL of the cookbook version and Version, which represents the version number (identifier) of the cookbook version

type CookbookItem

type CookbookItem struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Checksum    string `json:"checksum"`
	Specificity string `json:"specificity"`
	Url         string `json:"url"`
}

chef.CookbookItem defines the relevant parameters of various items that are found in a chef Cookbook such as the name, checksum, etc. This type is embedded in the chef.CookVersion type to reduce code repetition.

type CookbookVersion

type CookbookVersion struct {
	Files []struct {
		CookbookItem
	} `json:"files"`
	Definitions []struct {
		CookbookItem
	} `json:"definitions"`
	Libraries []struct {
		CookbookItem
	} `json:"libraries"`
	Attributes []struct {
		CookbookItem
	} `json:"attributes"`
	Recipes []struct {
		CookbookItem
	} `json:"recipes"`
	Providers []struct {
		CookbookItem
	} `json:"providers"`
	Resources []struct {
		CookbookItem
	} `json:"resources"`
	Templates []struct {
		CookbookItem
	} `json:"templates"`
	RootFiles []struct {
		CookbookItem
	} `json:"root_file"`
	Metadata struct {
		Name            string            `json:"name"`
		Description     string            `json:"description"`
		LongDescription string            `json:"long_description"`
		Maintainer      string            `json:"maintainer"`
		MaintainerEmail string            `json:"maintainer_email"`
		License         string            `json:"license"`
		Providing       map[string]string `json:"providing"`
		Dependencies    map[string]string `json:"dependencies"`
	} `json:"metadata"`
	Name      string `json:"cookbook_name"`
	Version   string `json:"version"`
	FullName  string `json:"name"`
	Frozen    bool   `json:"frozen?"`
	ChefType  string `json:"chef_type"`
	JSONClass string `json:"json_class"`
}

chef.CookbookVersion defines the relevant parameters of a specific Chef cookbook version. This includes, but is not limited to, information about recipes, files, etc, various pieces of metadata about the cookbook at that point in time, such as the name of the cookbook, the description, the license, etc.

type Environment

type Environment struct {
	Name               string                 `json:"name"`
	Description        string                 `json:"description"`
	CookbookVersions   map[string]string      `json:"cookbook_versions"`
	JSONClass          string                 `json:"json_class"`
	ChefType           string                 `json:"chef_type"`
	DefaultAttributes  map[string]interface{} `json:"default_attributes"`
	OverrideAttributes map[string]interface{} `json:"override_attributes"`
}

chef.Environment dinfes the relevant parameters of a Chef environment. This includes the name of the environment, the description strings, etc.

type Node

type Node struct {
	Name        string   `json:"name"`
	Environment string   `json:"chef_environment"`
	JSONClass   string   `json:"json_class"`
	RunList     []string `json:"run_list"`
	ChefType    string   `json:"chef_type"`
	Info        struct {
		Languages map[string]map[string]string `json:"languages"`
		Kernel    struct {
			Name    string                       `json:"name"`
			Release string                       `json:"release"`
			Version string                       `json:"version"`
			Machine string                       `json:"machine"`
			Modules map[string]map[string]string `json:"modules"`
		} `json:"kernel"`
		OS        string `json:"os"`
		OSVersion string `json:"os_version"`
		Hostname  string `json:"hostname"`
		FQDN      string `json:"fqdn"`
		Domain    string `json:"domain"`
		Network   struct {
			Interfaces map[string]struct {
				Type          string `json:"type"`
				Number        string `json:"number"`
				Encapsulation string `json:"encapsulation"`
				Addresses     map[string]struct {
					Family    string `json:"family"`
					Broadcast string `json:"broadcast"`
					Netmast   string `json:"netmast"`
				} `json:"addresses"`
				Flags []string          `json:"flags"`
				MTU   string            `json:"mtu"`
				Arp   map[string]string `json:"arp"`
			} `json:"interfaces"`
		} `json:"network"`
		IPAddress       string                       `json:"ipaddress"`
		MACAddress      string                       `json:"macaddress"`
		ChefPackages    map[string]map[string]string `json:"chef_packages"`
		Keys            map[string]map[string]string `json:"keys"`
		Platform        string                       `json:"platform"`
		PlatformVersion string                       `json:"platform_version"`
		CPU             map[string]interface{}       `json:"cpu"`
		Filesystem      map[string]struct {
			KBSize       string   `json:"ks_size"`
			KBUsed       string   `json:"ks_used"`
			KBavailable  string   `json:"ks_available"`
			PercentUsed  string   `json:"percent_used"`
			Mount        string   `json:"mount"`
			FSType       string   `json:"fs_type"`
			MountOptions []string `json:"mount_options"`
		} `json:"filesystem"`
		Memory          map[string]interface{} `json:"memory"`
		UptimeSeconds   int                    `json:"uptime_seconds"`
		Uptime          string                 `json:"uptime"`
		IdletimeSeconds int                    `json:"idletime_seconds"`
		Idletime        string                 `json:"idletime"`
		BlockDevice     map[string]interface{} `json:"block_device"`
		Datacenter      map[string]interface{} `json:"datacenter"`
		Ipmi            struct {
			Address    string `json:"address"`
			MacAddress string `json:"mac_address"`
		} `json:"ipmi"`
		Recipes []string `json:"recipes"`
		Roles   []string `json:"roles"`
	} `json:"automatic"`
	Normal  map[string]interface{} `json:"normal"`
	Default map[string]interface{} `json:"default"`
}

chef.Node represents the relevant parameters of a Chef node

type Role

type Role struct {
	Name               string                 `json:"name"`
	ChefType           string                 `json:"chef_type"`
	JSONClass          string                 `json:"json_class"`
	DefaultAttributes  map[string]interface{} `json:"default_attributes"`
	OverrideAttributes map[string]interface{} `json:"override_attributes"`
	RunList            []string               `json:"run_list"`
}

chef.Role represents the relevant attributes of a Chef role

type SearchParams

type SearchParams struct {
	Index string
	Query string
	Sort  string
	Rows  int
	Start int
	// contains filtered or unexported fields
}

chef.SearchParams represents the necessary parameters of a Chef search query

func (*SearchParams) Execute

func (search *SearchParams) Execute() (*SearchResults, error)

chef.Execute is a method on the chef.SearchParams type that executes a given search that has a given set of paramters. This is mostly used by the chef.Search method, but you can call it yourself if you'd like some more control over your parameters

type SearchResults

type SearchResults struct {
	Total int           `json:"total"`
	Start int           `json:"start"`
	Rows  []interface{} `json:"rows"`
}

chef.SearchResults represents the results of a Chef search query

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL