Class: PEClient::Resource::PuppetV3

Inherits:
BaseWithPort show all
Defined in:
lib/pe_client/resources/puppet.v3.rb,
lib/pe_client/resources/puppet.v3/file_bucket.rb,
lib/pe_client/resources/puppet.v3/file_metadata.rb

Overview

Server-specific Puppet API endpoints.

Defined Under Namespace

Classes: FileBucket, FileMetadata

Constant Summary collapse

BASE_PATH =

The base path for Puppet API v3 endpoints.

"/puppet/v3"
PORT =

Default Puppet API Port

8140

Instance Method Summary collapse

Methods inherited from BaseWithPort

#initialize

Constructor Details

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

Instance Method Details

#catalog(node_name:, environment: nil) ⇒ Hash

Returns a catalog for the specified node name given the provided facts.

Parameters:

  • node_name (String)

    The name of the node to retrieve the catalog for.

  • environment (String) (defaults to: nil)

    The environment to use when compiling the catalog.

Returns:

  • (Hash)

See Also:



39
40
41
# File 'lib/pe_client/resources/puppet.v3.rb', line 39

def catalog(node_name:, environment: nil)
  @client.get File.join("#{BASE_PATH}/catalog", node_name), params: {environment:}.compact
end

#environment_classes(environment:) ⇒ Hash

The environment classes API serves as a replacement for the Puppet resource type API for classes, which was removed in Puppet.

Parameters:

  • environment (String)

    The environment to query.

Returns:

  • (Hash)

See Also:



116
117
118
# File 'lib/pe_client/resources/puppet.v3.rb', line 116

def environment_classes(environment:)
  @client.get "#{BASE_PATH}/environment_classes", params: {environment:}
end

#environment_modules(environment: nil) ⇒ Array<Hash>, Hash

The environment modules API returns information about what modules are installed for the requested environment.

Parameters:

  • environment (String) (defaults to: nil)

    The environment to query.

Returns:

  • (Array<Hash>, Hash)

See Also:



127
128
129
# File 'lib/pe_client/resources/puppet.v3.rb', line 127

def environment_modules(environment: nil)
  @client.get "#{BASE_PATH}/environment_modules", params: {environment:}.compact
end

#facts(node_name:, values:, timestamp:, expiration:, environment: nil) ⇒ Hash

Allows setting the facts for the specified node name.

Parameters:

  • node_name (String)

    The name of the node to set the facts for.

  • values (Hash)

    The facts for the specified node.

  • timestamp (String)

    When the facts were gathered.

  • expiration (String)

    When the facts will expire.

  • environment (String) (defaults to: nil)

    The environment to use when setting the facts.

Returns:

  • (Hash)

See Also:



69
70
71
# File 'lib/pe_client/resources/puppet.v3.rb', line 69

def facts(node_name:, values:, timestamp:, expiration:, environment: nil)
  @client.put File.join("#{BASE_PATH}/facts", node_name), body: {name: node_name, values:, timestamp:, expiration:}, params: {environment:}.compact
end

#file_bucketPEClient::Resource::PuppetV3::FileBucket



144
145
146
147
# File 'lib/pe_client/resources/puppet.v3.rb', line 144

def file_bucket
  require_relative "puppet.v3/file_bucket"
  @file_bucket ||= PuppetV3::FileBucket.new(@client)
end

#file_content(mount_point:, name:) ⇒ String

Returns the contents of the specified file.

Parameters:

  • mount_point (String)

    One of the following types:

    • Custom file serving mounts as specified in fileserver.conf

    • ‘modules/<MODULE>` — a semi-magical mount point which allows access to the files subdirectory of <MODULE>

    • plugins — a highly magical mount point which merges the lib directory of every module together. Used for syncing plugins; not intended for general consumption. Per-module sub-paths can not be specified.

    • pluginfacts — a highly magical mount point which merges the facts.d directory of every module together. Used for syncing external facts; not intended for general consumption. Per-module sub-paths can not be specified.

    • ‘tasks/<MODULE>` — a semi-magical mount point which allows access to files in the tasks subdirectory of <MODULE>

  • name (String)

Returns:

  • (String)

See Also:



90
91
92
# File 'lib/pe_client/resources/puppet.v3.rb', line 90

def file_content(mount_point:, name:)
  @client.get File.join("#{BASE_PATH}/file_content", mount_point, name), headers: {"Content-Type": "application/octet-stream", Accept: "application/octet-stream"}
end

#file_metadataPEClient::Resource::PuppetV3::FileMetadata



150
151
152
153
# File 'lib/pe_client/resources/puppet.v3.rb', line 150

def 
  require_relative "puppet.v3/file_metadata"
  @file_metadata ||= PuppetV3::FileMetadata.new(@client)
end

#node(certname:, environment: nil, transaction_uuid: nil, configured_environment: nil) ⇒ Hash

The returned information includes the node name and environment, and optionally any classes set by an External Node Classifier and a hash of parameters which may include the node’s facts. The returned node may have a different environment from the one given in the request if Puppet is configured with an ENC.

Parameters:

  • certname (String)

    The name of the node to retrieve information for.

  • environment (String) (defaults to: nil)

    The environment to use when retrieving the node information.

  • transaction_uuid (String) (defaults to: nil)

    A transaction uuid identifying the entire transaction (shows up in the report as well).

  • configured_environment (String) (defaults to: nil)

    The environment configured on the client.

Returns:

  • (Hash)

See Also:



54
55
56
# File 'lib/pe_client/resources/puppet.v3.rb', line 54

def node(certname:, environment: nil, transaction_uuid: nil, configured_environment: nil)
  @client.get File.join("#{BASE_PATH}/node", certname), params: {environment:, transaction_uuid:, configured_environment:}.compact
end

#report(node_name:, environment:, report:) ⇒ Hash

This endpoint allows clients to send reports to the master. Once received by the master they are processed by the ‘report processors` configured to be triggered when a report is received. As an example, storing reports in PuppetDB is handled by one such report processor.

Parameters:

  • node_name (String)

    The name of the node the report is for.

  • environment (String)

    The environment to use when submitting the report.

  • report (Hash)

    The report to submit.

Returns:

  • (Hash)

See Also:



105
106
107
# File 'lib/pe_client/resources/puppet.v3.rb', line 105

def report(node_name:, environment:, report:)
  @client.put File.join("#{BASE_PATH}/report", node_name), body: report, params: {environment:}
end

#static_file_content(file_path:) ⇒ String

The static_file_content endpoint returns the standard output of a code-content-command script, which should output the contents of a specific version of a ‘file resource` that has a source attribute with a puppet:/// URI value. That source must be a file from the files or tasks directory of a module in a specific environment.

Parameters:

  • file_path (String)

    The path corresponds to the requested file’s path on the Server relative to the given environment’s root directory, and must point to a file in the //files/**, //lib/**, //scripts/**, or //tasks/** glob.

Returns:

  • (String)

See Also:



139
140
141
# File 'lib/pe_client/resources/puppet.v3.rb', line 139

def static_file_content(file_path:)
  @client.get File.join("#{BASE_PATH}/static_file_content", file_path)
end