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
This lab will walk you through the basic steps of creating a native integration with puppet. After this you will have a fully functioning module to manage Philips HUE lights and have seen all the bits fall into place.
3
+
The Resource API hands-on lab walks you through creating a native integration with Puppet. After completely this lab, you will have a fully functioning module to manage Philips HUE lights.
4
4
5
-
These labs are intended for new and experienced developers alike. Please post feedback and suggestions for improvement in the [issues section](https://github.com/puppetlabs/puppet-resource_api/issues).
5
+
>Note: These labs are intended for both new and experienced developers. If you have any feedback or suggestions for improvement, post it in the [issues section](https://github.com/puppetlabs/puppet-resource_api/issues).
6
6
7
-
Start with[installing the Puppet Development Kit](./hands-on-lab/01-installing-prereqs.md)
7
+
To start with, we'll go through [installing Puppet Development Kit](./hands-on-lab/01-installing-prereqs.md)(PDK).
# Install the Puppet Development Kit and other tools
1
+
# Install Puppet Development Kit (PDK) and other tools
2
2
3
-
To start out, install the Puppet Development Kit (PDK), which will provide all necessary tools and libraries to build and test modules. Additionally we recommend an emulator for the target device of this lab, a code editor with good ruby and puppet support, and GIT, a version control system to keep track of our progress.
3
+
To start, install Puppet Development Kit (PDK), which provides all the necessary tools and libraries to build and test modules. We also recommend an emulator for the target device, a code editor with good Ruby and Puppet support, and git — a version control system to keep track of your progress.
4
4
5
-
1.Choose your platform from https://puppet.com/download-puppet-development-kit; download and install the package
5
+
1.[Download PDK](https://puppet.com/download-puppet-development-kit) on your platform of choice.
6
6
7
-
2. If you do not have a Philips HUE hub available, you can download the [Hue-Emulator](https://github.com/SteveyO/Hue-Emulator/raw/master/HueEmulator-v0.8.jar). You will need to have Java installed to run this.
7
+
2. If you do not have a Philips HUE hub available, you can download the [Hue-Emulator](https://github.com/SteveyO/Hue-Emulator/raw/master/HueEmulator-v0.8.jar). You need to have Java installed to run this.
8
8
9
9
3. To edit code, we recommend the cross-platform editor [VSCode](https://code.visualstudio.com/download), with the [Ruby](https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby) and [Puppet](https://marketplace.visualstudio.com/items?itemName=jpogran.puppet-vscode) extensions. There are lots of other extensions that can help you with your development workflow.
10
10
11
-
4. Git is a version control system that helps you keep track of changes and collaborate with others. In the course of the hands-on lab, we will show some integrations with cloud services that can help you. If you never used git before, skip this and all related steps for now.
11
+
4. Git is a version control system that helps you keep track of changes and collaborate with others. As we go through hands-on lab, we will show you some integrations with cloud services. If you have never used git before, ignore this and all related steps.
12
12
13
13
14
14
## Next up
15
15
16
-
Having installed all of this, let's[light up a few](./02-connecting-to-the-lightbulbs.md).
16
+
After installing the relevant tools, you'll[light up a few](./02-connecting-to-the-lightbulbs.md).
While there are no technical restrictions on the kinds of remote devices or APIs you can connect to with transports, for the purpose of this workshop we are connecting to a Philips HUE hub and make some colourful wireless lightbulbs light up. If you (understandably) do not have physical devices available, you can get going with the Hue Emulator.
3
+
There are no technical restrictions on the kinds of remote devices or APIs you can connect to with transports. For this lab, we will connect to a Philips HUE hub and make some colourful wireless light bulbs light up. If you (understandably) do not have physical devices available, you can use the Hue Emulator.
4
4
5
5
## Hue Emulator
6
6
7
7
Download the [HueEmulator-v0.8.jar](https://github.com/SteveyO/Hue-Emulator/blob/master/HueEmulator-v0.8.jar) from [SteveyO/Hue-Emulator](https://github.com/SteveyO/Hue-Emulator).
8
8
9
-
To run this emulator, you will need to have a Java Runtime installed. Once you have java installed, use `java -jar` with the emulator's filename to run it:
9
+
To run the Hue Emulator, you need to have a Java Runtime installed. Use `java -jar` with the emulator's filename to run it, for example:
All you need now is to input a port (the default 8000 is usually fine) and press "Start" to activate the built-in server.
19
+
All you need now is to input a port (the default 8000 is usually fine) and click "Start" to activate the built-in server.
20
20
21
21
## Connecting to your hub
22
22
23
-
To connect to an actual hub, you will need be able to access the Hub on your network and get an API key. Follow the [Philips Developer docs](http://www.developers.meethue.com/documentation/getting-started) (registration required) for that.
23
+
To connect to an actual hub, you need be able to access the bub on your network and get an API key. See the [Philips Developer docs](http://www.developers.meethue.com/documentation/getting-started) (registration required).
24
24
25
25
26
26
## Next up
27
27
28
-
Once you have some lights up, head on to [create a new module](./03-creating-a-new-module.md).
28
+
Now that you have some lights up, you'll [create a module](./03-creating-a-new-module.md).
To read more about the different options when creating new modules see [the PDK docs](https://puppet.com/docs/pdk/1.x/pdk_creating_modules.html).
36
+
To read more about the different options when creating new modules, see [PDK docs](https://puppet.com/docs/pdk/1.x/pdk_creating_modules.html).
37
37
38
-
Open the new directory in VSCode, or your coding editor of choice:
38
+
Open the new directory in your code editor:
39
39
40
40
```
41
41
code -a hue_workshop
42
42
```
43
43
44
-
For this workshop, we'll active a few future defaults to make our lives easier down the line. Directly in the `hue_workshop` directory, create a file called `.sync.yml` and paste the following snippet:
44
+
Next, we'll active a few future defaults. In the `hue_workshop` directory, create a file called `.sync.yml` and paste the following:
45
45
46
46
```
47
47
# .sync.yml
@@ -56,7 +56,7 @@ spec/spec_helper.rb:
56
56
mock_with: ':rspec'
57
57
```
58
58
59
-
Then run `pdk update` in the module's directory to deploy the changes into the module:
59
+
Run `pdk update` in the module's directory to deploy the changes in the module:
Copy file name to clipboardExpand all lines: docs/hands-on-lab/04-adding-a-new-transport.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Add a new transport
2
2
3
-
[Eventually](https://github.com/puppetlabs/pdk/pull/666) there will be a `pdk new transport`, for now you'll need to copy in a few files for this workshop.
3
+
[Eventually](https://github.com/puppetlabs/pdk/pull/666) there will be a `pdk new transport` command. For now, you'll need to copy the files below.
4
4
5
5
Copy the files from [this directory](./04-adding-a-new-transport/) into your new module:
6
6
@@ -11,7 +11,7 @@ Copy the files from [this directory](./04-adding-a-new-transport/) into your new
11
11
* spec/unit/puppet/transport/hue_spec.rb
12
12
* spec/unit/puppet/transport/schema/hue_spec.rb
13
13
14
-
Afterwards run`pdk update --force` to enable a few future defaults that are required for these templates:
14
+
Run`pdk update --force` to enable a few future defaults that are required for these templates:
15
15
16
16
```
17
17
david@davids:~/tmp/hue$ pdk update --force
@@ -36,7 +36,7 @@ david@davids:~/tmp/hue$
36
36
37
37
## Checkpoint
38
38
39
-
To make sure that everything went well with creating the module and copying in the files you can run `pdk validate --parallel` and `pdk test unit`:
39
+
To validate your new module and transport, run `pdk validate --parallel` and `pdk test unit`:
40
40
41
41
```
42
42
david@davids:~/tmp/hue$ pdk validate --parallel
@@ -62,7 +62,7 @@ Run options: exclude {:bolt=>true}
62
62
david@davids:~/tmp/hue$
63
63
```
64
64
65
-
If you're working with a version control system, this would also be a good point to make the first commit to store away all the boilerplate code and later revisit the changes you made. Here I'm showing how to initialise a local git repository and storing all files in an initial commit:
65
+
If you're working with a version control system, now would be a good time to make your first commit and store the boilerplate code, and then you can revisit the changes you made later. For example:
66
66
67
67
```
68
68
david@davids:~/tmp/hue$ git init
@@ -102,4 +102,4 @@ david@davids:~/tmp/hue$
102
102
103
103
## Next up
104
104
105
-
Once you have everything ready, head on to[implement the transport](./05-implementing-the-transport.md).
105
+
Now that you have everything ready, you'll[implement the transport](./05-implementing-the-transport.md).
Copy file name to clipboardExpand all lines: docs/hands-on-lab/05-implementing-the-transport-hints.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
## Implementing the transport - Exercise
2
2
3
-
Implement a`request_debug` option that can be toggled on to create additional debug output on each request. You will not need concepts that you haven't yet seen in this tutorial, and basic programing skills. If you get stuck, have a look at some hints below, or [the finished file](TODO).
3
+
Implement the`request_debug` option that you can toggle on to create additional debug output on each request. If you get stuck, review the hints below, or [the finished file](TODO).
4
4
5
5
## Hints
6
6
7
-
*A toggle option can be created with the `Boolean` (`true` or `false`) data type. Add it to the `connection_info` in the transport schema.
7
+
*You can create a toggle option with the `Boolean` (`true` or `false`) data type. Add it to the `connection_info` in the transport schema.
8
8
9
9
* Make it an `Optional[Boolean]` so that users who do not require request debugging do not have to specify the value.
10
10
11
-
* To remember the value passed in from the user, store `connection_info[:request_debug]` in a `@request_debug` variable.
11
+
* To remember the value you passed, store `connection_info[:request_debug]` in a `@request_debug` variable.
12
12
13
-
* In the `hue_get` and `hue_put` methods add `context.debug(message)` calls showing the method's arguments.
13
+
* In the `hue_get` and `hue_put` methods, add `context.debug(message)` calls showing the method's arguments.
14
14
15
-
* Make the debugging optional based on the user's input by appending `if @request_debug` to each logging statement.
15
+
* Make the debugging optional based on your input by appending `if @request_debug` to each logging statement.
Copy file name to clipboardExpand all lines: docs/hands-on-lab/05-implementing-the-transport.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ A transport consists of a *schema* describing the required data and credentials
4
4
5
5
## Schema
6
6
7
-
The transport schema defines those attributes in a reusable manner, allowing users to understand the requirements of the transport. All schemas are located in `lib/puppet/transport/schema` in a ruby file named after the transport. In this case `hue.rb`.
7
+
The transport schema defines attributes in a reusable way, allowing you to understand the requirements of the transport. All schemas are located in `lib/puppet/transport/schema` in a Ruby file named after the transport. In this case `hue.rb`.
8
8
9
-
To connect to the HUE hub we need an IP address, a port, and an API key.
9
+
To connect to the HUE hub you need an IP address, a port, and an API key.
10
10
11
-
Replace the `connection_info` in `lib/puppet/transport/schema/hue.rb` with the following snippet.
11
+
Replace the `connection_info` in `lib/puppet/transport/schema/hue.rb` with the following code:
12
12
13
13
```ruby
14
14
connection_info: {
@@ -28,21 +28,21 @@ Replace the `connection_info` in `lib/puppet/transport/schema/hue.rb` with the f
28
28
},
29
29
```
30
30
31
-
> Note: The Resource API transports use [Puppet Data Types](https://puppet.com/docs/puppet/5.3/lang_data_type.html#core-data-types) to define the allowable values for an attribute. Abstract types like `Optional[]` can be useful to make using your transport easier. Take special note of the `sensitive: true` annotation on the `key`; it instructs all services processing this attribute with special care, for example to avoid logging the key.
31
+
> Note: The Resource API transports use [Puppet Data Types](https://puppet.com/docs/puppet/5.3/lang_data_type.html#core-data-types) to define the allowable values for an attribute. Abstract types like `Optional[]` can be useful to make using your transport easier. Take note of the `sensitive: true` annotation on the `key`; it instructs all services processing this attribute with special care, for example to avoid logging the key.
32
32
33
33
34
34
## Implementation
35
35
36
-
The implementation of a transport provides connectivity and utility functions for both puppet and the providers managing the remote target. The HUE API is a simple REST interface, so we can store the credentials until we need make a connection. The default template at `lib/puppet/transport/hue.rb` already does this. Have a look at the `initialize` function to see how this is done.
36
+
The implementation of a transport provides connectivity and utility functions for both Puppet and the providers managing the remote target. The HUE API is a simple REST interface, so you can store the credentials until you need make a connection. The default template at `lib/puppet/transport/hue.rb` already does this. Have a look at the `initialize` function to see how this is done.
37
37
38
-
For the HUE's REST API, we want to create a `Faraday` object to capture the target host and key, so the transport can facilitate requests. Replace the `initialize` method in `lib/puppet/transport/hue.rb` with the following snippet:
38
+
For the HUE's REST API, we want to create a `Faraday` object to capture the target host and key so that the transport can facilitate requests. Replace the `initialize` method in `lib/puppet/transport/hue.rb` with the following code:
39
39
40
40
<!-- TODO: do we really need this? -- probably not ```
41
41
# @summary
42
42
# Expose the `Faraday` object connected to the hub
43
43
attr_reader :connection
44
44
45
-
```-->
45
+
```-->
46
46
```
47
47
# @summary
48
48
# Initializes and returns a faraday connection to the given host
@@ -60,7 +60,7 @@ For the HUE's REST API, we want to create a `Faraday` object to capture the targ
60
60
61
61
The transport is also responsible for collecting any facts from the remote target, similar to how facter works for regular systems. For now we'll only return a hardcoded `operatingsystem` value to mark HUE Hubs:
62
62
63
-
Replace the example `facts` method in `lib/puppet/transport/hue.rb` with this snippet:
63
+
Replace the example `facts` method in `lib/puppet/transport/hue.rb` with the following code:
64
64
65
65
```
66
66
# @summary
@@ -70,13 +70,13 @@ Replace the example `facts` method in `lib/puppet/transport/hue.rb` with this sn
70
70
end
71
71
```
72
72
73
-
### Connection Verification and Closing
73
+
### Connection verification and closing
74
74
75
75
To enable better feedback when something goes wrong, a transport can implement a `verify` method to run extra checks on the credentials passed in.
76
76
77
77
To save resources both on the target and the node running the transport, the `close` method will be called when the transport is not needed anymore. The transport can close connections and release memory and other resources at this point.
78
78
79
-
For this tutorial, replace the example methods with this snippet:
79
+
For this tutorial, replace the example methods with the following code:
80
80
81
81
```
82
82
# @summary
@@ -93,9 +93,9 @@ For this tutorial, replace the example methods with this snippet:
93
93
94
94
### Making requests
95
95
96
-
Besides exposing some standardises functionality to puppet, the transport is also a good place to put utility functions that can be reused across your providers. While it may seem overkill for this small example, it is no extra effort, and will establish a healthy pattern.
96
+
Besides exposing some standardises functionality to Puppet, the transport is also a good place to put utility functions that can be reused across your providers. While it may seem overkill for this small example, it is no extra effort, and will establish a healthy pattern.
97
97
98
-
Insert the following snippet after the `close` method:
98
+
Insert the following code after the `close` method:
99
99
100
100
```
101
101
# @summary
@@ -118,7 +118,7 @@ Insert the following snippet after the `close` method:
118
118
119
119
## Exercise
120
120
121
-
Implement a `request_debug` option that can be toggled on to create additional debug output on each request. You will not need concepts that you haven't yet seen in this tutorial, and basic programing skills. If you get stuck, have a look at [some hints](./05-implementing-the-transport-hints.md), or [the finished file](TODO).
121
+
Implement a `request_debug` option that you can toggle to create additional debug output on each request. If you get stuck, have a look at [some hints](./05-implementing-the-transport-hints.md), or [the finished file](TODO).
0 commit comments