knife-vagrant 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +21 -10
  2. data/lib/chef/knife/vagrant_test.rb +14 -5
  3. metadata +1 -1
data/README.md CHANGED
@@ -24,24 +24,35 @@ Usage
24
24
  knife vagrant test (options)
25
25
 
26
26
  -b, --box BOX Name of vagrant box to be provisioned
27
-
28
27
  -U, --box-url URL URL of pre-packaged vbox template. Can be a local path or an HTTP URL. Defaults to ./package.box
29
-
30
28
  -l, --chef-loglevel LEVEL Logging level for the chef-client process that runs inside the provisioned VM. Default is INFO
31
-
29
+ -s, --server-url URL Chef Server URL
30
+ -k, --key KEY API Client Key
31
+ --[no-]color Use colored output, defaults to enabled
32
+ -c, --config CONFIG The configuration file to use
33
+ --defaults Accept default values for all questions
32
34
  -x, --destroy Destroy vagrant box and delete chef node/client when finished
33
-
35
+ -d, --disable-editing Do not open EDITOR, just accept the data as is
36
+ -e, --editor EDITOR Set the editor to use for interactive commands
34
37
  -E, --environment ENVIRONMENT Set the Chef environment
35
-
38
+ -F, --format FORMAT Which format to use for output
36
39
  -H, --hostname HOSTNAME Hostname to be set as hostname on vagrant box when provisioned
37
-
38
40
  -m, --memsize MEMORY Amount of RAM to allocate to provisioned VM, in MB. Defaults to 1024
39
-
40
- -D, --vagrant-dir PATH Path to vagrant project directory. Defaults to cwd (/home/mgarrett/knife-vagrant) if not specified
41
-
41
+ -u, --user USER API Client Username
42
+ -p, --port-forward PORTS Port forwarding. Host port, VM port separated by a colon. E.G. to forward 80 on the
43
+ host machine to 8080 on the VM, -p 80:8080.
44
+ To list multiple forwards separate with a comma, e.g. "-p 80:8080,22:2222"
45
+ --print-after Show the data after a destructive operation
46
+ -D, --vagrant-dir PATH Path to vagrant project directory. Defaults to cwd (/Users/mgarrett/vagrant) if not specified
42
47
  -r, --vagrant-run-list RUN_LIST Comma separated list of roles/recipes to apply
43
-
48
+ -V, --verbose More verbose output. Use twice for max verbosity
49
+ -v, --version Show chef version
44
50
  -y, --yes Say yes to all prompts for confirmation
51
+ -h, --help Show this message
52
+
53
+ #### Example
54
+
55
+ knife vagrant test -b base -H vagrant-mgarrett01 -r role[vagrant] -m 2048 -p 22:2222,8080:8080 -b box64 -U http://files.vagrantup.com/lucid64.box -xy
45
56
 
46
57
  Disclaimer
47
58
  -------------------
@@ -14,14 +14,19 @@ module KnifePlugins
14
14
  require 'chef/node'
15
15
  require 'chef/api_client'
16
16
  end
17
+
18
+ option :port_forward,
19
+ :short => '-p PORTS',
20
+ :long => '--port-forward PORTS',
21
+ :description => "Port forwarding. Host port, VM port separated by a colon. E.G. to forward 80 on the host machine to 8080 on the VM, -p 80:8080. To list multiple forwards separate with a comma, e.g. \"-p 80:8080,22:2222\"",
22
+ :proc => lambda { |o| Hash[o.split(/,/).collect { |a| a.split(/:/) }] },
23
+ :default => {}
17
24
 
18
- # Default is nil here because if :cwd passed to the Vagrant::Environment object is nil,
19
- # it defaults to Dir.pwd, which is the cwd of the running process.
20
25
  option :vagrant_dir,
21
26
  :short => '-D PATH',
22
27
  :long => '--vagrant-dir PATH',
23
28
  :description => "Path to vagrant project directory. Defaults to cwd (#{Dir.pwd}) if not specified",
24
- :default => nil
29
+ :default => Dir.pwd
25
30
 
26
31
  option :vagrant_run_list,
27
32
  :short => "-r RUN_LIST",
@@ -71,11 +76,15 @@ module KnifePlugins
71
76
  runlist.collect { |i| "\"#{i}\"" }.join(",\n")
72
77
  end
73
78
 
79
+ def build_port_forwards(ports)
80
+ ports.collect { |k, v| "config.vm.forward_port(#{k}, #{v})" }.join("\n")
81
+ end
82
+
74
83
  # 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.
75
84
  def build_vagrantfile
76
85
  file = <<-EOF
77
86
  Vagrant::Config.run do |config|
78
- config.vm.forward_port(22, 2222)
87
+ #{build_port_forwards(config[:port_forward])}
79
88
  config.vm.box = "#{config[:box]}"
80
89
  config.vm.host_name = "#{config[:hostname]}"
81
90
  config.vm.customize [ "modifyvm", :id, "--memory", #{config[:memsize]} ]
@@ -120,9 +129,9 @@ module KnifePlugins
120
129
  ensure
121
130
  if config[:destroy]
122
131
  ui.confirm("Destroy vagrant box #{config[:box]} and delete chef node and client")
123
- config[:yes] = true
124
132
  args = %w[ destroy --force ]
125
133
  @vagrant_env.cli(args)
134
+ config[:yes]
126
135
  delete_object(Chef::Node, config[:hostname])
127
136
  delete_object(Chef::ApiClient, config[:hostname])
128
137
  end
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: