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

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Recently uploaded (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

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