SlideShare a Scribd company logo
1 of 16
How to create a
libcloud driver from scratch
the NephoScale case
Libcloud
one library to rule them all
Supports many providers
What if your provider is not
supported?
● Clone
● Branch
● Write
● Test
● Merge back
Time to contribute
Tasklist
Backend actions
● list_nodes: list all nodes, including ip addresses, node state, metadata, etc
● list_images: list all the images the provider supports
● list_sizes: list different plans, providing data such as CPU, ram and disk size
● list_locations: List all available provider zones when applicable
Tasklist
Node actions
● create_node: create a node specifying it’s size, image, name and location
● deploy_node: create a node and deploy a public ssh key and optionally run a
deploy script
● reboot_node/shut down_node
● start_node/stop_node: start a stopped node, or stop a started one
● destroy_node: Delete the node
Getting ready
APIs and drivers
● Familiarize yourself with the provider API
● Choose a recent libcloud driver to base your code on
● Don’t break conventions. Do it the libcloud way
libcloud repo
Clone and extend
● Clone libcloud from https://github.com/apache/libcloud
● Libcloud drivers live in libcloud/compute/drivers
● They all inherit from the base driver at libcloud/compute/base.py
● Create your git branch
● Add your driver on libcloud/compute/providers.py
Create driver file
Create libcloud/compute/drivers/nephoscale.py
Specify the cloud provider API endpoint
API_HOST = 'api.nephoscale.com'
and the possible node states
NODE_STATE_MAP = {
'on': NodeState.RUNNING,
'off': NodeState.UNKNOWN,
'unknown': NodeState.UNKNOWN,
}
Writing the driver
We need to create a NodeDriver based driver
class NephoscaleNodeDriver(NodeDriver):
"""Nephoscale node driver class"""
type = Provider.NEPHOSCALE
api_name = 'nephoscale'
name = 'NephoScale'
website = 'http://www.nephoscale.com'
connectionCls = NephoscaleConnection
features = {'create_node': ['ssh_key']}
def list_locations(self):
...
Writing the Connection class
and write a Connection class
class NephoscaleConnection(ConnectionUserAndKey):
host = API_HOST
responseCls = NephoscaleResponse
def add_default_headers(self, headers):
user_b64 = base64.b64encode(b('%s:%s' % (self.user_id,
self.key)))
headers['Authorization'] = 'Basic %s' %
(user_b64.decode('utf-8'))
return headers
Writing the Response class
Response classes derive from JsonResponse or XMLRPCResponse
class NephoscaleResponse(JsonResponse):
"""Nephoscale API Response"""
def parse_error(self):
if self.status == httplib.UNAUTHORIZED:
raise InvalidCredsError('Authorization Failed')
if self.status == httplib.NOT_FOUND:
raise Exception("The resource you are looking for is not
found.")
return self.body
Keep consistency
Keep consistency, hardcode things when necessary
● Most of the times you don’t need to override deploy_node
● Libcloud standardizes things for providers (nodes/sizes/images/locations)
● When a provider does non-standard stuff, override
● Some providers don’t return enough details
● Hardcode only when necessary
Testing the driver
Test your driver often to make sure it works
user@user:~/dev/libcloud$ python
>>> from libcloud.compute.types import Provider
>>> from libcloud.compute.providers import get_driver
>>> driver = get_driver(Provider.NEPHOSCALE)
>>> conn = driver('user','correct_password')
>>> conn.list_nodes()
[<Node: uuid=e20bdbf7ef6890645f5b217e0bd2b5912b969cc1,
name=nepho-7, state=0, public_ips=['198.89.109.116'],
provider=NephoScale ...>]
Contributing to libcloud
Some ground rules and contribution workflow:
● Open a ticket on the tracker to notify any interested parties
● Write unit tests
● Follow code style (follow PEP8, use spaces for tabs, etc)
● Commit and open a pull request
● Wait for a review and make any changes pointed
● Create a patch with your changes and add it to your ticket
Thank you!
To check the driver in action, visit https://mist.io
More resources:
● https://libcloud.readthedocs.org/en/latest/development.html
● https://github.com/apache/libcloud
● https://libcloud.readthedocs.org/en/latest/developer_information.html
Special thanks to Tomaz, maintainer of libcloud and a very helpful guy :)

More Related Content

What's hot

Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 

What's hot (20)

Express node js
Express node jsExpress node js
Express node js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Express js
Express jsExpress js
Express js
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Development of Ansible modules
Development of Ansible modulesDevelopment of Ansible modules
Development of Ansible modules
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 

Viewers also liked

αίσιο τέλος, διήγημα
αίσιο τέλος, διήγημααίσιο τέλος, διήγημα
αίσιο τέλος, διήγημα
artedinou
 
Learning activity progress- Sarah
Learning activity progress- SarahLearning activity progress- Sarah
Learning activity progress- Sarah
sarahmobilelearning
 
Area and perimeter (1)
Area and perimeter (1)Area and perimeter (1)
Area and perimeter (1)
Mari QZ
 
Ingi_El-Azizi 2014 - Copy
Ingi_El-Azizi  2014 - CopyIngi_El-Azizi  2014 - Copy
Ingi_El-Azizi 2014 - Copy
Ingi Elazizi
 
Educational Transformation with Media
Educational Transformation with MediaEducational Transformation with Media
Educational Transformation with Media
TerryKH2006
 
Golden ages of Florence
Golden ages of FlorenceGolden ages of Florence
Golden ages of Florence
skate99
 
Curriculum Vitae_Sudhan R with 2Yr`s Experience
Curriculum Vitae_Sudhan R with 2Yr`s ExperienceCurriculum Vitae_Sudhan R with 2Yr`s Experience
Curriculum Vitae_Sudhan R with 2Yr`s Experience
SUDHAN R
 
Wee cig presentation
Wee cig presentationWee cig presentation
Wee cig presentation
dennislzf
 

Viewers also liked (20)

Improving notes addressing experience with recent contacts
Improving notes addressing experience with recent contactsImproving notes addressing experience with recent contacts
Improving notes addressing experience with recent contacts
 
αίσιο τέλος, διήγημα
αίσιο τέλος, διήγημααίσιο τέλος, διήγημα
αίσιο τέλος, διήγημα
 
Learning activity progress- Sarah
Learning activity progress- SarahLearning activity progress- Sarah
Learning activity progress- Sarah
 
Area and perimeter (1)
Area and perimeter (1)Area and perimeter (1)
Area and perimeter (1)
 
0026 resistencia
0026 resistencia0026 resistencia
0026 resistencia
 
Measuring What Really Matters: Search Engine Metrics & Tracking Tips - David ...
Measuring What Really Matters: Search Engine Metrics & Tracking Tips - David ...Measuring What Really Matters: Search Engine Metrics & Tracking Tips - David ...
Measuring What Really Matters: Search Engine Metrics & Tracking Tips - David ...
 
Gta 5
Gta 5Gta 5
Gta 5
 
Ingi_El-Azizi 2014 - Copy
Ingi_El-Azizi  2014 - CopyIngi_El-Azizi  2014 - Copy
Ingi_El-Azizi 2014 - Copy
 
Photography
Photography Photography
Photography
 
Educational Transformation with Media
Educational Transformation with MediaEducational Transformation with Media
Educational Transformation with Media
 
Dung si Monti_Ep 01
Dung si Monti_Ep 01Dung si Monti_Ep 01
Dung si Monti_Ep 01
 
Avoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrcAvoiding conflict and litigation with hmrc
Avoiding conflict and litigation with hmrc
 
Epis
EpisEpis
Epis
 
Golden ages of Florence
Golden ages of FlorenceGolden ages of Florence
Golden ages of Florence
 
Декада
ДекадаДекада
Декада
 
Dung si Monti - Ep 03
Dung si Monti - Ep 03Dung si Monti - Ep 03
Dung si Monti - Ep 03
 
Curriculum Vitae_Sudhan R with 2Yr`s Experience
Curriculum Vitae_Sudhan R with 2Yr`s ExperienceCurriculum Vitae_Sudhan R with 2Yr`s Experience
Curriculum Vitae_Sudhan R with 2Yr`s Experience
 
Tujuan
TujuanTujuan
Tujuan
 
Hi-Lok Installation
Hi-Lok InstallationHi-Lok Installation
Hi-Lok Installation
 
Wee cig presentation
Wee cig presentationWee cig presentation
Wee cig presentation
 

Similar to How to create a libcloud driver from scratch

How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
Juan Maiz
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
Inada Naoki
 

Similar to How to create a libcloud driver from scratch (20)

Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Working in the multi-cloud with libcloud
Working in the multi-cloud with libcloudWorking in the multi-cloud with libcloud
Working in the multi-cloud with libcloud
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for us
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun..."ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Chef solo the beginning
Chef solo the beginning Chef solo the beginning
Chef solo the beginning
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 

Recently uploaded

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
Asmae Rabhi
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 

Recently uploaded (20)

20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 

