device based
modules
making them as simple as a light switch
TP Honey
@tphoney_puppet - tp@puppet.com
Agenda
where it started
writing puppet code
adding new functionality
the final mile - release
making life easy
where does this lead
Q&A
2simple_hue
where it started
3
Why it started
4simple_hue
the team
Why it started
5simple_hue
the office
Why it started
kitchen
6simple_hue
the Hue experience
Hue hub + bulbs lamp shade
7simple_hue
+ = AWESOME
Baby steps - discovery
8simple_hue
to control the hue:
● IP address (upnp scanner helps)
● developer key
Useful starting points:
● http://IP_OF_HUE/debug/clip.html
● http://www.developers.meethue.com/docu
mentation/getting-started
● http://www.developers.meethue.com/docu
mentation/lights-api
the initial probe
● curl is your friend, a bad bad friend
● the api debugger for the hue is way more
helpful
9simple_hue
The big bang moment
● using api’s to change the world
around you.
● still only a light switch :)
10simple_hue
exec {'change-lights': command => "curl -X PUT
http://9.9.9.9/api/asodasd/lights/1 {"name":"Bedroom Light"}",
require => [ Package['curl']],
}
writing puppet code
11
Writing code is hard - let's borrow it
12simple_hue
how much code do you need
13simple_hue
puppet resource (get the state)
As a user I want to be able to retrieve the state of the philips light bulb
- self-instances > create http connection > get http uri
puppet apply (set the state)
As a user I want to be able to set the state of the philips light bulb
- self-instances > create http connection > get http uri > flush > put http uri
where to start - mvp / use cases
14
Provider
- self-instances
- flush
where to start - class diagram
15
Type
- attributes
Parent class
- create http connection
- get http uri
- put http uri
- boiler plate code
what is a type
Puppet::Type.newtype(:hue_light) do
newparam(:name) do
desc 'The light name'
isnamevar
end
newproperty(:on) do
desc 'is the light on'
end
newproperty(:hue) do
desc 'hue of the hue_light'
end
end
16simple_hue
provider code
17simple_hue
def self.instances
instances = []
lights = Puppet::Provider::Hue.hue_get('lights')
return [] if lights.nil?
lights.each do |light|
instances << new(:name => light.first,
:on => light.last['state']['on'].to_s,
:hue => light.last['state']['hue'].to_s)
end
instances
end
def flush
name = @original_values[:name]
@property_hash = @property_hash.reject { |k, _v|
!resource[k] }
@property_hash.delete(:name)
@property_hash[:hue] = @property_hash[:hue].to_i
result =
Puppet::Provider::Hue.hue_put("lights/#{name}/state",
@property_hash)
end
the ugly side - parent class
18simple_hue
def self.connection
@connection = Faraday.new(:url =>
"http://#{hue_ip}/api/#{hue_key}", :ssl => { :verify =>
false })
end
def self.hue_get(url, args = nil)
url = URI.escape(url) if url
result = connection.get(url, args)
output = JSON.parse(result.body)
rescue JSON::ParserError
return nil
end
def self.hue_put(url, message)
message = message.to_json
message.gsub!(/"false"/, 'false')
message.gsub!(/"true"/, 'true')
connection.put(url, message)
end
types and providers
some great blog posts
http://garylarizza.com/blog/2013/11/25/fun-with-
providers/
http://garylarizza.com/blog/2013/11/26/fun-with-
providers-part-2/
http://garylarizza.com/blog/2013/12/15/seriously
-what-is-this-provider-doing/
AWS and azure
19simple_hue
setting up the environment
20
setting up the environment
21
ITS MESSY TO START
iterate iterate iterate
22simple_hue
switching the light off and on
● writing a manifest
● using puppet resource
● using puppet apply
23simple_hue
adding new functionality
24
living life to the max
25simple_hue
adding funk-tionality
26
let’s look at the philips API
27simple_hue
FLASHY LIGHTS
Live coding - hopefully
28simple_hue
the final mile - release
29
ease of use - users
have a readme
simple examples
naming is hard
dependency hell
semver
30simple_hue
ease of use - developers
docs / urls for apis
code snippets
debugging
copy pasta for contributors (readme,
test, code)
how to set up an environment
dependency hell
31simple_hue
going for approval
avoiding common mistakes:
● start early
● follow the docs guides
● write tests / any tests
why it’s good:
● attracts users
● attracts developers
● you’ll get noticed
32simple_hue
acceptance testing
painful but worth it / hard work already done with
the environment setup
peace of mind
ensuring your code will be maintained over time.
33simple_hue
Puppet device
https://github.com/tphoney/simple_hue_device
34simple_hue
where does this lead
35
technology impact
if you can control a $10 light bulb. you can
control a $100,000 switch
we can control anything with an ip
agentless FTW
someone could fork your branch into something
really weird and awesome
36simple_hue
last minute win - auto-generation of code
Netconf - yang
built on simple_hue
same architecture (if you can call it that)
80% of the code is generated
37simple_hue
Q&A
38
https://forge.puppet.com/tphoney/simple_hue
PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switch – TP Honey, Puppet

More Related Content

PPTX
Flask – Python
PDF
PM : code faster
PDF
Flask - Backend com Python - Semcomp 18
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
Drupal 8 Theme System: The Backend of Frontend
PDF
Flask patterns
PDF
Filling the flask
PDF
Writing and Publishing Puppet Modules - PuppetConf 2014
Flask – Python
PM : code faster
Flask - Backend com Python - Semcomp 18
Python RESTful webservices with Python: Flask and Django solutions
Drupal 8 Theme System: The Backend of Frontend
Flask patterns
Filling the flask
Writing and Publishing Puppet Modules - PuppetConf 2014

What's hot (20)

PDF
Unit Testing Lots of Perl
ODP
The why and how of moving to PHP 5.4/5.5
PDF
Workshop quality assurance for php projects - ZendCon 2013
PDF
UA testing with Selenium and PHPUnit - PFCongres 2013
PDF
Selenium sandwich-3: Being where you aren't.
PDF
Getting testy with Perl
PDF
How to deploy node to production
PDF
Anatomy of a reusable module
PDF
Ansible tips & tricks
PDF
Hacking ansible
PDF
Ansible leveraging 2.0
ODP
Caching and tuning fun for high scalability @ FrOSCon 2011
PDF
Writing & Sharing Great Modules on the Puppet Forge
PDF
Puppet: What _not_ to do
PDF
Effective Benchmarks
PDF
Replacing "exec" with a type and provider: Return manifests to a declarative ...
PDF
Let's Talk Scope
ODP
The why and how of moving to PHP 5.5/5.6
PDF
Datagrids with Symfony 2, Backbone and Backgrid
PDF
More tips n tricks
Unit Testing Lots of Perl
The why and how of moving to PHP 5.4/5.5
Workshop quality assurance for php projects - ZendCon 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
Selenium sandwich-3: Being where you aren't.
Getting testy with Perl
How to deploy node to production
Anatomy of a reusable module
Ansible tips & tricks
Hacking ansible
Ansible leveraging 2.0
Caching and tuning fun for high scalability @ FrOSCon 2011
Writing & Sharing Great Modules on the Puppet Forge
Puppet: What _not_ to do
Effective Benchmarks
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Let's Talk Scope
The why and how of moving to PHP 5.5/5.6
Datagrids with Symfony 2, Backbone and Backgrid
More tips n tricks
Ad

Viewers also liked (20)

