itamae 1.0.0.beta29 → 1.0.0.beta30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e6c40f7ec418f602cc9c3656ab52e2911ef569a
4
- data.tar.gz: ae5a65e894d475f4001ba6e81ceee410eee7a2a2
3
+ metadata.gz: a8f874dbe2bbea23c2b737a85b36c81a215f2ff2
4
+ data.tar.gz: 236c5f921b47fde0c43d55d8e5c2050cfad3c71d
5
5
  SHA512:
6
- metadata.gz: 8bb64b1eeb4a24e68384acb26cbac4f3bf71f152b7df88c9daeb13a271db796b9162d945d31871ea500cd5309db4ba627f2346dedaf709b9147fb8f08cf6fb4b
7
- data.tar.gz: c806857b5bc48e363d19320926e21db59833b38da307a9db0615591edf2c232495d13a030bbd3a22f81601e0ac3ead9b09a9bb7be938768701250a01de3ef968
6
+ metadata.gz: a37f3e87c9441cb271b64b6840ed2938fe0ee3bde462f3eec5395514619017743912bf6e257f54493a1a09442316a032b3eec264e4ed6c0ba035424f734b1884
7
+ data.tar.gz: 97972599e06ad215501ac16f90f9f52fff8e6427766ad24861bf911bdbb9c1c65c0dfa15992504fb44c6796bf1a1fe43fcd360317f079dc8f520323dd0d9d96d
data/itamae.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_runtime_dependency "thor"
21
- spec.add_runtime_dependency "specinfra", "2.0.0.beta39"
21
+ spec.add_runtime_dependency "specinfra", "2.0.0.beta41"
22
22
  spec.add_runtime_dependency "hashie"
23
23
  spec.add_runtime_dependency "ansi"
24
24
 
data/lib/itamae.rb CHANGED
@@ -8,6 +8,7 @@ require "itamae/logger"
8
8
  require "itamae/node"
9
9
  require "itamae/backend"
10
10
  require "itamae/notification"
11
+ require "itamae/definition"
11
12
 
12
13
  module Itamae
13
14
  # Your code goes here...
data/lib/itamae/cli.rb CHANGED
@@ -18,6 +18,10 @@ module Itamae
18
18
  option :dry_run, type: :boolean, aliases: ['-n']
19
19
  option :ohai, type: :boolean, default: false
20
20
  def local(*recipe_files)
21
+ if recipe_files.empty?
22
+ raise "Please specify recipe files."
23
+ end
24
+
21
25
  Runner.run(recipe_files, :local, options)
22
26
  end
23
27
 
@@ -30,6 +34,10 @@ module Itamae
30
34
  option :port, type: :numeric, aliases: ['-p']
31
35
  option :ohai, type: :boolean, default: false
32
36
  def ssh(*recipe_files)
37
+ if recipe_files.empty?
38
+ raise "Please specify recipe files."
39
+ end
40
+
33
41
  Runner.run(recipe_files, :ssh, options)
34
42
  end
35
43
 
@@ -0,0 +1,63 @@
1
+ require 'itamae'
2
+
3
+ module Itamae
4
+ class Definition < Resource::Base
5
+ class << self
6
+ def create_class(name, params, &block)
7
+ Class.new(self).tap do |klass|
8
+ klass.definition_block = block
9
+
10
+ klass.define_attribute :action, default: :run
11
+ params.each_pair do |key, value|
12
+ klass.define_attribute key.to_sym, type: Object, default: value
13
+ end
14
+ end
15
+ end
16
+
17
+ def definition_block=(block)
18
+ @definition_block = block
19
+ end
20
+
21
+ def definition_block
22
+ @definition_block
23
+ end
24
+ end
25
+
26
+ def initialize(*args)
27
+ super
28
+
29
+ construct_resources
30
+ end
31
+
32
+ def run_action(options)
33
+ @children.run(options)
34
+ end
35
+
36
+ private
37
+
38
+ def construct_resources
39
+ block = self.class.definition_block
40
+
41
+ context = Context.new(@attributes.merge(name: resource_name))
42
+ context.instance_exec(&block)
43
+ @children = context.children
44
+ end
45
+
46
+ class Context
47
+ attr_reader :params
48
+ attr_reader :children
49
+
50
+ def initialize(params, &block)
51
+ @params = params
52
+ @children = RecipeChildren.new
53
+ end
54
+
55
+ def method_missing(method, name, &block)
56
+ klass = Resource.get_resource_class(method)
57
+ resource = klass.new(self, name, &block)
58
+ @children << resource
59
+ end
60
+ end
61
+ end
62
+ end
63
+
data/lib/itamae/recipe.rb CHANGED
@@ -46,14 +46,16 @@ module Itamae
46
46
  klass = Resource.get_resource_class(method)