How to create a libcloud driver from scratch

  • 1. How to create a libcloud driver from scratch the NephoScale case
  • 2. Libcloud one library to rule them all
  • 4. What if your provider is not supported? ● Clone ● Branch ● Write ● Test ● Merge back Time to contribute
  • 5. Tasklist Backend actions ● list_nodes: list all nodes, including ip addresses, node state, metadata, etc ● list_images: list all the images the provider supports ● list_sizes: list different plans, providing data such as CPU, ram and disk size ● list_locations: List all available provider zones when applicable
  • 6. Tasklist Node actions ● create_node: create a node specifying it’s size, image, name and location ● deploy_node: create a node and deploy a public ssh key and optionally run a deploy script ● reboot_node/shut down_node ● start_node/stop_node: start a stopped node, or stop a started one ● destroy_node: Delete the node
  • 7. Getting ready APIs and drivers ● Familiarize yourself with the provider API ● Choose a recent libcloud driver to base your code on ● Don’t break conventions. Do it the libcloud way
  • 8. libcloud repo Clone and extend ● Clone libcloud from https://github.com/apache/libcloud ● Libcloud drivers live in libcloud/compute/drivers ● They all inherit from the base driver at libcloud/compute/base.py ● Create your git branch ● Add your driver on libcloud/compute/providers.py
  • 9. Create driver file Create libcloud/compute/drivers/nephoscale.py Specify the cloud provider API endpoint API_HOST = 'api.nephoscale.com' and the possible node states NODE_STATE_MAP = { 'on': NodeState.RUNNING, 'off': NodeState.UNKNOWN, 'unknown': NodeState.UNKNOWN, }
  • 10. Writing the driver We need to create a NodeDriver based driver class NephoscaleNodeDriver(NodeDriver): """Nephoscale node driver class""" type = Provider.NEPHOSCALE api_name = 'nephoscale' name = 'NephoScale' website = 'http://www.nephoscale.com' connectionCls = NephoscaleConnection features = {'create_node': ['ssh_key']} def list_locations(self): ...
  • 11. Writing the Connection class and write a Connection class class NephoscaleConnection(ConnectionUserAndKey): host = API_HOST responseCls = NephoscaleResponse def add_default_headers(self, headers): user_b64 = base64.b64encode(b('%s:%s' % (self.user_id, self.key))) headers['Authorization'] = 'Basic %s' % (user_b64.decode('utf-8')) return headers
  • 12. Writing the Response class Response classes derive from JsonResponse or XMLRPCResponse class NephoscaleResponse(JsonResponse): """Nephoscale API Response""" def parse_error(self): if self.status == httplib.UNAUTHORIZED: raise InvalidCredsError('Authorization Failed') if self.status == httplib.NOT_FOUND: raise Exception("The resource you are looking for is not found.") return self.body
  • 13. Keep consistency Keep consistency, hardcode things when necessary ● Most of the times you don’t need to override deploy_node ● Libcloud standardizes things for providers (nodes/sizes/images/locations) ● When a provider does non-standard stuff, override ● Some providers don’t return enough details ● Hardcode only when necessary
  • 14. Testing the driver Test your driver often to make sure it works user@user:~/dev/libcloud$ python >>> from libcloud.compute.types import Provider >>> from libcloud.compute.providers import get_driver >>> driver = get_driver(Provider.NEPHOSCALE) >>> conn = driver('user','correct_password') >>> conn.list_nodes() [<Node: uuid=e20bdbf7ef6890645f5b217e0bd2b5912b969cc1, name=nepho-7, state=0, public_ips=['198.89.109.116'], provider=NephoScale ...>]
  • 15. Contributing to libcloud Some ground rules and contribution workflow: ● Open a ticket on the tracker to notify any interested parties ● Write unit tests ● Follow code style (follow PEP8, use spaces for tabs, etc) ● Commit and open a pull request ● Wait for a review and make any changes pointed ● Create a patch with your changes and add it to your ticket
  • 16. Thank you! To check the driver in action, visit https://mist.io More resources: ● https://libcloud.readthedocs.org/en/latest/development.html ● https://github.com/apache/libcloud ● https://libcloud.readthedocs.org/en/latest/developer_information.html Special thanks to Tomaz, maintainer of libcloud and a very helpful guy :)

Editor's Notes

  1. Libcloud allows users to manage four different cloud resources: Cloud Servers, Cloud Storage, Load Balancers as a Service and DNS as a Service. Cloud Servers is the oldest and more mature part of the library and currently supports more than 40 providers.
  2. Many cloud providers eg Amazon, Rackspace, Openstack etc, are already supported by libcloud. But what if your favorite provider isn’t?
  3. We’ll just create one ourselves. Libcloud is an open-source project with solid documentation and lots of code examples.
  4. The are two main sets of actions we need to support. Backend actions that are provider/account specific.
  5. and node actions that refer to a specific node (Virtual Machine). Most of them our self-explanatory. deploy_node runs create node and supplies a public ssh key for server access. It can optionally wait for the server to come online and deploy a script.
  6. We’ll need access to our provider API. In this scenario, the Nephoscale API. We will use the Digital Ocean driver as a template as it is one of the most recent, well written and up-to-date drivers. There is an effort by libcloud to standardize the basic functionality for all the compute drivers, and update the oldest ones.
  7. We’ll start by cloning the libcloud repo. All our drivers are in /libcloud/compute/drivers Every driver inherits from the main base driver at libcloud/compute/base.py We’ll create a git branch and add our driver on the DRIVERS dict on libcloud/compute/providers.py And our Provider class on libcloud/compute/types.py We will use the Digital Ocean driver as a template as it is one of the most recent, well written and up-to-date drivers. There is an effort by libcloud to standardize the basic functionality for all the compute drivers, and update the oldest ones.
  8. On libcloud/compute/drivers/ we create a file with the name of our provider: nephoscale.py in our case. After the initial imports that we copy from the Digital Ocean driver, we specify the API endpoint of our cloud provider and a dict with the states that the nodes can have. This differs from provider to provider, with some providers having just a few states -running, stopped - and others having intermediates ones -e.g. rebooting, shutting down etc.
  9. Here we specify the type (same as on libcloud/compute/types.py), the connection class (NephoscaleConnection) and a features dict with the way deploy_node will try to authenticate to the created node after create_node has run . Inside the NephoscaleNodeDriver is where all our functions will live. We’ll write all functions we want to implement there, list_images, list_nodes, reboot_node etc. To keep consistency, we make sure that list_nodes returns a list of Node objects, list_images a list of NodeImage objects, list_sizes a list of NodeSize objects and list_locations a list of NodeLocation objects.
  10. NephoscaleConnection is the Connection class that will handle connection, authentication and send the request to the NephoScale API endpoint. All drivers implement a Connection class that is responsible for sending the request data, adding HTTP headers or params and also encoding the request body.The API host endpoint is specified there, along with the HTTP headers or params that are used to authenticate for each provider. NephoScale API calls require HTTP Basic Authentication with the user/password base64 encoded on every request, so we’ll add it to add_default_params. Other providers handle authentication with requiring the params on each request -API key, password, secret etc.
  11. All drivers also need a response class that handles responses of the API endpoint, parses body and returns Exceptions or the actual return content. Response classes for the libcloud drivers derive from JsonResponse or XMLRPCResponse, depending on the response type of the cloud provider -Json or XML. Both derive from Response class that lives in libcloud/common/base.py. We want to make sure here that in the case of errors we throw the correct exceptions - e.g. InvalidCredsError for failed authentication
  12. Most of the drivers of libcloud implement create_node to return a Node object, of the newly created host. Function deploy_node is not overridden , but instead gets called from the NodeDriver, since it does a lot of things that need not be rewritten, such as checks that the node public ip is up, that the machine can be accessible, that it can authenticate via password or ssh key, and optionally runs a deploy script. One of the cool things with libcloud is that it standardizes things. It enforces the use of basic entities -nodes, sizes, images, locations- for all cloud providers it supports. SoftLayer for example does not provide a size entity through it’s API, but rather expects that we specify CPU, RAM and disk size when we create a node. The way libcloud driver is implemented, one can either pass these manually, or simply select one of the sizes provided by list_sizes. Ideally all size/image/location related data should be fetched by asking the provider. When this is not possible, for example when the provider does not implement a request, we need to hard code these settings. For example the pricing info for some of the providers isn’t returned while asking for the sizes (list_sizes) and thus is hard coded on libcloud/data/pricing.json
  13. Having created the compute driver for our cloud provider and having tested it’s functionality, it is time to commit it to libcloud. In this case we need to write tests -ideally for all functionality, add some fixtures and make sure the tests pass. Libcloud contains unit tests for nearly everything and enforces testing for new functionality. Use the codestyle proposed by libcloud, follow the workflow and your patch will be accepted to trunk.
  14. Have fun developing your driver! To check this driver in action log in to mist.io Special thanks to Tomaz, maintainer of liblcoud and it’s bigger laborer of love, for proof reading this text.