PPTX
Demystifying TLS
PPTX
What's New in Puppet Enterprise 2016.4
PDF
Advice on how to get started — and ahead — in a career in DevOps
PPTX
What's New in Puppet Enterprise 2016.5
PPTX
Network Automation at Shapeways
PPTX
Introduction to Puppet Enterprise
PPTX
Introduction to Puppet Enterprise
PPTX
Introduction to Puppet Enterprise
PPTX
Adopting Kubernetes with Puppet
PPTX
What's New in Puppet Enterprise 2016.4
PPTX
Introduction to Puppet Enterprise 2016.4
PPTX
Introduction to Puppet Enterprise 2016.5
PPTX
Introduction to Puppet Enterprise 2016.5
PDF
The Challenges of Container Configuration
PDF
PuppetConf 2016: Keynote - Luke Kanies, Puppet Founder
PDF
PuppetConf 2016: Keynote - Sanjay Mirchandani, Puppet CEO
PPTX
Introduction to Puppet Enterprise 2016.5
PPTX
Controlled Evolution with Puppet and AWS
PDF
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
PDF
Introduction to puppet
Demystifying TLS
What's New in Puppet Enterprise 2016.4
Advice on how to get started — and ahead — in a career in DevOps
What's New in Puppet Enterprise 2016.5
Network Automation at Shapeways
Introduction to Puppet Enterprise
Introduction to Puppet Enterprise
Introduction to Puppet Enterprise
Adopting Kubernetes with Puppet
What's New in Puppet Enterprise 2016.4
Introduction to Puppet Enterprise 2016.4
Introduction to Puppet Enterprise 2016.5
Introduction to Puppet Enterprise 2016.5
The Challenges of Container Configuration
PuppetConf 2016: Keynote - Luke Kanies, Puppet Founder
PuppetConf 2016: Keynote - Sanjay Mirchandani, Puppet CEO
Introduction to Puppet Enterprise 2016.5
Controlled Evolution with Puppet and AWS
PuppetConf 2016: Puppet as Security Tooling – Bill Weiss, Puppet
Introduction to puppet
Ad

Similar to PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switch – TP Honey, Puppet (20)

PPTX
06-classes.ppt (copy).pptx
PDF
Dataflow: Declarative concurrency in Ruby
PDF
Build a bot workshop async primer - php[tek]
PDF
Can you upgrade to Puppet 4.x?
PDF
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
PDF
Building Cloud Castles
PDF
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
PDF
The new features of PHP 7
ODP
Tame your Infrastructure with Puppet
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
PDF
A General Purpose Docker Image for PHP
PPTX
PDF
Lean Php Presentation
ODP
Incredible Machine with Pipelines and Generators
PPTX
Python Homework Help
PDF
I, For One, Welcome Our New Perl6 Overlords
ODP
The promise of asynchronous php
PDF
YAPC::Brasil 2009, POE
PPTX
PSGI and Plack from first principles
PDF
Puppi. Puppet strings to the shell
06-classes.ppt (copy).pptx
Dataflow: Declarative concurrency in Ruby
Build a bot workshop async primer - php[tek]
Can you upgrade to Puppet 4.x?
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Building Cloud Castles
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7
Tame your Infrastructure with Puppet
ZendCon 2017 - Build a Bot Workshop - Async Primer
A General Purpose Docker Image for PHP
Lean Php Presentation
Incredible Machine with Pipelines and Generators
Python Homework Help
I, For One, Welcome Our New Perl6 Overlords
The promise of asynchronous php
YAPC::Brasil 2009, POE
PSGI and Plack from first principles
Puppi. Puppet strings to the shell

More from Puppet (20)

