File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#
22# Author:: Adam Jacob (<adam@opscode.com>)
3- # Copyright:: Copyright (c) 2009 Opscode, Inc.
3+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
44# License:: Apache License, Version 2.0
55#
66# Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,8 +32,19 @@ class NodeList < Knife
3232 :description => "Show corresponding URIs"
3333
3434 def run
35- output ( format_list_for_display ( Chef :: Node . list ) )
35+ output ( format_list_for_display ( retrieve_node_list ) )
3636 end
37+
38+ def retrieve_node_list
39+ if config [ :environment ]
40+ response = Hash . new
41+ Chef ::Search ::Query . new . search ( :node , "chef_environment:#{ config [ :environment ] } " ) { |n | response [ n . name ] = "#{ Chef ::Config [ :chef_server_url ] } /nodes/#{ n . name } " unless n . nil? }
42+ response
43+ else
44+ Chef ::Node . list
45+ end
46+ end
47+
3748 end
3849 end
3950end
Original file line number Diff line number Diff line change 2727 "foo" => "http://example.com/foo" ,
2828 "bar" => "http://example.com/foo"
2929 }
30+ Chef ::REST . stub! ( :new ) . and_return ( "foo" )
31+ @chef_search_query = Chef ::Search ::Query . new
3032 Chef ::Node . stub! ( :list ) . and_return ( @list )
33+ Chef ::Search ::Query . stub! ( :new ) . and_return ( @chef_search_query )
3134 end
3235
3336 describe "run" do
34- it "should list the nodes" do
37+ it "should list all of the nodes if -E is not specified " do
3538 Chef ::Node . should_receive ( :list ) . and_return ( @list )
3639 @knife . run
3740 end
4245 @knife . run
4346 end
4447
48+ it "should list nodes in the specific environment if -E ENVIRONMENT is specified" do
49+ @knife . config = { :environment => "prod" }
50+ Chef ::Search ::Query . should_receive ( :new ) . and_return ( @chef_search_query )
51+ @chef_search_query . should_receive ( :search ) . with ( :node , "chef_environment:prod" ) . and_return ( [ "foo" , "bar" ] )
52+ @knife . run
53+ end
54+
4555 describe "with -w or --with-uri" do
4656 it "should pretty print the hash" do
4757 @knife . config [ :with_uri ] = true
You can’t perform that action at this time.
0 commit comments