Welcome to pastry’s documentation!

PastryClient

Supported Operations

Initialize Initialize the client with the chef server info
Load Config Load server config from a yaml file
Get Url Get the server and endpoint for the request
Call Call a resource on the chef server

API Reference

class pastry.pastry_client.PastryClient[source]

PastryClient is used by the resources to send requests to chef. You can use the PastryClient to initialize the config to use for the chef server.

classmethod call(endpoint, method='GET', data=None)[source]

Send an http request to the chef server api

Parameters:
  • endpoint (string) – The endpoint for the resource being called
  • method (string) – The HTTP method
  • data (hash) – The body of the request
Returns:

The json response from the server

Return type:

hash

classmethod get_url(endpoint)[source]

Fetches the server and updates the endpoint with the organization

Parameters:endpoint (string) – The endpoint being called on the chef server
Returns:The server url and updated endpoint
Return type:tuple
classmethod initialize(server, organization, client, keypath, verify)[source]

Initializes the server connection info

Parameters:
  • server (string) – The url for the chef server e.g. https://my.chef.server
  • organization (string) – The name of the cheff org to use
  • client (string) – The client/username to use
  • keypath (string) – The path to the pem for the client/user
  • verify (boolean) – Verify the ssl cert on requests
classmethod load_config(config_path=None)[source]

Load server config from a yaml file

If no config_path is specified it will try to load config from $HOME/.chef/pastry.yaml

Note

This method is automatically called if an http requests is made and the client has not yet been initialised

Parameters:config_path (string) – The path to the config file on the local filesystem

Users

Wraps the chef user account. In order to modify users in chef you will need server admin privledges. Server admins are supported in chef 12.4.1 and above. If you are using an older version of chef server you will have to use the pivotal user (not recommended) to be able to modify users. More info on chef server admins can be found in the chef server admins documentation.

Supported Operations

Index Fetch a list of all of the users
Get Lookup user info
Create Create a new user
Update Update a group
Delete Delete a group
Exists Check if a user exists
Invite Invite a user to an org

API Reference

class pastry.resources.users.Users[source]

Provides access to the chef users resource

classmethod create(user)[source]

Creates a new chef user on the server

The user hash should be in the form:

{
    'username': <username>,
    'display_name': <display_name>,
    'first_name': <first name>,
    'middle_name': <middle name>, # optional
    'last_name': <last name>,
    'email': <email>,
    'password': <password>
}
Parameters:user (hash) – The user to create
Returns:The username and url
Return type:hash
classmethod delete(username)[source]

Deletes a user from the chef server

Parameters:username – The User’s username
Returns:The deleted user’s name
Return type:hash
classmethod exists(username)[source]

Checks if a user exists on the chef server

Parameters:username – The User’s username
Returns:If the user exists
Return type:boolean
classmethod get(username)[source]

Fetches a user from the chef server

Parameters:username (string) – The User’s username
Returns:The chef user
Return type:hash
classmethod index()[source]

Fetches all of the users on the chef server

Returns:All the chef users with a url for each user
Return type:hash
classmethod invite(username, orgname)[source]

Invite a user to an org

Parameters:
  • username (string) – The User’s username
  • orgname (string) – The chef organization
Returns:

If the request was successful

Return type:

boolean

classmethod update(username, user)[source]

Updates a user on the chef server

Parameters:
  • username (string) – The User’s username
  • user (hash) – The User members and content
Returns:

The username and url

Return type:

hash

Groups

The groups resource adds support for managing chef groups.

Supported Operations

Index Fetch a list of all of the groups
Get Lookup group info
Create Create a new group
Update Update a group
Delete Delete a group
Exists Check if a group exists

API Reference

class pastry.resources.groups.Groups[source]

Provides access to the chef groups resource

classmethod create(group)[source]

Creates a new chef group on the server

The group hash should be in the form:

{
    'groupname': <groupname>,
    'name': <groupname>,
    'actors': { #optional
        'users': <list of usernames>, # optional
        'clients': <list of clients>, #optional
        'groups': <list of groups> #optional
    }
}
Parameters:group (hash) – The group to create
Returns:The groupname and url
Return type:hash
classmethod delete(groupname)[source]

Deletes a group from the chef server

