aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-09-30 13:36:26 -0700
committerelijah <elijah@riseup.net>2014-09-30 13:36:26 -0700
commita5b77fa30ed5548978c0907b74ba986cdbf6c11a (patch)
treefad9db58d566fb3cc2b4a605bc941ea580dfb1a9 /lib/leap_cli/commands
parent410b5d793e8b8ee0abd42b581f09d8c7d5721ed3 (diff)
downloadleap_cli-a5b77fa30ed5548978c0907b74ba986cdbf6c11a.tar.gz
leap_cli-a5b77fa30ed5548978c0907b74ba986cdbf6c11a.tar.bz2
environment pinning: new commands `leap env`, `leap env pin X` and `leap env unpin`. See `leap help env` for more information.
Diffstat (limited to 'lib/leap_cli/commands')
-rw-r--r--lib/leap_cli/commands/compile.rb7
-rw-r--r--lib/leap_cli/commands/deploy.rb14
-rw-r--r--lib/leap_cli/commands/env.rb53
-rw-r--r--lib/leap_cli/commands/list.rb9
-rw-r--r--lib/leap_cli/commands/pre.rb7
5 files changed, 64 insertions, 26 deletions
diff --git a/lib/leap_cli/commands/compile.rb b/lib/leap_cli/commands/compile.rb
index eaedfbf..13fa9ac 100644
--- a/lib/leap_cli/commands/compile.rb
+++ b/lib/leap_cli/commands/compile.rb
@@ -9,10 +9,13 @@ module LeapCli
c.command :all do |all|
all.action do |global_options,options,args|
environment = args.first
+ if !LeapCli.leapfile.environment.nil? && environment != LeapCli.leapfile.environment
+ bail! "You cannot specify an ENVIRONMENT argument while the environment is pinned."
+ end
if environment && manager.environment_names.include?(environment)
- compile_hiera_files(manager.filter(args))
+ compile_hiera_files(manager.filter([environment]))
else
- compile_hiera_files
+ compile_hiera_files(manager.filter)
end
end
end
diff --git a/lib/leap_cli/commands/deploy.rb b/lib/leap_cli/commands/deploy.rb
index 553b2b1..bd1f479 100644
--- a/lib/leap_cli/commands/deploy.rb
+++ b/lib/leap_cli/commands/deploy.rb
@@ -36,7 +36,7 @@ module LeapCli
init_submodules
end
- nodes = filter_deploy_nodes(args)
+ nodes = manager.filter!(args)
if nodes.size > 1
say "Deploying to these nodes: #{nodes.keys.join(', ')}"
if !global[:yes] && !agree("Continue? ")
@@ -253,17 +253,5 @@ module LeapCli
tags.join(',')
end
- #
- # for safety, we allow production deploys to be turned off in the Leapfile.
- #
- def filter_deploy_nodes(filter)
- nodes = manager.filter!(filter)
- if !leapfile.allow_production_deploy
- nodes = nodes[:environment => "!production"]
- assert! nodes.any?, "Skipping deploy because @allow_production_deploy is disabled."
- end
- nodes
- end
-
end
end
diff --git a/lib/leap_cli/commands/env.rb b/lib/leap_cli/commands/env.rb
new file mode 100644
index 0000000..d81e82f
--- /dev/null
+++ b/lib/leap_cli/commands/env.rb
@@ -0,0 +1,53 @@
+module LeapCli
+ module Commands
+
+ desc "Manipulate and query environment information."
+ long_desc "The 'environment' node property can be used to isolate sets of nodes into entirely separate environments. "+
+ "A node in one environment will never interact with a node from another environment. "+
+ "Environment pinning works by modifying your ~/.leaprc file and is dependent on the "+
+ "absolute file path of your provider directory (pins don't apply if you move the directory)"
+ command :env do |c|
+ c.desc "List the available environments. The pinned environment, if any, will be marked with '*'."
+ c.command :ls do |ls|
+ ls.action do |global_options, options, args|
+ envs = ["default"] + manager.environment_names.compact.sort
+ envs.each do |env|
+ if env
+ if LeapCli.leapfile.environment == env
+ puts "* #{env}"
+ else
+ puts " #{env}"
+ end
+ end
+ end
+ end
+ end
+
+ c.desc 'Pin the environment to ENVIRONMENT. All subsequent commands will only apply to nodes in this environment.'
+ c.arg_name 'ENVIRONMENT'
+ c.command :pin do |pin|
+ pin.action do |global_options,options,args|
+ environment = args.first
+ if environment == 'default' ||
+ (environment && manager.environment_names.include?(environment))
+ LeapCli.leapfile.set('environment', environment)
+ log 0, :saved, "Leapfile with environment set to #{environment}."
+ end
+ end
+ end
+
+ c.desc "Unpin the environment. All subsequent commands will apply to all nodes."
+ c.command :unpin do |unpin|
+ unpin.action do |global_options, options, args|
+ LeapCli.leapfile.unset('environment')
+ log 0, :saved, "Leapfile, removing environment property."
+ end
+ end
+
+ c.default_command :ls
+ end
+
+ protected
+
+ end
+end \ No newline at end of file
diff --git a/lib/leap_cli/commands/list.rb b/lib/leap_cli/commands/list.rb
index be9163b..b8d7739 100644
--- a/lib/leap_cli/commands/list.rb
+++ b/lib/leap_cli/commands/list.rb
@@ -30,9 +30,10 @@ module LeapCli; module Commands
if args.any?
NodeTable.new(manager.filter(args), colors).run
else
- TagTable.new('SERVICES', manager.services, colors).run
- TagTable.new('TAGS', manager.tags, colors).run
- NodeTable.new(manager.nodes, colors).run
+ environment = LeapCli.leapfile.environment || '_all_'
+ TagTable.new('SERVICES', manager.env(environment).services, colors).run
+ TagTable.new('TAGS', manager.env(environment).tags, colors).run
+ NodeTable.new(manager.filter(), colors).run
end
end
end
@@ -41,7 +42,6 @@ module LeapCli; module Commands
private
def self.print_node_properties(nodes, properties)
- node_list = manager.nodes
properties = properties.split(',')
max_width = nodes.keys.inject(0) {|max,i| [i.size,max].max}
nodes.each_node do |node|
@@ -75,6 +75,7 @@ module LeapCli; module Commands
column "NODES", :width => HighLine::SystemExtensions.terminal_size.first - max_width - 2, :padding => 2
end
tags.each do |tag|
+ next if @tag_list[tag].node_list.empty?
row :color => @colors[1] do
column tag
column @tag_list[tag].node_list.keys.sort.join(', ')
diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb
index 835eada..2e5c34e 100644
--- a/lib/leap_cli/commands/pre.rb
+++ b/lib/leap_cli/commands/pre.rb
@@ -48,13 +48,6 @@ module LeapCli; module Commands
bail! { log :missing, "platform directory '#{Path.platform}'" }
end
- if LeapCli.leapfile.platform_branch && LeapCli::Util.is_git_directory?(Path.platform)
- branch = LeapCli::Util.current_git_branch(Path.platform)
- if branch != LeapCli.leapfile.platform_branch
- bail! "Wrong branch for #{Path.platform}. Was '#{branch}', should be '#{LeapCli.leapfile.platform_branch}'. Edit Leapfile to disable this check."
- end
- end
-
#
# set log file
#