PPTX
Puppet Community Day: Planning the Future Together
PPTX
The Evolution of Puppet: Key Changes and Modernization Tips
PPTX
Can You Help Me Upgrade to Puppet 8? Tips, Tools & Best Practices for Your Up...
PPTX
Bolt Dynamic Inventory: Making Puppet Easier
PPTX
Customizing Reporting with the Puppet Report Processor
PPTX
Puppet at ConfigMgmtCamp 2025 Sponsor Deck
PPTX
The State of Puppet in 2025: A Presentation from Developer Relations Lead Dav...
PPTX
Let Red be Red and Green be Green: The Automated Workflow Restarter in GitHub...
PDF
Puppet camp2021 testing modules and controlrepo
PPTX
Puppetcamp r10kyaml
PDF
2021 04-15 operational verification (with notes)
PPTX
Puppet camp vscode
PDF
Modules of the twenties
PDF
Applying Roles and Profiles method to compliance code
PPTX
KGI compliance as-code approach
PDF
Enforce compliance policy with model-driven automation
PDF
Keynote: Puppet camp compliance
PPTX
Automating it management with Puppet + ServiceNow
PPTX
Puppet: The best way to harden Windows
PPTX
Simplified Patch Management with Puppet - Oct. 2020
Puppet Community Day: Planning the Future Together
The Evolution of Puppet: Key Changes and Modernization Tips
Can You Help Me Upgrade to Puppet 8? Tips, Tools & Best Practices for Your Up...
Bolt Dynamic Inventory: Making Puppet Easier
Customizing Reporting with the Puppet Report Processor
Puppet at ConfigMgmtCamp 2025 Sponsor Deck
The State of Puppet in 2025: A Presentation from Developer Relations Lead Dav...
Let Red be Red and Green be Green: The Automated Workflow Restarter in GitHub...
Puppet camp2021 testing modules and controlrepo
Puppetcamp r10kyaml
2021 04-15 operational verification (with notes)
Puppet camp vscode
Modules of the twenties
Applying Roles and Profiles method to compliance code
KGI compliance as-code approach
Enforce compliance policy with model-driven automation
Keynote: Puppet camp compliance
Automating it management with Puppet + ServiceNow
Puppet: The best way to harden Windows
Simplified Patch Management with Puppet - Oct. 2020

Recently uploaded (20)

PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Decision Optimization - From Theory to Practice
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
Electrocardiogram sequences data analytics and classification using unsupervi...
PDF
CEH Module 2 Footprinting CEH V13, concepts
PDF
Examining Bias in AI Generated News Content.pdf
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
Human Computer Interaction Miterm Lesson
PDF
SaaS reusability assessment using machine learning techniques
PDF
Altius execution marketplace concept.pdf
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
substrate PowerPoint Presentation basic one
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
Internet of Everything -Basic concepts details
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Decision Optimization - From Theory to Practice
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
Data Virtualization in Action: Scaling APIs and Apps with FME
Rapid Prototyping: A lecture on prototyping techniques for interface design
Electrocardiogram sequences data analytics and classification using unsupervi...
CEH Module 2 Footprinting CEH V13, concepts
Examining Bias in AI Generated News Content.pdf
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
Human Computer Interaction Miterm Lesson
SaaS reusability assessment using machine learning techniques
Altius execution marketplace concept.pdf
Ensemble model-based arrhythmia classification with local interpretable model...
Early detection and classification of bone marrow changes in lumbar vertebrae...
Build Real-Time ML Apps with Python, Feast & NoSQL
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
substrate PowerPoint Presentation basic one
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
Internet of Everything -Basic concepts details