Parameters:groupname (string) – The Group’s groupname
Returns:The deleted group’s name
Return type:hash
classmethod exists(groupname)[source]

Checks if a group exists on the chef server

Parameters:username – The Group’s groupname
Returns:If the group exists
Return type:boolean
classmethod get(groupname)[source]

Fetches a group from the chef server

Note

Chef returns a slightly different format to what it expects for create/update groups.

Parameters:groupname (string) – The Group’s name
Returns:The chef group and members
Return type:hash
classmethod index()[source]

Fetches all of the groups on the chef server

Returns:All the chef groups with a url for each group
Return type:hash
classmethod update(groupname, group)[source]

Updates a group on the chef server

the group hash should be in the same format as for create

Parameters:
  • groupname (string) – The Group’s groupname
  • group (hash) – The Group members and content
Returns:

The groupname and url

Return type:

hash

Nodes

The groups module adds support for chef nodes.

Supported Operations

Exists Check if a node exists
Get Acl Fetch a node’s acl
Set Permission Set a permission for a node

API Reference

class pastry.resources.nodes.Nodes[source]

Provides access to the chef nodes

classmethod exists(nodename)[source]

Checks if a node exists on the chef server

Parameters:nodename (string) – The Node’s nodename
Returns:If the node exists
Return type:boolean
classmethod get_acl(nodename)[source]

Gets the access control list for the node

Parameters:nodename (string) – The Node’s nodename
Returns:The acl for the node
Return type:hash
classmethod set_permission(nodename, permission, actors)[source]

Grants the specified actors a permission on the node. Chef only supports setting one permission at a time.

The actors hash should be in the form:

{
    'actors': <list of usernames>
    'groups': <list of groupnames>
}
Parameters:
  • nodename (string) – The Node’s nodename
  • permission (string) – One of: create, read, update, delete, grant
  • actors (hash) – The set of actors to grant this permission to
Returns:

empty hash

Type:

hash

Environments

The environments resource adds support for managing chef environments.

Supported Operations

Index Fetch a list of all of the users
Get Lookup user info
Create Create a new environment
Update Update an environment
Delete Delete an environment
Exists Check if an environment exists

API Reference

Cookbooks

The cookbooks resource adds support for querying chef cookbooks.

Supported Operations

Index Fetch a list of all of the groups
Exists Check if a group exists
Contents Get the list of files in a cookbook
Parse Filename Splits up the path to a file in a cookbook
File Content Read the contents of a file

API Reference

class pastry.resources.cookbooks.Cookbooks[source]

Provides methods for interacting with chef cookbooks

classmethod contents(cookbook, version='_latest')[source]

Fetches the cookbooks list of files that chef knows about

Parameters:
  • cookbook (string) – The cookbook’s name
  • version (string) – The cookbook’s version
Returns:

All of the files the cookbook knows about

Return type:

hash

classmethod exists(cookbook)[source]

Checks if a cookbook exists on the chef server

Parameters:cookbook (string) – The Cookbook’s name
Returns:If the cookbook exists
Return type:boolean
classmethod file_content(cookbook, filename, version='_latest')[source]

Fetches the contents of a specific file in a cookbook

Parameters:
  • cookbook (string) – The cookbook’s name
  • filename (string) – The name (and path) of the file to fetch
  • version (string) – The cookbook’s version
Returns:

The raw contents of the specified file

Return type:

string

classmethod index()[source]

Fetches all of the cookbooks (and versions) on the chef server

Returns:All the chef cookbooks and versions
Return type:hash
classmethod parse_filename(filename)[source]

Splits the file path so that it can be used to call the chef api

Parameters:filename (string) – The file’s path relative to the cookbook root
Returns:The type of file, specificity, and filename
Return type:iterable

Pushy

Provides a wrapper to the chef pushy endpoints. node_states (status) is the only supported endpoint at this time.

Supported Operations

Status Check the push jobs status on a node

API Reference

class pastry.resources.pushy.Pushy[source]

Provides access to the chef pushy api

classmethod status(nodename)[source]

Checks the push jobs status of a node

Parameters:nodename (string) – The Node’s nodename
Returns:If pushy jobs is available on the node
Return type:boolean

Indices and tables