vagrant-openwrt 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b110be120953f3e7769128537368823b5632a47
4
+ data.tar.gz: 28f41cc274a80554bffeca911b2b99d6a55c9b54
5
+ SHA512:
6
+ metadata.gz: 6c1fc621ea7564ad3155249cf066137a10f45d0e5ac261ba249749e2ee8bc5a7e31bb5d7320b2bb59a11eb37d27e5ff13a1b6689722698f5e84cb64b210e3b1a
7
+ data.tar.gz: ab9d3045db2c1457a3483ed25e20d28b0a2b8182cbe2cba73e56ebe470c610a96e4341db34099290890f10e44226426da3130b7debb93e36c62cc818f896b628
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /.vagrant
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-openwrt", path: "."
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hanfei Shen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Vagrant::OpenWrt
2
+
3
+ OpenWrt guest support.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vagrant-openwrt'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vagrant-openwrt
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/qqshfox/vagrant-openwrt/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ require "vagrant/openwrt"
@@ -0,0 +1,2 @@
1
+ require "vagrant/openwrt/version"
2
+ require "vagrant/plugins/guests/openwrt/plugin"
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module OpenWrt
3
+ VERSION = "0.1"
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ module VagrantPlugins
2
+ module GuestOpenWrt
3
+ module Cap
4
+ class ChangeHostName
5
+ def self.change_host_name(machine, name)
6
+ new(machine, name).change!
7
+ end
8
+
9
+ attr_reader :machine, :new_hostname
10
+
11
+ def initialize(machine, new_hostname)
12
+ @machine = machine
13
+ @new_hostname = new_hostname
14
+ end
15
+
16
+ def change!
17
+ return unless should_change?
18
+
19
+ update_etc_hostname
20
+ end
21
+
22
+ def should_change?
23
+ new_hostname != current_hostname
24
+ end
25
+
26
+ def current_hostname
27
+ @current_hostname ||= get_current_hostname
28
+ end
29
+
30
+ def get_current_hostname
31
+ hostname = ""
32
+ execute "uci get system.@system[0].hostname" do |type, data|
33
+ hostname = data.chomp if type == :stdout && hostname.empty?
34
+ end
35
+
36
+ hostname
37
+ end
38
+
39
+ def update_etc_hostname
40
+ execute(%{uci set system.@system[0].hostname="#{new_hostname}" && uci commit system})
41
+ end
42
+
43
+ def execute(cmd, &block)
44
+ machine.communicate.execute(cmd, &block)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ module VagrantPlugins
2
+ module GuestOpenWrt
3
+ module Cap
4
+ class ConfigureNetworks
5
+ def self.configure_networks(machine, networks)
6
+ new(machine, networks).configure!
7
+ rescue IOError
8
+ # Do nothing, because it probably means the machine shut down
9
+ # and SSH connection was lost.
10
+ end
11
+
12
+ attr_reader :machine, :networks
13
+
14
+ def initialize(machine, networks)
15
+ @machine = machine
16
+ @networks = networks
17
+ end
18
+
19
+ def configure!
20
+ lan = networks[0]
21
+ execute "uci set network.lan.ipaddr='#{lan[:ip]}'"
22
+
23
+ wan = networks[1]
24
+ execute "uci add network interface"
25
+ execute "uci rename network.@interface[-1]='wan'"
26
+ execute "uci set network.wan.ifname='eth1'"
27
+ execute "uci set network.wan.proto='#{wan[:type]}'"
28
+ if wan[:type] != :dhcp
29
+ execute "uci set network.wan.ipaddr='#{wan[:ip]}'"
30
+ execute "uci set network.wan.netmask='#{wan[:netmask]}'"
31
+ end
32
+
33
+ execute "uci commit network && /etc/init.d/network reload"
34
+ end
35
+
36
+ def execute(cmd, &block)
37
+ machine.communicate.execute(cmd, &block)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module GuestOpenWrt
3
+ module Cap
4
+ class Halt
5
+ def self.halt(machine)
6
+ machine.communicate.execute("poweroff")
7
+ rescue IOError
8
+ # Do nothing, because it probably means the machine shut down
9
+ # and SSH connection was lost.
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestOpenWrt
5
+ class Guest < Vagrant.plugin("2", :guest)
6
+ def detect?(machine)
7
+ machine.communicate.test("cat /etc/openwrt_release | grep 'OpenWrt'")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestOpenWrt
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "OpenWrt guest"
7
+ description "OpenWrt guest support."
8
+
9
+ guest "openwrt", "linux" do
10
+ require_relative "guest"
11
+ Guest
12
+ end
13
+
14
+ guest_capability "openwrt", "configure_networks" do
15
+ require_relative "cap/configure_networks"
16
+ Cap::ConfigureNetworks
17
+ end
18
+
19
+ guest_capability "openwrt", "change_host_name" do
20
+ require_relative "cap/change_host_name"
21
+ Cap::ChangeHostName
22
+ end
23
+
24
+ guest_capability "openwrt", "halt" do
25
+ require_relative "cap/halt"
26
+ Cap::Halt
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/openwrt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-openwrt"
8
+ spec.version = Vagrant::OpenWrt::VERSION
9
+ spec.authors = ["Hanfei Shen"]
10
+ spec.email = ["qqshfox@gmail.com"]
11
+ spec.summary = %q{OpenWrt guest}
12
+ spec.description = %q{OpenWrt guest support.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-openwrt
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Hanfei Shen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: OpenWrt guest support.
42
+ email:
43
+ - qqshfox@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/vagrant-openwrt.rb
54
+ - lib/vagrant/openwrt.rb
55
+ - lib/vagrant/openwrt/version.rb
56
+ - lib/vagrant/plugins/guests/openwrt/cap/change_host_name.rb
57
+ - lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb
58
+ - lib/vagrant/plugins/guests/openwrt/cap/halt.rb
59
+ - lib/vagrant/plugins/guests/openwrt/guest.rb
60
+ - lib/vagrant/plugins/guests/openwrt/plugin.rb
61
+ - vagrant-openwrt.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: OpenWrt guest
86
+ test_files: []