diff options
author | elijah <elijah@riseup.net> | 2014-11-04 15:38:54 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-11-04 15:38:54 -0800 |
commit | c15d6ee970859f1e5775aec51e289b683fa3116c (patch) | |
tree | 48db38d94ef3120f7d159d05f21b864a26f4e8cb | |
parent | 60f8f753a11c4543931281c56cbd568b2b00f278 (diff) | |
download | leap_cli-c15d6ee970859f1e5775aec51e289b683fa3116c.tar.gz leap_cli-c15d6ee970859f1e5775aec51e289b683fa3116c.tar.bz2 |
bugfix - deploy failed when all nodes had default environment
-rw-r--r-- | lib/leap_cli/config/filter.rb | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/lib/leap_cli/config/filter.rb b/lib/leap_cli/config/filter.rb index 123533f..0a7e91c 100644 --- a/lib/leap_cli/config/filter.rb +++ b/lib/leap_cli/config/filter.rb @@ -4,7 +4,22 @@ # # Classes other than Manager should not use this class. # - +# Filter rules: +# +# * A filter consists of a list of tokens +# * A token may be a service name, tag name, environment name, or node name. +# * Each token may be optionally prefixed with a plus sign. +# * Multiple tokens with a plus are treated as an OR condition, +# but treated as an AND condition with the plus sign. +# +# For example +# +# * openvpn +development => all nodes with service 'openvpn' AND environment 'development' +# * openvpn seattle => all nodes with service 'openvpn' OR tag 'seattle'. +# +# There can only be one environment specified. Typically, there are also tags +# for each environment name. These name are treated as environments, not tags. +# module LeapCli module Config class Filter @@ -15,6 +30,10 @@ module LeapCli # :nopin -- disregard environment pinning # :local -- if false, disallow local nodes # + # A nil value in the filters array indicates + # the default environment. This is in order to support + # calls like `manager.filter(environments)` + # def initialize(filters, options, manager) @filters = filters.nil? ? [] : filters.dup @environments = [] @@ -29,22 +48,27 @@ module LeapCli @environments = [LeapCli.leapfile.environment] end @filters.select! do |filter| - filter_text = filter.sub(/^\+/,'') - if is_environment?(filter_text) - if filter_text == LeapCli.leapfile.environment - # silently ignore already pinned environments - elsif (filter =~ /^\+/ || @filters.first == filter) && !@environments.empty? - LeapCli::Util.bail! do - LeapCli::Util.log "Environments are exclusive: no node is in two environments." do - LeapCli::Util.log "Tried to filter on '#{@environments.join('\' AND \'')}' AND '#{filter_text}'" + if filter.nil? + @environments << nil unless @environments.include?(nil) + false + else + filter_text = filter.sub(/^\+/,'') + if is_environment?(filter_text) + if filter_text == LeapCli.leapfile.environment + # silently ignore already pinned environments + elsif (filter =~ /^\+/ || @filters.first == filter) && !@environments.empty? + LeapCli::Util.bail! do + LeapCli::Util.log "Environments are exclusive: no node is in two environments." do + LeapCli::Util.log "Tried to filter on '#{@environments.join('\' AND \'')}' AND '#{filter_text}'" + end end + else + @environments << filter_text end + false else - @environments << filter_text + true end - false - else - true end end |