knife-vagrant 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/chef/knife/vagrant_server.rb +30 -0
  2. metadata +1 -1
@@ -73,6 +73,13 @@ module KnifePlugins
73
73
  require 'vagrant/cli'
74
74
  end
75
75
 
76
+ option :networks,
77
+ :short => '-n NETWORKS',
78
+ :long => '--networks ',
79
+ :description => 'Network definitions. Comma separated network entries containing type:data Pairs. Where data is network adress or bridge info',
80
+ :proc => lambda { |o| o.split(/,/).collect { |a| a.split(/:/) } },
81
+ :default => []
82
+
76
83
  option :port_forward,
77
84
  :short => '-p PORTS',
78
85
  :long => '--port-forward PORTS',
@@ -125,6 +132,28 @@ module KnifePlugins
125
132
  ports.collect { |k, v| "config.vm.forward_port(#{k}, #{v})" }.join("\n")
126
133
  end
127
134
 
135
+ def parse_hostonly(network)
136
+ addr, mask = network.split("/")
137
+ config = "\"#{addr}\""
138
+ if mask
139
+ config << ", :netmask => \"#{mask}\""
140
+ end
141
+ config
142
+ end
143
+
144
+ def build_networks(networks)
145
+ output = ""
146
+ puts "DEBUG: Networks: #{networks.inspect}"
147
+ networks.each do |net|
148
+ case net[0].downcase
149
+ when "bridge"
150
+ output << "config.vm.network :bridged, :bridge => #{net[1]}\n"
151
+ when "hostonly"
152
+ output << "config.vm.network :hostonly, #{parse_hostonly(net[1])}\n"
153
+ end
154
+ end
155
+ end
156
+
128
157
  # TODO: see if there's a way to pass this whole thing in as an object or hash or something, instead of writing a file to disk.
129
158
  def build_vagrantfile
130
159
  file = <<-EOF
@@ -135,6 +164,7 @@ module KnifePlugins
135
164
  config.vm.customize [ "modifyvm", :id, "--memory", #{config[:memsize]} ]
136
165
  config.vm.customize [ "modifyvm", :id, "--name", "#{config[:hostname]}" ]
137
166
  config.vm.box_url = "#{config[:box_url]}"
167
+ #{build_networks(config[:networks])}
138
168
  config.vm.provision :chef_client do |chef|
139
169
  chef.chef_server_url = "#{Chef::Config[:chef_server_url]}"
140
170
  chef.validation_key_path = "#{Chef::Config[:validation_key]}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: