cheflib package

Subpackages

Submodules

cheflib.cheflib module

Main code for cheflib.

class cheflib.cheflib.Chef(endpoint: str, organization: str, user_id: str, private_key_contents: str, client_version: str = '12.0.2', authentication_version: str = '1.3', api_version: int = 1)[source]

Bases: object

Chef api library.

property clients: EntityManager

List all clients.

Returns:

Generator for all clients

property cookbooks: EntityManager

List all cookbooks.

Returns:

Generator for all cookbooks

create_client(name: str, data: dict | None = None) Client | None[source]

Create a client, with specified.

Parameters:
  • name – string, name of the client

  • data – (optional) dictionary, containing additional attributes that will be added to the client

Returns:

New client

create_data_bag(name: str) DataBag | None[source]

Create a data bag.

Parameters:

name – string, name of the data bag

Returns:

New data bag

create_environment(name: str, data: dict | None = None) Environment[source]

Create a environment, with specified name.

Parameters:
  • name – string, name of the environment

  • data – (optional) dictionary, containing additional attributes that will be added to the environment

Returns:

New environment

create_node(name: str, data: dict | None = None) Node[source]

Create a node, with specified name.

Parameters:
  • name – string, Name of the node

  • data – (optional) dictionary, containing additional attributes that will be added to the node

Returns:

New node

create_role(name: str, data: dict | None = None) Role[source]

Create a role, with specified name.

Parameters:
  • name – string, name of the role

  • data – (optional) dictionary, containing additional attributes that will be added to the role.

Returns:

New role

property data_bags: EntityManager

List all data bags.

Returns:

Generator for all data bags

delete_client_by_name(name: str) bool[source]

Deletes a client by name.

Parameters:

name – string, name of the client

Returns:

True if deletion succeeded or False if deletion failed

delete_environment_by_name(name: str) bool[source]

Delete environment with specifief name.

Parameters:

name – string, name of environment

Returns:

True if deletion succeeded or False if deletion failed

delete_node_by_name(name: str) bool[source]

Delete node with specified name.

Parameters:

name – string, name of the node

Returns:

True if deletion succeeded or False if deletion failed

delete_role_by_name(name: str) bool[source]

Delete role with specified name.

Parameters:

name – string, name of the role

Returns:

True if deletion succeeded or False if deletion failed

property environments: EntityManager

List all environments.

Returns:

Generator for all environments

get_client_by_name(name: str) Client[source]

Gets a client by name.

Parameters:

name – string, name of the client

Returns:

First client with specified name

get_data_bag_by_name(name: str) DataBag[source]

Gets a data bag by name.

Parameters:

name – string, name of the data bag

Returns:

First data bag with specified name

get_data_bag_item_by_name(bag_name: str, name: str, secret: bytes | None = None) DataBag[source]

Gets a data bag item by name.

Parameters:
  • bag_name – string, name of the data bag

  • name – string, name of the item

  • secret – (optional) bytes, secret key to encrypt/decrypt the data bag

Returns:

Data bag item with specified name

get_environment_by_name(name: str) Environment[source]

Get environment with specified name.

Parameters:

name – string, name of the environment

Returns:

First environment with specified name

get_node_by_ip_address(ipaddress: str) Node[source]

Get node with specified IP address.

Parameters:

ipaddress – string, IP address of the node

Returns:

First node with specified IP address

get_node_by_name(name: str) Node[source]

Get node with specified name.

Parameters:

name – string, name of the node

Returns:

First node with specified name

get_role_by_name(name: str) Role[source]

Get role with specified name.

Parameters:

name – string, name of the role

Returns:

First role with specified name

property nodes: EntityManager

List all nodes.

Returns:

Generator for all nodes

raw(uri, method='get', **kwargs)[source]

Raw API calls to chef API.

See https://docs.chef.io/workstation/knife_raw/ for more details.

Parameters:
  • uri – string, uri part of the API call

  • method – (optional) string, GET, PUT, DELETE or POST

  • **kwargs – (optional) additional keyword arguments

Returns:

JSON response from chef API

property roles: EntityManager

List all roles.

Returns:

Generator for all roles

search_nodes(query: str = '*:*', keys: dict | None = None)[source]

Search nodes, full and partial search supported.

When a keys dictionary is provided, only those attributes will be returned. See https://docs.chef.io/chef_search/ for more details.

Parameters:
  • query – (optional) string containing the search query

  • keys – (optional) dictionary, containing the returned attributes (partial search)

Returns:

Generator for all nodes matching the search

cheflib.cheflibexceptions module

Custom exception code for cheflib.

exception cheflib.cheflibexceptions.CreateFailed[source]

Bases: Exception

exception cheflib.cheflibexceptions.DeleteFailed[source]

Bases: Exception

exception cheflib.cheflibexceptions.InvalidObject[source]

Bases: Exception

exception cheflib.cheflibexceptions.InvalidSearchIndex[source]

Bases: Exception

exception cheflib.cheflibexceptions.NodeNotFound[source]

Bases: Exception

exception cheflib.cheflibexceptions.UnAuthorized[source]

Bases: Exception

cheflib.configuration module

Module contents

cheflib package.

Import all parts from cheflib here