chef-fork 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff9a6a1e5886c238b2375110fc72f34624bded15
4
- data.tar.gz: 34d6aaf1a3c65f92da6ec7190688d1abe7209c7f
3
+ metadata.gz: 389fc33ea14f3940f41e337f0a43bb2acb33f524
4
+ data.tar.gz: 94fe767539b6be91ae9dacc76b2f92ec93a04771
5
5
  SHA512:
6
- metadata.gz: e42f96c88b4d3d13fda2e55d96f79791b18116cdfd2cd70bc35095e0f126a794c9abf53d4ffdc242899465d9adbb09fd75fbe9ee2b45931e954310b627a3ca08
7
- data.tar.gz: 12dc3fee80a97cbf77e6c09c5d084976cc0119e4fe7fc7e1ad511f5c24ff563193a3b55b189099ef6ea5b9c32b544b2e540c6713671b223de54d9ef25d02f600
6
+ metadata.gz: 3d0a2d1eba11e63465a0b7e9b7dc926c7d6c148dbe392ca82a4acb1c4a6c9d752ff3204c479b40ccb1bfaa20db0812ec81ffabe74daaed3c436d57b381bd1745
7
+ data.tar.gz: 8153a3af4141e0b145548a628afc61ab60a9321682a6b05a173fb64f19025c55bd3a8cef8381b3a79534c5ae3db4e6c52e81447ec70a591a804eec92017021fd
data/knife-and-fork.md ADDED
@@ -0,0 +1,41 @@
1
+ # knife and fork
2
+
3
+ ## Environment
4
+
5
+ ```sh
6
+ $ knife environment from file environments/foo.rb
7
+ ```
8
+
9
+ ```sh
10
+ $ fork environment upload foo
11
+ ```
12
+
13
+ ## Role
14
+
15
+ ```sh
16
+ $ knife role from file roles/foo.rb
17
+ ```
18
+
19
+ ```sh
20
+ $ fork role upload foo
21
+ ```
22
+
23
+ ## DataBag
24
+
25
+ ```sh
26
+ $ knife data bag from file foo data_bags/foo/bar.json
27
+ ```
28
+
29
+ ```sh
30
+ $ fork databag upload foo bar
31
+ ```
32
+
33
+ ## Cookbook
34
+
35
+ ```sh
36
+ $ knife cookbook upload foo
37
+ ```
38
+
39
+ ```sh
40
+ $ fork cookbook upload foo
41
+ ```
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require "chef/rest"
5
+
4
6
  class Chef
5
7
  class Fork
6
8
  module Commands
@@ -27,6 +29,10 @@ class Chef
27
29
  def optparse()
28
30
  @application.optparse
29
31
  end
32
+
33
+ def rest()
34
+ @rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
35
+ end
30
36
  end
31
37
  end
32
38
  end
@@ -2,6 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  require "chef/fork/commands"
5
+ require "json"
5
6
 
6
7
  class Chef
7
8
  class Fork
@@ -10,6 +11,10 @@ class Chef
10
11
  def run(args=[])
11
12
  rest = optparse.order(args)
12
13
  case rest.first
14
+ when "edit"
15
+ cookbook_edit(rest.slice(1..-1) || [])
16
+ when "list"
17
+ cookbook_list(rest.slice(1..-1) || [])
13
18
  when "show"
14
19
  cookbook_show(rest.slice(1..-1) || [])
15
20
  when "upload"
@@ -20,11 +25,35 @@ class Chef
20
25
  end
21
26
 
22
27
  private
23
- def cookbook_show(args=[])
28
+ def cookbook_edit(args=[])
24
29
  raise(NotImplementedError.new(args.inspect))
25
30
  end
26
31
 
32
+ def cookbook_list(args=[])
33
+ raise(NotImplementedError.new(args.inspect))
34
+ end
35
+
36
+ def cookbook_show(args=[])
37
+ if cookbook_name = args.shift
38
+ if args.empty?
39
+ cookbook_version = "_latest"
40
+ STDOUT.puts(JSON.pretty_generate(rest.get_rest("cookbooks/#{cookbook_name}/#{cookbook_version}").to_hash()))
41
+ else
42
+ args.each do |cookbook_version|
43
+ STDOUT.puts(JSON.pretty_generate(rest.get_rest("cookbooks/#{cookbook_name}/#{cookbook_version}").to_hash()))
44
+ end
45
+ end
46
+ end
47
+ end
48
+
27
49
  def cookbook_upload(args=[])
50
+ cookbook_paths = [ Chef::Config[:cookbook_path] ].flatten
51
+ args.each do |cookbook_name|
52
+ candidates = cookbook_paths.map { |path| File.join(path, cookbook_name) }
53
+ if file = candidates.select { |candidate| File.exist?(candidate) }.first
54
+ p([cookbook_name, file])
55
+ end
56
+ end
28
57
  raise(NotImplementedError.new(args.inspect))
29
58
  end
30
59
  end
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require "chef/data_bag"
5
+ require "chef/data_bag_item"
4
6
  require "chef/fork/commands"
