mofa 0.2.13 → 0.2.14

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.
data/lib/mofa/cli.rb CHANGED
@@ -17,6 +17,7 @@ module Mofa
17
17
 
18
18
  desc 'provision <cookbook>', 'provisions Targethost(s) using a given cookbook.'
19
19
  method_option :target, :type => :string, :aliases => '-t'
20
+ method_option :concrete_target, :type => :string, :aliases => '-T'
20
21
  method_option :runlist, :type => :string, :aliases => '-o'
21
22
  method_option :service_hostlist_url, :type => :string
22
23
 
@@ -26,11 +27,11 @@ module Mofa
26
27
  cookbook_name_or_path ||= '.'
27
28
 
28
29
  target_filter = options[:target]
29
- target_filter ||= Mofa::Config.config['profiles']['default']['target']
30
+ #target_filter ||= Mofa::Config.config['profiles']['default']['target']
30
31
 
31
32
  token = MofaCmd.generate_token
32
33
 
33
- hostlist = Hostlist.create(target_filter, options[:service_hostlist_url])
34
+ hostlist = Hostlist.create(target_filter, options[:service_hostlist_url], options[:concrete_target])
34
35
  cookbook = Cookbook.create(cookbook_name_or_path, token)
35
36
  runlist_map = RunlistMap.create(cookbook, hostlist, token, options[:runlist])
36
37
  attributes_map = AttributesMap.create(cookbook, hostlist, token, options[:runlist], options[:attributes])
data/lib/mofa/hostlist.rb CHANGED
@@ -7,17 +7,18 @@ class Hostlist
7
7
  attr_accessor :filter
8
8
  attr_accessor :service_host
9
9
  attr_accessor :service_url
10
- attr_accessor :filter
11
10
  attr_accessor :api_key
11
+ attr_accessor :concrete_target
12
12
 
13
- def self.create(filter = nil, service_hostlist_url = nil)
13
+ def self.create(filter = nil, service_hostlist_url = nil, concrete_target = nil)
14
14
  hl = Hostlist.new
15
- filter ||= Mofa::Config.config['service_hostlist_default_filter']
15
+ filter = Mofa::Config.config['service_hostlist_default_filter'] if concrete_target.nil? && filter.nil?
16
16
  service_hostlist_url ||= Mofa::Config.config['service_hostlist_url']
17
17
  hl.filter = filter
18
18
  hl.service_host = Mofa::Config.config['service_hostlist_url'].gsub(/^http:\/\//, '').gsub(/\/.*$/, '').gsub(/:.*$/, '')
19
19
  hl.service_url = service_hostlist_url
20
20
  hl.api_key = Mofa::Config.config['service_hostlist_api_key']
21
+ hl.concrete_target = concrete_target
21
22
  hl
22
23
  end
23
24
 
@@ -29,8 +30,14 @@ class Hostlist
29
30
  Hostlist::get_shortname(hostname).gsub(/\d+$/, '')
30
31
  end
31
32
 
33
+ def has_concrete_target
34
+ return (@concrete_target.nil?) ? false : true
35
+ end
36
+
32
37
  def retrieve
33
38
  case
39
+ when has_concrete_target
40
+ @list = [@concrete_target]
34
41
  when @service_url.match(/^http/)
35
42
  fail "Hostlist Service not reachable! (cannot ping #{service_host})" unless up?
36
43
  response = RestClient.get(@service_url, {:params => {:key => api_key}})
@@ -59,16 +66,17 @@ class Hostlist
59
66
  end
60
67
 
61
68
  def apply_filter
62
-
63
- if @filter[0] == '/' && @filter[-1] == '/' && @filter.length > 2
64
- regex = @filter[1..-2]
65
- else
66
- # building matcher
67
- regex = @filter.gsub(/\*/, '__ASTERISK__')
68
- regex = Regexp.escape(regex).gsub(/__ASTERISK__/, '.*')
69
- regex = '^' + regex + '$'
69
+ unless @filter.nil?
70
+ if @filter[0] == '/' && @filter[-1] == '/' && @filter.length > 2
71
+ regex = @filter[1..-2]
72
+ else
73
+ # building matcher
74
+ regex = @filter.gsub(/\*/, '__ASTERISK__')
75
+ regex = Regexp.escape(regex).gsub(/__ASTERISK__/, '.*')
76
+ regex = '^' + regex + '$'
77
+ end
78
+ @list.select! { |hostname| hostname.match(regex) }
70
79
  end
71
- @list.select! { |hostname| hostname.match(regex) }
72
80
  end
73
81
 
74
82
  def sort_by_domainname
data/lib/mofa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mofa
2
- VERSION = "0.2.13"
2
+ VERSION = "0.2.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: