vagrant plugin development intro

21
Vagrant Plugin Development Intro @budhrg @budhrg budhram #IRC Work @ Budh Ram Gurung Blog @ http://budhram.info

Upload: budh-ram-gurung

Post on 23-Feb-2017

350 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Vagrant plugin development intro

Vagrant Plugin Development

Intro

@budhrg

@budhrg

budhram#IRC

Work @

Budh Ram Gurung

Blog @ http://budhram.info

Page 2: Vagrant plugin development intro

What is Vagrant?

● VM Management Tool

● Automate development environment setup

● Close friend of Developer

Page 3: Vagrant plugin development intro

About Vagrant Plugin

● Plugin Centric

● Most basic features are implemented via built-in plugins

● Internal and external plugins uses the same API

Page 4: Vagrant plugin development intro

Available Vagrant Plugins

• vagrant-aws • vagrant-omnibus • vagrant-foodshow

• vagrant-digitalocean • vagrant-fabric • vagrant-hostsupdater

• vagrant-google • vagrant-berkshelf • vagrant-reload

• vagrant-libvirt • vagrant-librarian-chef • vagrant-vbguest

• vagrant-lxc • vagrant-librarian-puppet • oh-my-vagrant

• vagrant-openstack • vagrant-puppet-install • sahara

• vagrant-parallels • vagrant-cachier • landrush

• vagrant-rackspace • vagrant-serverspec • <...>

Page 5: Vagrant plugin development intro

Let’s build

a

Simple Plugin

https://www.noppanit.com/create-simple-vagrant-pluginCredits -

Page 6: Vagrant plugin development intro

Create directories/files

../vagrant-ls $ mkdir lib lib/vagrant-ls

../vagrant-ls $ touch Gemfile vagrant-ls.gemspec Rakefile lib/vagrant-ls.rb lib/vagrant-ls/version.rb lib/vagrant-ls/plugin.rb lib/vagrant-ls/command.rb

../demo $ mkdir vagrant-ls && cd vagrant-ls

Page 7: Vagrant plugin development intro

Gemfile

source 'https://rubygems.org'

group :development do gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git' gem 'json' gem 'rake' gem 'bundler', '~> 1.6'end

group :plugins do gem 'vagrant-ls', path: '.'end

Page 8: Vagrant plugin development intro

vagrant-ls.gemspec

require File.expand_path('../lib/vagrant-ls/version', __FILE__)

Gem::Specification.new do |s| s.name = 'vagrant-ls' s.version = VagrantPlugins::Ls::VERSION s.summary = "List all vms" s.description = "A simple vagrant plugin for listing all vms" s.authors = ["Budh Ram Gurung"] s.email = '[email protected]' ... ... other common configurations ... ...end

Page 9: Vagrant plugin development intro

Rakefile

require 'bundler/gem_tasks'

Page 10: Vagrant plugin development intro

lib/vagrant-ls.rb

begin require 'vagrant'rescue LoadError raise 'The Vagrant vagrant-ls plugin must be run within Vagrant.'end

require 'vagrant-ls/plugin'

Page 11: Vagrant plugin development intro

lib/vagrant-ls/version.rb

module VagrantPlugins module Ls VERSION = '0.0.1' endend

Page 12: Vagrant plugin development intro

lib/vagrant-ls/plugin.rb

module VagrantPlugins module Ls class Plugin < Vagrant.plugin('2') name "List"

description “This plugin 'ls' all of the vms running inside the machine”

command 'ls' do require_relative 'command' Command end end endend

Page 13: Vagrant plugin development intro

lib/vagrant-ls/command.rb (actual implementation)

module VagrantPlugins module Ls class Command < Vagrant.plugin('2', :command) def execute # Your plugin logic

exec('VBoxManage list vms') 0 end end endend

Page 14: Vagrant plugin development intro

../vagrant-ls $ bundle exec vagrant list-commandsBelow is a listing of all available Vagrant commands and a briefdescription of what they do.

box manages boxes: installation, removal, etc.halt stops the vagrant machinehelp shows the help for a subcommand..........................................................................................ls list all of the vms running inside the machine..........................................................................................suspend suspends the machineup starts and provisions the vagrant environmentversion prints current and latest Vagrant version

Check your command

Page 15: Vagrant plugin development intro

../vagrant-ls $ bundle exec vagrant ls

"win7-ie10_default_1456812636294_67555" {4edcfa84-627c-446d-8ba4-311c6c2b134b}"vagrant-devtools_default_1458233788740_76759" {7ef9b907-1bd1-4d39-92e5-2a3c572128d0}"test_adb_default_1458279527566_54262" {19d3a56b-2f73-428f-b34b-edffe8ec2ca5}"vagrant-ls_default_1458362268506_16566" {12d4eec5-20bc-4129-b993-a4170b6937e3}"vagrant-service-manager_default_1458367027826_45167" {820afb23-3651-424e-9236-1d54cd9b4a49}

Run your command

Page 16: Vagrant plugin development intro

Build your plugin

../vagrant-ls $ rake build

vagrant-ls 0.0.1 built to pkg/vagrant-ls-0.0.1.gem.

Page 17: Vagrant plugin development intro

● vagrant-service-manager ○ Provides services setup information○ Environment variables○ TLS certificates○ Services like Docker, Openshift etc

We are working on a plugin

● Hosted @

https://github.com/projectatomic/vagrant-service-manager

Page 18: Vagrant plugin development intro

Graphical Overview

Page 19: Vagrant plugin development intro

../demo $ vagrant init projectatomic/adb

../demo $ vagrant plugin install vagrant-service-manager

../demo $ vagrant up

How to start?

Page 20: Vagrant plugin development intro

../demo eval "$(bundle exec vagrant service-manager env docker)"

How to use plugin?

# Pre-requisite : Docker Client# Check Docker

./demo $ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

Page 21: Vagrant plugin development intro

Thanks