You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hands-on-lab/06-implementing-the-provider.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
# Implementing the Provider
1
+
# Implementing the provider
2
2
3
-
To expose resources from the HUE Hub to puppet, a type and provider define and implement the desired interactions. The *type*, like the transport schema, defines the shape of the data using Puppet Data Types. The implementation in the *provider* takes care of the communication and data transformation.
3
+
To expose resources from the HUE Hub to Puppet, a type and provider define and implement the desired interactions. The *type*, like the transport schema, defines the shape of the data using Puppet data types. The implementation in the *provider* takes care of the communication and data transformation.
4
4
5
5
For this hands on lab, we'll now go through implementing a simple `hue_light` type and provider to manage the state of the light bulbs connected to the HUE Hub.
6
6
7
7
## Generating the Boilerplate
8
8
9
-
In your module directory, run `pdk new provider hue_light`. This will create another set of files with a bare-bones type and provider, as well as unit tests.
9
+
In your module directory, run `pdk new provider hue_light`. This creates another set of files with a bare-bones type and provider, as well as unit tests.
10
10
11
11
```
12
12
david@davids:~/tmp/hue_workshop$ pdk new provider hue_light
The type defines the attributes and allowed values, as well as a couple of other bits of information that concerns the processing of this provider.
23
23
24
-
For remote resources like this, adding the `'remote_resource'` feature is necessary to alert puppet of its specific needs. Add the string to the existing `features` array.
24
+
For remote resources like this, adding the `'remote_resource'` feature is necessary to alert Puppet of its specific needs. Add the string to the existing `features` array.
25
25
26
-
Browsing through the Hub API (TODO: insert link), we can identify a few basic properties we want to manage:
26
+
Browsing through the Hub API (TODO: insert link), we can identify a few basic properties we want to manage, for example:
27
27
28
-
*whether the lamp is on or off
29
-
*the colour of the light (hue and saturation)
30
-
*the brightness of the light
28
+
*Whether the lamp is on or off
29
+
*The colour of the light (hue and saturation)
30
+
*The brightness of the light
31
31
32
32
To define the necessary attributes, insert the following snippet into the `attributes` hash, after the `name`:
33
33
@@ -54,11 +54,11 @@ DESC
54
54
55
55
## Implementing the Provider
56
56
57
-
Every provider needs a `get` method, that returns a list of currently existing resources and their attributes from the remote target. For the HUE Hub, this is requires a call to the `lights` endpoint and some data transformation to the format puppet expects.
57
+
Every provider needs a `get` method, that returns a list of currently existing resources and their attributes from the remote target. For the HUE Hub, this is requires a call to the `lights` endpoint and some data transformation to the format Puppet expects.
58
58
59
59
### Reading the state of the lights
60
60
61
-
Replace the example `get` function in `lib/puppet/provider/hue_light/hue_light.rb` with the following snippet:
61
+
Replace the example `get` function in `lib/puppet/provider/hue_light/hue_light.rb` with the following code:
62
62
63
63
```
64
64
# @summary
@@ -81,7 +81,7 @@ Replace the example `get` function in `lib/puppet/provider/hue_light/hue_light.r
81
81
end
82
82
```
83
83
84
-
This method will return all connected lights from the HUE Hub and allow puppet to process those. To try this out, you need to setup a test configuration and then`puppet device` can be used to drive your testing.
84
+
This method returns all connected lights from the HUE Hub and allows Puppet to process them. To try this out, you need to setup a test configuration and use`puppet device` to drive your testing.
85
85
86
86
> TODO: explain steps to gain access to API keys for real device
87
87
@@ -147,7 +147,7 @@ The final step here is to implement enforcing the desired state of the lights. T
147
147
148
148
For the HUE Hub API, we can remove the `create` and `delete` method. Since the attribute names and data definitions line up with the HUE Hub API, the `update` method is very short.
149
149
150
-
Replace the `create`, `update`, and `delete` methods with this snippet:
150
+
Replace the `create`, `update`, and `delete` methods with the following code:
To round out the API support, add a`effect` attribute that defaults to `none`, but can be set to `colorloop`, and an `alert` attribute that defaults to `none` and can be set to `select`.
193
+
To round out the API support, add an`effect` attribute that defaults to `none`, but can be set to `colorloop`, and an `alert` attribute that defaults to `none` and can be set to `select`.
194
194
195
-
Note that this exercise will require exploring new data types and Resource API options.
195
+
Note that this exercise requires exploring new data types and Resource API options.
0 commit comments