47
47
  resource = klass.new(self, name, &block)
48
48
  @children << resource
49
- rescue NameError
50
- super
51
49
  end
52
50
 
53
- def include_recipe(target)
54
- target = ::File.expand_path(target, File.dirname(@path))
51
+ def include_recipe(recipe)
52
+ candidate_paths = [
53
+ ::File.expand_path(recipe, File.dirname(@path)),
54
+ find_recipe_from_load_path(recipe),
55
+ ].compact
56
+ target = candidate_paths.find {|path| File.exist?(path) }
55
57
 
56
- unless File.exist?(target)
58
+ unless target
57
59
  raise NotFoundError, "File not found. (#{target})"
58
60
  end
59
61
 
@@ -65,6 +67,24 @@ module Itamae
65
67
  recipe = Recipe.new(@runner, target)
66
68
  @children << recipe
67
69
  end
70
+
71
+ def find_recipe_from_load_path(recipe)
72
+ target = recipe.gsub(/::/, '/')
73
+ target += '.rb' if target !~ /\.rb$/
74
+ plugin_name = recipe.split('::')[0]
75
+
76
+ $LOAD_PATH.find do |path|
77
+ if path =~ %r{/itamae-plugin-recipe-#{plugin_name}/}
78
+ File.join(path, 'itamae', 'plugin', 'recipe', target)
79
+ end
80
+ end
81
+ end
82
+
83
+ def define(name, params = {}, &block)
84
+ Resource.const_set(
85
+ Resource.get_resource_class_name(name),
86
+ Definition.create_class(name, params, &block)
87
+ )
88
+ end
68
89
  end
69
90
  end
70
-
@@ -65,7 +65,7 @@ module Itamae
65
65
 
66
66
  unless options[:dry_run]
67
67
  [action].flatten.each do |action|
68
- public_send("#{specific_action || action}_action".to_sym)
68
+ public_send("#{specific_action || action}_action".to_sym, options)
69
69
  end
70
70
  end
71
71
 
@@ -80,7 +80,7 @@ module Itamae
80
80
  exit 2
81
81
  end
82
82
 
83
- def nothing_action
83
+ def nothing_action(options)
84
84
  # do nothing
85
85
  end
86
86
 
@@ -28,7 +28,7 @@ module Itamae
28
28
  end
29
29
  end
30
30
 
31
- def create_action
31
+ def create_action(options)
32
32
  if !run_specinfra(:check_file_is_directory, path)
33
33
  run_specinfra(:create_file_as_directory, path)
34
34
  end
@@ -6,7 +6,7 @@ module Itamae
6
6
  define_attribute :action, default: :run
7
7
  define_attribute :command, type: String, default_name: true
8
8
 
9
- def run_action
9
+ def run_action(options)
10
10
  run_command(command)
11
11
  updated!
12
12
  end
@@ -61,7 +61,7 @@ module Itamae
61
61
  end
62
62
  end
63
63
 
64
- def create_action
64
+ def create_action(options)
65
65
  if mode
66
66
  run_specinfra(:change_file_mode, @temppath, mode)
67
67
  end
@@ -76,7 +76,7 @@ module Itamae
76
76
  run_specinfra(:move_file, @temppath, path)
77
77
  end
78
78
 
79
- def delete_action
79
+ def delete_action(options)
80
80
  if run_specinfra(:check_file_is_file, path)
81
81
  # TODO: delegate to Specinfra
82
82
  run_command(["rm", path])
@@ -22,7 +22,7 @@ module Itamae
22
22
  @current_attributes[:exist?] = exist
23
23
  end
24
24
 
25
- def sync_action
25
+ def sync_action(options)
26
26
  ensure_git_available
27
27
 
28
28
  new_repository = false
@@ -22,7 +22,7 @@ module Itamae
22
22
  end
23
23
  end
24
24
 
25
- def create_action
25
+ def create_action(options)
26
26
  unless run_specinfra(:check_file_is_linked_to, link, to)
27
27
  run_specinfra(:link_file_to, link, to)
28
28
  end
@@ -6,7 +6,7 @@ module Itamae
6
6
  define_attribute :action, default: :run
7
7
  define_attribute :block, type: Proc
8
8
 
9
- def run_action
9
+ def run_action(options)
10
10
  block.call
11
11
  end
12
12
  end
@@ -7,7 +7,7 @@ module Itamae
7
7
  define_attribute :mail_alias, type: String, default_name: true
8
8
  define_attribute :recipient, type: String, required: true
9
9
 
10
- def create_action
10
+ def create_action(options)
11
11
  if !run_specinfra(:check_mail_alias_is_aliased_to, mail_alias, recipient)
12
12
  run_specinfra(:add_mail_alias, mail_alias, recipient)
13
13
  end
@@ -21,18 +21,10 @@ module Itamae
21
21
  end
22
22
  end
23
23
 
24
- def install_action
24
+ def install_action(action_options)
25
25
  unless run_specinfra(:check_package_is_installed, name, version)
26
- if %w!ubuntu debian!.include?(backend.os[:family])
27
- # TODO: delegate to Specinfra
28
- package_name = name
29
- package_name += "=#{version}" if version
30
- run_command("DEBIAN_FRONTEND='noninteractive' apt-get -y #{options} install #{shell_escape(package_name)}")
31
- updated!
32
- else
33
- run_specinfra(:install_package, name, version)
34
- updated!
35
- end
26
+ run_specinfra(:install_package, name, version, options)
27
+ updated!
36
28
  end
37
29
  end
38
30
  end
@@ -24,27 +24,27 @@ module Itamae
24
24
  end
25
25
  end
26
26
 
27
- def start_action
27
+ def start_action(options)
28
28
  run_specinfra(:start_service, name)
29
29
  end
30
30
 
31
- def stop_action
31
+ def stop_action(options)
32
32
  run_specinfra(:stop_service, name)
33
33
  end
34
34
 
35
- def restart_action
35
+ def restart_action(options)
36
36
  run_specinfra(:restart_service, name)
37
37
  end
38
38
 
39
- def reload_action
39
+ def reload_action(options)
40
40
  run_specinfra(:reload_service, name)
41
41
  end
42
42
 
43
- def enable_action
43
+ def enable_action(options)
44
44
  run_specinfra(:enable_service, name)
45
45
  end
46
46
 
47
- def disable_action
47
+ def disable_action(options)
48
48
  run_specinfra(:disable_service, name)
49
49
  end
50
50
  end
@@ -23,7 +23,7 @@ module Itamae
23
23
  end
24
24
  end
25
25
 
26
- def create_action
26
+ def create_action(options)
27
27
  if run_specinfra(:check_user_exists, username)
28
28
  if uid && uid.to_s != @current_attributes[:uid]
29
29
  # TODO: delegate to Specinfra
@@ -1 +1 @@
1
- 1.0.0.beta29
1
+ 1.0.0.beta30
@@ -170,3 +170,13 @@ file "/tmp/should_not_exist" do
170
170
  action :delete
171
171
  end
172
172
 
173
+ #####
174
+
175
+ define :definition_example, key: 'default' do
176
+ execute "echo 'name:#{params[:name]},key:#{params[:key]}' > /tmp/created_by_definition"
177
+ end
178
+
179
+ definition_example "name" do
180
+ key 'value'
181
+ end
182
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta29
4
+ version: 1.0.0.beta30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0.beta39
33
+ version: 2.0.0.beta41
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0.beta39
40
+ version: 2.0.0.beta41
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +156,7 @@ files:
156
156
  - lib/itamae.rb
157
157
  - lib/itamae/backend.rb
158
158
  - lib/itamae/cli.rb
159
+ - lib/itamae/definition.rb
159
160
  - lib/itamae/logger.rb
160
161
  - lib/itamae/node.rb
161
162
  - lib/itamae/notification.rb