cheflib.entities package

Submodules

cheflib.entities.base module

Chef base entity.

class cheflib.entities.base.Entity(_chef: 'Chef', _name: str, _url: str, _data: Dict | None = None)[source]

Bases: object

property data

Return cached data or retrieve it from server.

delete() bool[source]

Delete entity.

classmethod from_data(chef_instance, data: Dict)[source]

Function to intantiate entity from given data.

property name

Return name of entity.

class cheflib.entities.base.EntityManager(chef_instance, entity_object, parent_name=None, primary_match_field='name')[source]

Bases: object

Manages entities by making them act like iterables but also implements contains and other useful stuff.

filter(query: str, keys: dict | None = None) Generator[source]

Implements filtering based on the filtering capabilities of chef.

Parameters:
  • keys – Dictionary of keys to response filter by.

  • query – search query.

Returns:

Generator of the objects retrieved based on the filtering.

cheflib.entities.client module

Chef client entity.

Source: https://docs.chef.io/server/api_chef_server/

GET: /organizations/NAME/clients This method has no request body. Response: {

}

POST: /organizations/NAME/clients Body: {

“name”: “name_of_API_client”, “clientname”: “name_of_API_client”, “validator”: true, “create_key”: true

}

DELETE: /organizations/NAME/clients/NAME This method has no request body. The response has no body.

GET: /organizations/NAME/clients/NAME This method has no request body. Response: {

“name”: “user1”, “clientname”: “user1”, “orgname”: “test”, “json_class”: “Chef::ApiClient”, “chef_type”: “client”, “validator”: “false”

}

PUT: /organizations/NAME/clients/NAME with a request body similar to: {

“name”: “monkeypants”, “validator”: false

} The response is similar to: {

“name”: “monkeypants”, “clientname”: “monkeypants”, “validator”: true, “json_class”:”Chef::ApiClient”, “chef_type”:”client”

}

class cheflib.entities.client.Client(_chef: Chef, _name: str, _url: str, _data: Dict | None = None, _keys: Dict | None = None)[source]

Bases: Entity

Client entity.

create_key(name, data) ClientKey | None[source]

Create new key.

delete_key_by_name(name: str) bool[source]

Delete client key by name.

property expiration_date
get_key_by_name(name: str) ClientKey[source]

Get client key by name.

property keys
property org_name
property private_key
property public_key
reregister() bool[source]
property validator

cheflib.entities.client_key module

Chef client key entity.

Source: https://docs.chef.io/server/api_chef_server/

GET: /organizations/NAME/clients/NAME/keys This method has no request body. Response: {

}

POST: /organizations/NAME/clients Body: {

“name”: “name_of_API_client”, “clientname”: “name_of_API_client”, “validator”: true, “create_key”: true

}

DELETE: /organizations/NAME/clients/NAME This method has no request body. The response has no body.

GET: /organizations/NAME/clients/NAME This method has no request body. Response: {

“name”: “user1”, “clientname”: “user1”, “orgname”: “test”, “json_class”: “Chef::ApiClient”, “chef_type”: “client”, “validator”: “false”

}

PUT: /organizations/NAME/clients/NAME with a request body similar to: {

“name”: “monkeypants”, “validator”: false

} The response is similar to: {

“name”: “monkeypants”, “clientname”: “monkeypants”, “validator”: true, “json_class”:”Chef::ApiClient”, “chef_type”:”client”

}

class cheflib.entities.client_key.ClientKey(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Client key entity.

property expiration_date

Return the expiration date of the key or None.

property expired

Returns true if key is expired.

property public_key

Return public key or None.

cheflib.entities.cookbook module

Chef cookbook entity.

Source: https://docs.chef.io/server/api_chef_server/

GET /organizations/NAME/cookbooks

{
“apache2”: {

“url”: “https://localhost/cookbooks/apache2”, “versions”: [

{“url”: “https://localhost/cookbooks/apache2/5.1.0”,

“version”: “5.1.0”},

{“url”: “https://localhost/cookbooks/apache2/4.2.0”,

“version”: “4.2.0”}

]

}, “nginx”: {

“url”: “https://localhost/cookbooks/nginx”, “versions”: [

{“url”: “https://localhost/cookbooks/nginx/1.0.0”,

“version”: “1.0.0”},

{“url”: “https://localhost/cookbooks/nginx/0.3.0”,

“version”: “0.3.0”}

]

}

}

class cheflib.entities.cookbook.Cookbook(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Cookbook entity.

property versions

cheflib.entities.databag module

Chef data bag entity.

Source: https://docs.chef.io/server/api_chef_server/

GET: /organizations/NAME/data {

}

POST: /organizations/NAME/data {

“name”: “users”

}

GET: /organizations/NAME/data/NAME/ITEM {

“real_name”: “Adam Jacob”, “id”: “adam”

}

class cheflib.entities.databag.DataBag(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Data bag entity.

create_item(name, data, secret=None) DataBagItem | None[source]

Create item in data bag, encrypt if secret is given.

get_item_by_name(name: str, secret: bytes | None = None) [<class 'cheflib.entities.databagitem.DataBagItem'>, None][source]

Get data bag item by name.

property get_item_names

cheflib.entities.databagitem module

Chef data bag entity.

Source: https://docs.chef.io/server/api_chef_server/

GET: /organizations/NAME/data {

}

POST: /organizations/NAME/data {

“name”: “users”

}

GET: /organizations/NAME/data/NAME/ITEM {

“real_name”: “Adam Jacob”, “id”: “adam”

}

class cheflib.entities.databagitem.DataBagItem(_chef: 'Chef', _name: str, _url: str, _data: Dict | None = None, _secret: bytes | None = None, _encrypted_data: dict | None = None)[source]

Bases: Entity

property encrypted
property secret
cheflib.entities.databagitem.b64_chunker(b64: str) str[source]

cheflib.entities.environment module

Chef environment entity.

Source: https://docs.chef.io/server/api_chef_server/

Request:

GET /organizations/NAME/environments Response

The response is similar to:

{

“_default”: “https://api.chef.io/organizations/org_name/environments/_default”, “webserver”: “https://api.chef.io/organizations/org_name/environments/webserver

}

POST /organizations/NAME/environments with a request body similar to:

{

“name”: “dev”, “default_attributes”: {}, “json_class”: “Chef::Environment”, “description”: “”, “cookbook_versions”: {}, “chef_type”: “environment”

}

Response

The response is similar to:

{ “uri”: “https://localhost/environments/dev” }

class cheflib.entities.environment.Environment(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Environment entity.

property cookbook_versions
property default_attributes
property description
property override_attributes

cheflib.entities.node module

Chef node entity.

Source: https://docs.chef.io/server/api_chef_server/

Request

GET /organizations/NAME/nodes Response

The response is similar to:

{

“latte”: “https://localhost/nodes/latte

}

Request

POST /organizations/NAME/nodes with a request body similar to:

{

“name”: “latte”, “chef_type”: “node”, “json_class”: “Chef::Node”, “attributes”: {

“hardware_type”: “laptop”

}, “overrides”: {}, “defaults”: {}, “run_list”: [ “recipe[unicorn]” ]

}

Response

The response is similar to:

{ “uri”: “https://localhost/nodes/latte” }

class cheflib.entities.node.Node(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Node entity.

property automatic
property chef_environment
property default
property ip_address
property normal
property override
property run_list

cheflib.entities.role module

Chef role entity.

Source: https://docs.chef.io/server/api_chef_server/

Request

GET /organizations/NAME/roles

Response

The response is similar to:

{

“webserver”: “https://chef.example/organizations/org1/roles/webserver

}

Request

POST /organizations/NAME/roles with a request body similar to:

{

“name”: “webserver”, “default_attributes”: {}, “description”: “A webserver”, “env_run_lists”: {

“testenv”: {

“recipe[pegasus]”

}

}, “run_list”: [

“recipe[unicorn]”, “recipe[apache2]”

], “override_attributes”: {}

} Response

The response is similar to:

{ “uri”: “https://chef.example/organizations/org1/roles/webserver” }

class cheflib.entities.role.Role(_chef: Chef, _name: str, _url: str, _data: Dict | None = None)[source]

Bases: Entity

Role entity.

Module contents

cheflib package.

Import all parts from cheflib.entities here