Class: PEClient::Resource::NodeClassifierV1::Groups

Inherits:
Base
  • Object
show all
Defined in:
lib/pe_client/resources/node_classifier.v1/groups.rb

Overview

The groups endpoints create, read, update, and delete groups.

Constant Summary collapse

BASE_PATH =

The base path for Node Classifier API v1 groups endpoints.

"#{NodeClassifierV1::BASE_PATH}/groups".freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PEClient::Resource::Base

Instance Method Details

#create(name:, parent:, id: nil, environment: nil, environment_trumps: nil, description: nil, rule: nil, variables: nil, classes: {}, config_data: nil) ⇒ Hash

Create a node group with a randomly-generated ID or specific ID if supplied.

Parameters:

  • name (String)

    The name of the node group.

  • parent (String)

    The ID of the node group’s parent.

  • id (String) (defaults to: nil)
  • environment (String) (defaults to: nil)

    The name of the node group’s environment. This is optional. If omitted, the default value is production.

  • environment_trumps (Boolean) (defaults to: nil)

    When a node belongs to two or more groups, this Boolean indicates whether this node group’s environment overrides environments defined by other node groups. This is optional. If omitted, the default value is false.

  • description (String) (defaults to: nil)

    Describing the node group. This is optional. If omitted, the node group has no description.

  • rule (String) (defaults to: nil)

    The condition that must be satisfied for a node to be classified into this node group. For rule formatting assistance, refer to (Forming node classifier API requests)[help.puppet.com/pe/current/topics/forming_node_classifier_requests.htm].

  • variables (Hash{Symbol, String => String}) (defaults to: nil)

    An optional object that defines the names and values of any top-level variables set by the node group. Supply key-value pairs of variable names and corresponding variable values. Variable values can be any type of JSON value. The variables object can be omitted if the node group does not define any top-level variables.

  • classes (Hash{Symbol, String => String}) (defaults to: {})

    Defines the classes to be used by nodes in the node group. The classes object contains the parameters for each class. Some classes have required parameters. This object contains nested objects – The classes object’s keys are class names (as strings), and each key’s value is an object that defines class parameter names and their values. Within the nested objects, the keys are the parameter names (as strings), and each value is the parameter’s assigned value (which can be any type of JSON value). If no classes are declared, then classes must be supplied as an empty object ({}). If missing, the server returns a 400 Bad request response.

  • config_data (Hash{Symbol, String => Any}) (defaults to: nil)

    An optional object that defines the class parameters to be used by nodes in the group. Its structure is the same as the classes object. No configuration data is stored if you supply a config_data object that only contains a class name, such as ‘“config_data” => => {}`.

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 74

def create(name:, parent:, id: nil, environment: nil, environment_trumps: nil, description: nil, rule: nil, variables: nil, classes: {}, config_data: nil)
  body = {
    name:,
    parent:,
    environment:,
    environment_trumps:,
    description:,
    rule:,
    variables:,
    classes:,
    config_data:
  }.compact

  if id
    @client.put "#{BASE_PATH}/#{id}", body:
  else
    @client.post BASE_PATH, body:
  end
end

#delete(id) ⇒ Hash

Delete the node group with the given ID.

Parameters:

  • id (String)

Returns:

  • (Hash)

    If the request is successful, the response body is empty.



111
112
113
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 111

def delete(id)
  @client.delete "#{BASE_PATH}/#{id}"
end

#get(id = nil) ⇒ Hash+

Retrieves one or more groups.

Parameters:

  • id (String) (defaults to: nil)

Returns:

  • (Hash, Array<Hash>)


34
35
36
37
38
39
40
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 34

def get(id = nil)
  if id
    @client.get("#{BASE_PATH}/#{id}")
  else
    @client.get(BASE_PATH)
  end
end

#nodes(id) ⇒ Hash

Resolve all the nodes associated with a node group.

This endpoint combines all the rules for the group and queries PuppetDB for the result.

Parameters:

  • id (String)

Returns:

  • (Hash)


150
151
152
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 150

def nodes(id)
  @client.get "#{BASE_PATH}/#{id}/nodes"
end

#pin(id, nodes) ⇒ Hash

Pin specific nodes to a node group.

Parameters:

  • id (String)
  • nodes (Array<String>)

    Names of the nodes you want to pin to the group

Returns:

  • (Hash)

    If the request is successful, the response body is empty.



121
122
123
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 121

def pin(id, nodes)
  @client.post "#{BASE_PATH}/#{id}/pin", body: {nodes:}
end

#rules(id) ⇒ Hash

Resolve the rules for a specific node group, and then translate those rules to work with the PuppetDB nodes and inventory endpoints.

Parameters:

  • id (String)

Returns:

  • (Hash)


140
141
142
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 140

def rules(id)
  @client.get "#{BASE_PATH}/#{id}/rules"
end

#unpin(id, nodes) ⇒ Hash

Unpin specific nodes to a node group.

Parameters:

  • id (String)
  • nodes (Array<String>)

    Names of the nodes you want to unpin to the group

Returns:

  • (Hash)

    If the request is successful, the response body is empty.



131
132
133
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 131

def unpin(id, nodes)
  @client.post "#{BASE_PATH}/#{id}/unpin", body: {nodes:}
end

#update(id, attributes) ⇒ Hash

Edit the name, environment, parent node group, rules, classes, class parameters, configuration data, and variables for a specific node group.

Parameters:

  • id (String)
  • attributes (Hash)

    The attributes to update.

Returns:

  • (Hash)

See Also:



102
103
104
# File 'lib/pe_client/resources/node_classifier.v1/groups.rb', line 102

def update(id, attributes)
  @client.post "#{BASE_PATH}/#{id}", body: attributes
end