Skip to content

Commit d4c97ca

Browse files
author
Kevin Paulisse
committed
Finish API catalog documentation
1 parent e935ee7 commit d4c97ca

1 file changed

Lines changed: 95 additions & 2 deletions

File tree

doc/dev/api/v1/objects/catalog.md

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,113 @@ This object is the return value from the [`catalog`](/doc/dev/api/v1/calls/catal
1212

1313
#### `#builder` (String)
1414

15+
Returns the name of the class the built the catalog.
16+
17+
```
18+
catalog.builder #=> 'OctocatalogDiff::Catalog::JSON'
19+
```
20+
1521
#### `#compilation_dir` (String)
1622

23+
Returns the temporary directory in which the catalog was compiled.
24+
25+
```
26+
catalog.compilation_dir #=> '/var/folders/dw/5ftmkqk972j_kw2fdjyzdqdw0000gn/T/d20170108-95774-1r4ohjd'
27+
```
28+
29+
This is only applicable for catalogs compiled by `OctocatalogDiff::Catalog::Computed`. This method will return `nil` for catalogs generated by other backends.
30+
1731
#### `#error_message` (String)
1832

33+
Returns the error message for a failed catalog. (If the catalog is valid, this returns `nil`.)
34+
35+
```
36+
good_catalog.valid? #=> true
37+
good_catalog.error_message #=> nil
38+
39+
bad_catalog.valid? #=> false
40+
bad_catalog.error_message #=> 'Failed to compile catalog for node ...'
41+
```
42+
1943
#### `#puppet_version` (String)
2044

21-
#### `#resource(<Hash>)` (Object)
45+
Returns the Puppet version used to compile the catalog.
46+
47+
```
48+
catalog.puppet_version #=> '3.8.7'
49+
```
50+
51+
This is only applicable for catalogs compiled by `OctocatalogDiff::Catalog::Computed`. This method will return `nil` for catalogs generated by other backends.
52+
53+
#### `#resource(<Hash>)` (Hash)
54+
55+
Returns the hash representation of the object identified by the type and title supplied.
56+
57+
This method requires 1 argument, which is a hash containing `:type` and `:title` keys.
58+
59+
```
60+
catalog.resource(type: 'File', title: '/etc/foo')
61+
#=> {"title"=>"/etc/foo", "type"=>"File",
62+
"parameters"=>{"content"=>"This is the file", "owner"=>"root"},
63+
"file"=>"/etc/puppetlabs/code/environments/production/manifests/site.pp", "line"=>25}
64+
```
65+
66+
Returns `nil` if the type+title resource was not present in the catalog.
2267

23-
#### `#resources` (Array&lt;Object&gt;)
68+
##### Notes
69+
70+
1. The first call to this method will build a hash table (`O(N)` operation) from the resource array. Thereafter, each call to this method will look up the value in that hash table (`O(1)` operation). To perform lookups of known types and titles, it is faster to use this method than to use `#resources` with array operations when performing multiple lookups.
71+
72+
2. The structure of the returned hash is dependent on the representation of the resource in the Puppet catalog. It is therefore possible that different versions of Puppet could cause different data structures. It is the author's experience that Puppet 3.8.7 and Puppet 4.x produce similar (if not indistinguishable) resource representations.
73+
74+
3. This method will also locate a resource that was named using an alias.
75+
76+
```
77+
# Puppet code
78+
file { '/etc/foo':
79+
alias => 'foo file for the win',
80+
...
81+
}
82+
83+
# octocatalog-diff API
84+
catalog.resource(type: 'File', title: 'foo file for the win')
85+
#=> {"title"=>"/etc/foo", "type"=>"File", ...}
86+
```
87+
88+
#### `#resources` (Array&lt;Hash&gt;)
89+
90+
Returns an array of catalog resources in a successful catalog. (If the catalog is not valid, this returns `nil`.)
91+
92+
```
93+
bad_catalog.valid? #=> false
94+
bad_catalog.resources #=> nil
95+
96+
good_catalog.valid? #=> true
97+
good_catalog.resources
98+
#=> [
99+
{ "title"=>"/etc/foo", "type"=>"File", ... },
100+
{ "title"=>"/bin/true", "type"=>"Exec", ... }
101+
]
102+
```
103+
104+
The structure of the returned hash is dependent on the representation of the resource in the Puppet catalog. It is therefore possible that different versions of Puppet could cause different data structures. It is the author's experience that Puppet 3.8.7 and Puppet 4.x produce similar (if not indistinguishable) resource representations.
24105

25106
#### `#to_json` (String)
26107

108+
Returns the JSON representation of a successful catalog. (If the catalog is not valid, this returns `nil`.)
109+
110+
```
111+
bad_catalog.valid? #=> false
112+
bad_catalog.to_json #=> nil
113+
114+
good_catalog.valid? #=> true
115+
good_catalog.to_json #=> '{ "document_type": "Catalog", ... }'
116+
```
117+
27118
#### `#valid?` (Boolean)
28119

120+
Returns `true` if the catalog is valid, and `false` if the catalog is not valid.
121+
29122
## Other methods
30123

31124
These methods are available for debugging or development purposes but are not guaranteed to remain consistent between versions:

0 commit comments

Comments
 (0)