7
+ require "json"
5
8
 
6
9
  class Chef
7
10
  class Fork
@@ -20,15 +23,25 @@ class Chef
20
23
  private
21
24
  def data_bag(args=[])
22
25
  case args.first
26
+ when "edit"
27
+ data_bag_edit(args.slice(1..-1) || [])
23
28
  when "from"
24
29
  data_bag_from(args.slice(1..-1) || [])
30
+ when "list"
31
+ data_bag_list(args.slice(1..-1) || [])
25
32
  when "show"
26
33
  data_bag_show(args.slice(1..-1) || [])
34
+ when "upload"
35
+ data_bag_upload(args.slice(1..-1) || [])
27
36
  else
28
37
  raise(NameError.new(args.inspect))
29
38
  end
30
39
  end
31
40
 
41
+ def data_bag_edit(args=[])
42
+ raise(NotImplementedError.new(args.inspect))
43
+ end
44
+
32
45
  def data_bag_from(args=[])
33
46
  case args.first
34
47
  when "file"
@@ -39,10 +52,38 @@ class Chef
39
52
  end
40
53
 
41
54
  def data_bag_from_file(args=[])
55
+ data_bag_uploda(args)
56
+ end
57
+
58
+ def data_bag_list(args=[])
42
59
  raise(NotImplementedError.new(args.inspect))
43
60
  end
44
61
 
45
62
  def data_bag_show(args=[])
63
+ if data_bag_name = args.shift
64
+ if args.empty?
65
+ data_bag = Chef::DataBag.load(data_bag_name)
66
+ STDOUT.puts(JSON.pretty_generate(data_bag.to_hash()))
67
+ else
68
+ args.each do |data_bag_item_name|
69
+ data_bag_item = Chef::DataBagItem.load(data_bag_name, data_bag_item_name)
70
+ STDOUT.puts(JSON.pretty_generate(data_bag_item.to_hash()))
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def data_bag_upload(args=[])
77
+ data_bag_paths = [ Chef::Config[:data_bag_path] ].flatten
78
+ if data_bag_name = args.shift
79
+ args.each do |data_bag_item_name|
80
+ candidates = data_bag_paths.map { |path| File.join(path, data_bag_name, "#{data_bag_item_name}.json") }
81
+ if file = candidates.select { |candidate| File.exist?(candidate) }.first
82
+ data_bag_item = Chef::DataBagItem.from_hash(JSON.load(File.read(file)))
83
+ p(data_bag_item) # TODO: do upload
84
+ end
85
+ end
86
+ end
46
87
  raise(NotImplementedError.new(args.inspect))
47
88
  end
48
89
  end
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require "chef/environment"
4
5
  require "chef/fork/commands"
6
+ require "json"
5
7
 
6
8
  class Chef
7
9
  class Fork
@@ -10,16 +12,26 @@ class Chef
10
12
  def run(args=[])
11
13
  rest = optparse.order(args)
12
14
  case rest.first
15
+ when "edit"
16
+ environment_edit(rest.slice(1..-1) || [])
13
17
  when "from"
14
18
  environment_from(rest.slice(1..-1) || [])
19
+ when "list"
20
+ environment_list(rest.slice(1..-1) || [])
15
21
  when "show"
16
22
  environment_show(rest.slice(1..-1) || [])
23
+ when "upload"
24
+ environment_upload(rest.slice(1..-1) || [])
17
25
  else
18
26
  raise(NameError.new(rest.inspect))
19
27
  end
20
28
  end
21
29
 
22
30
  private
31
+ def environment_edit(args=[])
32
+ raise(NotImplementedError.new(args.inspect))
33
+ end
34
+
23
35
  def environment_from(args=[])
24
36
  case args.first
25
37
  when "file"
@@ -30,10 +42,29 @@ class Chef
30
42
  end
31
43
 
32
44
  def environment_from_file(args=[])
45
+ environment_upload(args)
46
+ end
47
+
48
+ def environment_list(args=[])
33
49
  raise(NotImplementedError.new(args.inspect))
34
50
  end
35
51
 
36
52
  def environment_show(args=[])
53
+ args.each do |environment_name|
54
+ environment = Chef::Environment.load(environment_name)
55
+ STDOUT.puts(JSON.pretty_generate(environment_to_hash(environment.to_hash())))
56
+ end
57
+ end
58
+
59
+ def environment_upload(args=[])
60
+ environment_paths = [ Chef::Config[:environment_path] ].flatten
61
+ args.each do |environment_name|
62
+ candidates = environment_paths.map { |path| File.join(path, "#{environment_name}.rb") }
63
+ if file = candidates.select { |candidate| File.exist?(candidate) }.first
64
+ environment = Chef::Environment.load_from_file(environment_name)
65
+ p(environment) # TODO: do upload
66
+ end
67
+ end
37
68
  raise(NotImplementedError.new(args.inspect))
38
69
  end
39
70
  end
@@ -1,16 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require "rbconfig"
5
4
  require "chef/fork/commands"
