SlideShare a Scribd company logo
1 of 26
Writing
Salt Modules
Joseph Hall
Senior Engineer at SaltStack, Inc.
Presented at OpenWest 2013
1Friday, June 7, 13
The future of technology is dependent upon our ability to effectively utilize infrastructures at any scale.
2Friday, June 7, 13
What Salt Does
Salt is a Remote Execution framework, which enables functionality such as:
• Configuration Management
• Cloud Management
• Monitoring
• Alerting
• Responding to Alerts
• etc.
3Friday, June 7, 13
What do these things all have in
common?
Every component on the previous slide is a function of distributed computing.
So why not also use Salt to do the things that we think about, when we think about distributed
computing?
4Friday, June 7, 13
Salt Venn Diagram
Salt
Chef
Puppet
CFEngine
5Friday, June 7, 13
Not Playing the Same Game
Flickr photo by kawwsu29 Flickr photo by ant.photos
6Friday, June 7, 13
Things that Should Be Salted
Flickr photo by gdgt buzz Flickr photo by Toronto Home Theater
Flickr photo by IntelFreePress Photo by Joseph Hall
7Friday, June 7, 13
A Basic Use Case
Writing a simple web crawler
• Need to collect various web pages
• Use multiple nodes to collect data
• Return web content to salt-master for storage
8Friday, June 7, 13
Using urllib2 for Our Crawler
• Easy to use
• Ships with Python
• Negates need to install 3rd party dependencies
• If a more complex spider is needed, a 3rd party library can be used
o If the 3rd party module is not installed, the module needs to know not to make itself
available, via the __virtual__() function
9Friday, June 7, 13
Execution Module Basics
• The __virtual__() function
o Not technically required, but is a best practice
o Executed when salt-minion is loaded
o Identifies the module name
o Commonly used to identify whether a module should be made available
• Private functions
o Name starts with underscore
o Only used internally by the module
o Will not show up in sys.doc
• Public functions
o Called directly by salt commands
o Will show up in sys.doc
10Friday, June 7, 13
A Few Basics
• PEP-8 is your friend
• The Salt Style Guide supersedes PEP-8
• Always use docstrings
• Avoid late imports
• Use (proper) logging
o Do not use warn/error when info is correct
o Do not use info when debug is correct
o Do not add log messages to __virtual__()
11Friday, June 7, 13
Using the Salt Logging System
import logging
log = logging.getLogger(__name__)
log.info('Always useful to users')
log.warn('Something isn't right, but I can still
continue')
log.error('Something is definitely wrong, and should
be fixed')
log.debug('Only developers care about me')
12Friday, June 7, 13
Sample __virtual__() Function
try:

 import urllib2

 HAS_URLLIB2 = True
except:

 HAS_URLLIB2 = False
def __virtual__():

 if HAS_URLLIB2 is True:

 
 return 'crawler'

 return False
13Friday, June 7, 13
Sample Private Function
def _query(url):
result = urllib2.urlopen(url)
return {
'url': result.url,
'code': result.code,
'msg': result.msg,
'headers': result.headers.dict,
'content': result.read(),
}
14Friday, June 7, 13
Sample Public Function
def fetch(urls=None):
ret = {}
if type(urls) is str:
ret[urls] = _query(urls)
elif type(urls) is list:
for url in urls:
ret[url] = _query(url)
return ret
15Friday, June 7, 13
Using Docstrings
def fetch(urls=None):
'''
Fetch a URL
CLI Example::
salt myminion crawler.download http://
www.mydomain.com/
'''
...SNIP...
16Friday, June 7, 13
Using our New Module
(command line)
Testing/debugging locally:
• salt-call --local -l debug crawler.fetch http://
tinyurl.com/cnyypk
From the salt-master:
• salt myminion crawler.fetch http://tinyurl.com/
cnyypk
17Friday, June 7, 13
Ready for more?
Let's write a salt runner!
18Friday, June 7, 13
Bootstrapping a Runner
• manage.py is a good example runner
• cp manage.py yourrunnername.py
• Make changes to suit your needs
o status() has the actual client in it
o up() and down() use the data to form a report
19Friday, June 7, 13
Using the LocalClient
import salt.client
client = salt.client.LocalClient(
__opts__['conf_file'],
)
minions = client.cmd(
'*',
'test.ping',
timeout=__opts__['timeout'],
)
20Friday, June 7, 13
Returning Output
import salt.output
data = some_stuff()
salt.output.display_output(data, '', __opts__)
21Friday, June 7, 13
Which Minions to Use?
• Maybe we don't want to use all of our minions for crawling.
• Just using the minions that have our crawler installed is sloppy and indeterminate
• So let's explicitly define which minions to use, in a configurable location
22Friday, June 7, 13
Setting Up a Pillar
# cat /srv/pillar/top.sls
base:
'spider*':
- crawler
# cat /srv/pillar/crawler.sls
crawler.enabled: True
23Friday, June 7, 13
Targeting the Pillar
minions = client.cmd(
'crawler.enabled:True',
'test.ping',
timeout=__opts__['timeout'],
expr_form='pillar',
)
24Friday, June 7, 13
Fetching From a Minion
def fetch(urls=None):
minions = up()
client = salt.client.LocalClient(
__opts__['conf_file'])
data = client.cmd(minions[0],
'crawler.fetch', arg=[urls],
timeout=__opts__['timeout'])
for minion in data.keys():
for url in data[minion]:
data[minion][url]['content'] = ''
salt.output.display_output(
data, '', __opts__)
25Friday, June 7, 13
Resources
Slides Available At:
http://tinyurl.com/utos-salt-modules-2013
Sources Available At:
https://github.com/techhat/salt-crawler/
Find me on Twitter:
@techhat
26Friday, June 7, 13

More Related Content

Similar to Writing SaltStack Modules - OpenWest 2013

Introduction to PhoneGap and PhoneGap Build
Introduction to PhoneGap and PhoneGap BuildIntroduction to PhoneGap and PhoneGap Build
Introduction to PhoneGap and PhoneGap BuildMartin de Keijzer
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app developmentGaurav Lochan
 
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...PatrickCrompton
 
Hadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopHadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopWisely chen
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby ConferenceJohn Woodell
 
De-Google Your Life
De-Google Your LifeDe-Google Your Life
De-Google Your LifeLorin Olsen
 
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP apps
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP appsphp[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP apps
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP appsPablo Godel
 
JSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJonathan Klein
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applicationsashleypuls
 
DevOps: Getting Started with Puppet on Windows
DevOps: Getting Started with Puppet on WindowsDevOps: Getting Started with Puppet on Windows
DevOps: Getting Started with Puppet on WindowsRob Reynolds
 
How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)Rodrigo Ayala
 
From Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEFrom Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEintelliyole
 
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Olaf Alders
 
Engineering culture
Engineering cultureEngineering culture
Engineering culturePamela Fox
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSPablo Godel
 
Front-End Performance Starts On the Server
Front-End Performance Starts On the ServerFront-End Performance Starts On the Server
Front-End Performance Starts On the ServerJon Arne Sæterås
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AnglePablo Godel
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 

Similar to Writing SaltStack Modules - OpenWest 2013 (20)

Introduction to PhoneGap and PhoneGap Build
Introduction to PhoneGap and PhoneGap BuildIntroduction to PhoneGap and PhoneGap Build
Introduction to PhoneGap and PhoneGap Build
 
Tools/Processes for serious android app development
Tools/Processes for serious android app developmentTools/Processes for serious android app development
Tools/Processes for serious android app development
 
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
eSynergy Andy Hawkins - Enabling DevOps through next generation configuration...
 
Building fb mobile
Building fb mobileBuilding fb mobile
Building fb mobile
 
App Engine Meetup
App Engine MeetupApp Engine Meetup
App Engine Meetup
 
Hadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopHadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoop
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby Conference
 
De-Google Your Life
De-Google Your LifeDe-Google Your Life
De-Google Your Life
 
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP apps
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP appsphp[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP apps
php[architect] Summit Series DevOps 2013 - Rock solid deployment of PHP apps
 
JSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web DesignJSDay 2013 - Practical Responsive Web Design
JSDay 2013 - Practical Responsive Web Design
 
Troubleshooting Live Java Web Applications
Troubleshooting Live Java Web ApplicationsTroubleshooting Live Java Web Applications
Troubleshooting Live Java Web Applications
 
DevOps: Getting Started with Puppet on Windows
DevOps: Getting Started with Puppet on WindowsDevOps: Getting Started with Puppet on Windows
DevOps: Getting Started with Puppet on Windows
 
How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)How to be a Chef (Developer Edition)
How to be a Chef (Developer Edition)
 
From Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDEFrom Renamer Plugin to Polyglot IDE
From Renamer Plugin to Polyglot IDE
 
Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013Ab(Using) the MetaCPAN API for Fun and Profit v2013
Ab(Using) the MetaCPAN API for Fun and Profit v2013
 
Engineering culture
Engineering cultureEngineering culture
Engineering culture
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
Front-End Performance Starts On the Server
Front-End Performance Starts On the ServerFront-End Performance Starts On the Server
Front-End Performance Starts On the Server
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 

More from SaltStack

Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceSaltStack
 
Spot Trading - A case study in continuous delivery for mission critical finan...
Spot Trading - A case study in continuous delivery for mission critical finan...Spot Trading - A case study in continuous delivery for mission critical finan...
Spot Trading - A case study in continuous delivery for mission critical finan...SaltStack
 
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web ScaleSaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web ScaleSaltStack
 
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)SaltStack
 
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...SaltStack
 
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...SaltStack
 
Configuration Management - Finding the tool to fit your needs
Configuration Management - Finding the tool to fit your needsConfiguration Management - Finding the tool to fit your needs
Configuration Management - Finding the tool to fit your needsSaltStack
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltStack
 
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStackSaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStackSaltStack
 
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStack
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStackSaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStack
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStackSaltStack
 
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...SaltStack
 
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...SaltStack
 
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltStack
 
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and States
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and StatesSaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and States
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and StatesSaltStack
 
SaltConf14 - Brendan Burns, Google - Management at Google Scale
SaltConf14 - Brendan Burns, Google - Management at Google ScaleSaltConf14 - Brendan Burns, Google - Management at Google Scale
SaltConf14 - Brendan Burns, Google - Management at Google ScaleSaltStack
 
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOps
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOpsSaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOps
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOpsSaltStack
 
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltStack
 
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...SaltStack
 
SaltStack - An open source software story
SaltStack - An open source software storySaltStack - An open source software story
SaltStack - An open source software storySaltStack
 
Real-time Cloud Management with SaltStack
Real-time Cloud Management with SaltStackReal-time Cloud Management with SaltStack
Real-time Cloud Management with SaltStackSaltStack
 

More from SaltStack (20)

Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
 
Spot Trading - A case study in continuous delivery for mission critical finan...
Spot Trading - A case study in continuous delivery for mission critical finan...Spot Trading - A case study in continuous delivery for mission critical finan...
Spot Trading - A case study in continuous delivery for mission critical finan...
 
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web ScaleSaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
SaltConf14 - Craig Sebenik, LinkedIn - SaltStack at Web Scale
 
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)
Salt Air 19 - Intro to SaltStack RAET (reliable asyncronous event transport)
 
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...
Arnold Bechtoldt, Inovex GmbH Linux systems engineer - Configuration Manageme...
 
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...
SaltConf14 - Matthew Williams, Flowroute - Salt Virt for Linux contatiners an...
 
Configuration Management - Finding the tool to fit your needs
Configuration Management - Finding the tool to fit your needsConfiguration Management - Finding the tool to fit your needs
Configuration Management - Finding the tool to fit your needs
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
 
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStackSaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
 
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStack
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStackSaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStack
SaltConf14 - Yazz Atlas, HP Cloud - Installing OpenStack using SaltStack
 
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...
SaltConf14 - Anita Kuno, HP & OpenStack - Using SaltStack for event-driven or...
 
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...
SaltConf14 - Saurabh Surana, HP Cloud - Automating operations and support wit...
 
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
 
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and States
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and StatesSaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and States
SaltConf14 - Forrest Alvarez, Choice Hotels - Salt Formulas and States
 
SaltConf14 - Brendan Burns, Google - Management at Google Scale
SaltConf14 - Brendan Burns, Google - Management at Google ScaleSaltConf14 - Brendan Burns, Google - Management at Google Scale
SaltConf14 - Brendan Burns, Google - Management at Google Scale
 
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOps
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOpsSaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOps
SaltConf14 - Justin Carmony, Deseret Digital Media - Teaching Devs About DevOps
 
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
 
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...
SaltConf14 - Eric johnson, Google - Orchestrating Google Compute Engine with ...
 
SaltStack - An open source software story
SaltStack - An open source software storySaltStack - An open source software story
SaltStack - An open source software story
 
Real-time Cloud Management with SaltStack
Real-time Cloud Management with SaltStackReal-time Cloud Management with SaltStack
Real-time Cloud Management with SaltStack
 

Recently uploaded

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Writing SaltStack Modules - OpenWest 2013

  • 1. Writing Salt Modules Joseph Hall Senior Engineer at SaltStack, Inc. Presented at OpenWest 2013 1Friday, June 7, 13
  • 2. The future of technology is dependent upon our ability to effectively utilize infrastructures at any scale. 2Friday, June 7, 13
  • 3. What Salt Does Salt is a Remote Execution framework, which enables functionality such as: • Configuration Management • Cloud Management • Monitoring • Alerting • Responding to Alerts • etc. 3Friday, June 7, 13
  • 4. What do these things all have in common? Every component on the previous slide is a function of distributed computing. So why not also use Salt to do the things that we think about, when we think about distributed computing? 4Friday, June 7, 13
  • 6. Not Playing the Same Game Flickr photo by kawwsu29 Flickr photo by ant.photos 6Friday, June 7, 13
  • 7. Things that Should Be Salted Flickr photo by gdgt buzz Flickr photo by Toronto Home Theater Flickr photo by IntelFreePress Photo by Joseph Hall 7Friday, June 7, 13
  • 8. A Basic Use Case Writing a simple web crawler • Need to collect various web pages • Use multiple nodes to collect data • Return web content to salt-master for storage 8Friday, June 7, 13
  • 9. Using urllib2 for Our Crawler • Easy to use • Ships with Python • Negates need to install 3rd party dependencies • If a more complex spider is needed, a 3rd party library can be used o If the 3rd party module is not installed, the module needs to know not to make itself available, via the __virtual__() function 9Friday, June 7, 13
  • 10. Execution Module Basics • The __virtual__() function o Not technically required, but is a best practice o Executed when salt-minion is loaded o Identifies the module name o Commonly used to identify whether a module should be made available • Private functions o Name starts with underscore o Only used internally by the module o Will not show up in sys.doc • Public functions o Called directly by salt commands o Will show up in sys.doc 10Friday, June 7, 13
  • 11. A Few Basics • PEP-8 is your friend • The Salt Style Guide supersedes PEP-8 • Always use docstrings • Avoid late imports • Use (proper) logging o Do not use warn/error when info is correct o Do not use info when debug is correct o Do not add log messages to __virtual__() 11Friday, June 7, 13
  • 12. Using the Salt Logging System import logging log = logging.getLogger(__name__) log.info('Always useful to users') log.warn('Something isn't right, but I can still continue') log.error('Something is definitely wrong, and should be fixed') log.debug('Only developers care about me') 12Friday, June 7, 13
  • 13. Sample __virtual__() Function try: import urllib2 HAS_URLLIB2 = True except: HAS_URLLIB2 = False def __virtual__(): if HAS_URLLIB2 is True: return 'crawler' return False 13Friday, June 7, 13
  • 14. Sample Private Function def _query(url): result = urllib2.urlopen(url) return { 'url': result.url, 'code': result.code, 'msg': result.msg, 'headers': result.headers.dict, 'content': result.read(), } 14Friday, June 7, 13
  • 15. Sample Public Function def fetch(urls=None): ret = {} if type(urls) is str: ret[urls] = _query(urls) elif type(urls) is list: for url in urls: ret[url] = _query(url) return ret 15Friday, June 7, 13
  • 16. Using Docstrings def fetch(urls=None): ''' Fetch a URL CLI Example:: salt myminion crawler.download http:// www.mydomain.com/ ''' ...SNIP... 16Friday, June 7, 13
  • 17. Using our New Module (command line) Testing/debugging locally: • salt-call --local -l debug crawler.fetch http:// tinyurl.com/cnyypk From the salt-master: • salt myminion crawler.fetch http://tinyurl.com/ cnyypk 17Friday, June 7, 13
  • 18. Ready for more? Let's write a salt runner! 18Friday, June 7, 13
  • 19. Bootstrapping a Runner • manage.py is a good example runner • cp manage.py yourrunnername.py • Make changes to suit your needs o status() has the actual client in it o up() and down() use the data to form a report 19Friday, June 7, 13
  • 20. Using the LocalClient import salt.client client = salt.client.LocalClient( __opts__['conf_file'], ) minions = client.cmd( '*', 'test.ping', timeout=__opts__['timeout'], ) 20Friday, June 7, 13
  • 21. Returning Output import salt.output data = some_stuff() salt.output.display_output(data, '', __opts__) 21Friday, June 7, 13
  • 22. Which Minions to Use? • Maybe we don't want to use all of our minions for crawling. • Just using the minions that have our crawler installed is sloppy and indeterminate • So let's explicitly define which minions to use, in a configurable location 22Friday, June 7, 13
  • 23. Setting Up a Pillar # cat /srv/pillar/top.sls base: 'spider*': - crawler # cat /srv/pillar/crawler.sls crawler.enabled: True 23Friday, June 7, 13
  • 24. Targeting the Pillar minions = client.cmd( 'crawler.enabled:True', 'test.ping', timeout=__opts__['timeout'], expr_form='pillar', ) 24Friday, June 7, 13
  • 25. Fetching From a Minion def fetch(urls=None): minions = up() client = salt.client.LocalClient( __opts__['conf_file']) data = client.cmd(minions[0], 'crawler.fetch', arg=[urls], timeout=__opts__['timeout']) for minion in data.keys(): for url in data[minion]: data[minion][url]['content'] = '' salt.output.display_output( data, '', __opts__) 25Friday, June 7, 13
  • 26. Resources Slides Available At: http://tinyurl.com/utos-salt-modules-2013 Sources Available At: https://github.com/techhat/salt-crawler/ Find me on Twitter: @techhat 26Friday, June 7, 13