PuppetConf 2016: Device-Based Modules: Making Them as Simple as a Light Switch – TP Honey, Puppet

  • 1. device based modules making them as simple as a light switch TP Honey @tphoney_puppet - [email protected]
  • 2. Agenda where it started writing puppet code adding new functionality the final mile - release making life easy where does this lead Q&A 2simple_hue
  • 7. the Hue experience Hue hub + bulbs lamp shade 7simple_hue + = AWESOME
  • 8. Baby steps - discovery 8simple_hue to control the hue: ● IP address (upnp scanner helps) ● developer key Useful starting points: ● http://IP_OF_HUE/debug/clip.html ● http://www.developers.meethue.com/docu mentation/getting-started ● http://www.developers.meethue.com/docu mentation/lights-api
  • 9. the initial probe ● curl is your friend, a bad bad friend ● the api debugger for the hue is way more helpful 9simple_hue
  • 10. The big bang moment ● using api’s to change the world around you. ● still only a light switch :) 10simple_hue exec {'change-lights': command => "curl -X PUT http://9.9.9.9/api/asodasd/lights/1 {"name":"Bedroom Light"}", require => [ Package['curl']], }
  • 12. Writing code is hard - let's borrow it 12simple_hue
  • 13. how much code do you need 13simple_hue
  • 14. puppet resource (get the state) As a user I want to be able to retrieve the state of the philips light bulb - self-instances > create http connection > get http uri puppet apply (set the state) As a user I want to be able to set the state of the philips light bulb - self-instances > create http connection > get http uri > flush > put http uri where to start - mvp / use cases 14
  • 15. Provider - self-instances - flush where to start - class diagram 15 Type - attributes Parent class - create http connection - get http uri - put http uri - boiler plate code
  • 16. what is a type Puppet::Type.newtype(:hue_light) do newparam(:name) do desc 'The light name' isnamevar end newproperty(:on) do desc 'is the light on' end newproperty(:hue) do desc 'hue of the hue_light' end end 16simple_hue
  • 17. provider code 17simple_hue def self.instances instances = [] lights = Puppet::Provider::Hue.hue_get('lights') return [] if lights.nil? lights.each do |light| instances << new(:name => light.first, :on => light.last['state']['on'].to_s, :hue => light.last['state']['hue'].to_s) end instances end def flush name = @original_values[:name] @property_hash = @property_hash.reject { |k, _v| !resource[k] } @property_hash.delete(:name) @property_hash[:hue] = @property_hash[:hue].to_i result = Puppet::Provider::Hue.hue_put("lights/#{name}/state", @property_hash) end
  • 18. the ugly side - parent class 18simple_hue def self.connection @connection = Faraday.new(:url => "http://#{hue_ip}/api/#{hue_key}", :ssl => { :verify => false }) end def self.hue_get(url, args = nil) url = URI.escape(url) if url result = connection.get(url, args) output = JSON.parse(result.body) rescue JSON::ParserError return nil end def self.hue_put(url, message) message = message.to_json message.gsub!(/"false"/, 'false') message.gsub!(/"true"/, 'true') connection.put(url, message) end
  • 19. types and providers some great blog posts http://garylarizza.com/blog/2013/11/25/fun-with- providers/ http://garylarizza.com/blog/2013/11/26/fun-with- providers-part-2/ http://garylarizza.com/blog/2013/12/15/seriously -what-is-this-provider-doing/ AWS and azure 19simple_hue
  • 20. setting up the environment 20
  • 21. setting up the environment 21 ITS MESSY TO START
  • 23. switching the light off and on ● writing a manifest ● using puppet resource ● using puppet apply 23simple_hue
  • 25. living life to the max 25simple_hue
  • 27. let’s look at the philips API 27simple_hue FLASHY LIGHTS
  • 28. Live coding - hopefully 28simple_hue
  • 29. the final mile - release 29
  • 30. ease of use - users have a readme simple examples naming is hard dependency hell semver 30simple_hue
  • 31. ease of use - developers docs / urls for apis code snippets debugging copy pasta for contributors (readme, test, code) how to set up an environment dependency hell 31simple_hue
  • 32. going for approval avoiding common mistakes: ● start early ● follow the docs guides ● write tests / any tests why it’s good: ● attracts users ● attracts developers ● you’ll get noticed 32simple_hue
  • 33. acceptance testing painful but worth it / hard work already done with the environment setup peace of mind ensuring your code will be maintained over time. 33simple_hue
  • 35. where does this lead 35
  • 36. technology impact if you can control a $10 light bulb. you can control a $100,000 switch we can control anything with an ip agentless FTW someone could fork your branch into something really weird and awesome 36simple_hue
  • 37. last minute win - auto-generation of code Netconf - yang built on simple_hue same architecture (if you can call it that) 80% of the code is generated 37simple_hue