5
+ require "json"
6
+ require "rbconfig"
6
7
 
7
8
  class Chef
8
9
  class Fork
9
10
  module Commands
10
11
  class Help < Noop
11
12
  def run(args=[])
12
- ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
13
- exit(system(ruby, $0, "--help") ? 0 : 1)
13
+ if command = args.shift
14
+ case command
15
+ when "commands"
16
+ paths = $LOAD_PATH.map { |path|
17
+ File.join(path, "chef", "fork", "commands")
18
+ }
19
+ commands = paths.map { |path|
20
+ Dir.glob(File.join(path, "*.rb")).map { |file| File.basename(file, ".rb") }
21
+ }.flatten
22
+ STDOUT.puts(JSON.pretty_generate(commands.sort.uniq))
23
+ else
24
+ raise(NotImplementedError.new(command.inspect))
25
+ end
26
+ else
27
+ ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
28
+ exec(ruby, $0, "--help")
29
+ exit(127)
30
+ end
14
31
  end
15
32
  end
16
33
  end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "chef/fork/commands"
5
+ require "chef/node"
6
+ require "json"
7
+
8
+ class Chef
9
+ class Fork
10
+ module Commands
11
+ class Node < Noop
12
+ def run(args=[])
13
+ rest = optparse.order(args)
14
+ case rest.first
15
+ when "edit"
16
+ node_edit(rest.slice(1..-1) || [])
17
+ when "list"
18
+ node_list(rest.slice(1..-1) || [])
19
+ when "show"
20
+ node_show(rest.slice(1..-1) || [])
21
+ else
22
+ raise(NameError.new(rest.inspect))
23
+ end
24
+ end
25
+
26
+ private
27
+ def node_edit(args=[])
28
+ raise(NotImplementedError.new(args.inspect))
29
+ end
30
+
31
+ def node_list(args=[])
32
+ raise(NotImplementedError.new(args.inspect))
33
+ end
34
+
35
+ def node_show(args=[])
36
+ args.each do |node_name|
37
+ node = Chef::Node.load(node_name)
38
+ STDOUT.puts(JSON.pretty_generate(node.to_hash()))
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,6 +2,8 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  require "chef/fork/commands"
5
+ require "chef/role"
6
+ require "json"
5
7
 
6
8
  class Chef
7
9
  class Fork
@@ -10,15 +12,26 @@ class Chef
10
12
  def run(args=[])
11
13
  rest = optparse.order(args)
12
14
  case rest.first
15
+ when "edit"
16
+ role_edit(rest.slice(1..-1) || [])
13
17
  when "from"
14
18
  role_from(rest.slice(1..-1) || [])
19
+ when "list"
20
+ role_list(rest.slice(1..-1) || [])
15
21
  when "show"
16
22
  role_show(rest.slice(1..-1) || [])
23
+ when "upload"
24
+ role_upload(rest.slice(1..-1) || [])
17
25
  else
18
26
  raise(NameError.new(rest.inspect))
19
27
  end
20
28
  end
21
29
 
30
+ private
31
+ def role_edit(args=[])
32
+ raise(NotImplementedError.new(args.inspect))
33
+ end
34
+
22
35
  def role_from(args=[])
23
36
  case args.shift
24
37
  when "file"
@@ -29,10 +42,29 @@ class Chef
29
42
  end
30
43
 
31
44
  def role_from_file(args=[])
45
+ role_upload(args)
46
+ end
47
+
48
+ def role_list(args=[])
32
49
  raise(NotImplementedError.new(args.inspect))
33
50
  end
34
51
 
35
52
  def role_show(args=[])
53
+ args.each do |role_name|
54
+ role = Chef::Role.load(role_name)
55
+ STDOUT.puts(JSON.pretty_generate(role_to_hash(role.to_hash())))
56
+ end
57
+ end
58
+
59
+ def role_upload(args=[])
60
+ role_paths = [ Chef::Config[:role_path] ].flatten
61
+ args.each do |role_name|
62
+ candidates = role_paths.map { |path| File.join(path, "#{role_name}.rb") }
63
+ if file = candidates.select { |candidate| File.exist?(candidate) }.first
64
+ role = Chef::Role.from_disk(role_name)
65
+ p(role) # TODO: do upload
66
+ end
67
+ end
36
68
  raise(NotImplementedError.new(args.inspect))
37
69
  end
38
70
  end
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  class Fork
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-fork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - bin/fork
83
83
  - chef-fork.gemspec
84
+ - knife-and-fork.md
84
85
  - lib/chef/fork.rb
85
86
  - lib/chef/fork/application.rb
86
87
  - lib/chef/fork/commands.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/chef/fork/commands/databag.rb
91
92
  - lib/chef/fork/commands/environment.rb
92
93
  - lib/chef/fork/commands/help.rb
94
+ - lib/chef/fork/commands/node.rb
93
95
  - lib/chef/fork/commands/role.rb
94
96
  - lib/chef/fork/commands/ssh.rb
95
97
  - lib/chef/fork/version.rb