vagrant plugin development intro

Post on 23-Feb-2017

350 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Vagrant Plugin Development

Intro

@budhrg

@budhrg

budhram#IRC

Work @

Budh Ram Gurung

Blog @ http://budhram.info

What is Vagrant?

● VM Management Tool

● Automate development environment setup

● Close friend of Developer

About Vagrant Plugin

● Plugin Centric

● Most basic features are implemented via built-in plugins

● Internal and external plugins uses the same API

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 • <...>

Let’s build

a

Simple Plugin

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

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

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

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 = 'budhram.gurung01@gmail.com' ... ... other common configurations ... ...end

Rakefile

require 'bundler/gem_tasks'

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'

lib/vagrant-ls/version.rb

module VagrantPlugins module Ls VERSION = '0.0.1' endend

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

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

../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

../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

Build your plugin

../vagrant-ls $ rake build

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

● 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

Graphical Overview

../demo $ vagrant init projectatomic/adb

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

../demo $ vagrant up

How to start?

../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

Thanks

top related