Module: Shef
- Defined in:
- lib/chef/shef/ext.rb,
lib/chef/shef.rb,
lib/chef/shef/shef_session.rb
Overview
- Author
-
Daniel DeLeo (<[email protected]>)
- Copyright
-
Copyright © 2009 Daniel DeLeo
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: Extensions Classes: ClientSession, Options, ShefSession, SoloSession, StandAloneSession
Constant Summary collapse
- LEADERS =
Hash.new("")
Class Attribute Summary collapse
-
.client_type ⇒ Object
Returns the value of attribute client_type.
-
.options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .configure_irb ⇒ Object
- .fatal!(message, exit_status) ⇒ Object
- .init ⇒ Object
- .irb_conf ⇒ Object
-
.irb_conf=(conf_hash) ⇒ Object
Set the irb_conf object to something other than IRB.conf usful for testing.
- .parse_json ⇒ Object
- .parse_opts ⇒ Object
-
.running? ⇒ Boolean
Shef assumes it’s running whenever it is defined.
- .session ⇒ Object
Class Attribute Details
.client_type ⇒ Object
Returns the value of attribute client_type.
36 37 38 |
# File 'lib/chef/shef.rb', line 36 def client_type @client_type end |
.options ⇒ Object
Returns the value of attribute options.
36 37 38 |
# File 'lib/chef/shef.rb', line 36 def @options end |
Class Method Details
.configure_irb ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chef/shef.rb', line 54 def self.configure_irb irb_conf[:HISTORY_FILE] = "~/.shef_history" irb_conf[:SAVE_HISTORY] = 1000 irb_conf[:IRB_RC] = lambda do |conf| m = conf.main leader = LEADERS[m.class] def m.help shef_help end conf.prompt_c = "chef#{leader} > " conf.return_format = " => %s \n" conf.prompt_i = "chef#{leader} > " conf.prompt_n = "chef#{leader} ?> " conf.prompt_s = "chef#{leader}%l> " end end |
.fatal!(message, exit_status) ⇒ Object
123 124 125 126 |
# File 'lib/chef/shef.rb', line 123 def self.fatal!(, exit_status) Chef::Log.fatal() exit exit_status end |
.init ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chef/shef.rb', line 79 def self.init parse_json configure_irb session # trigger ohai run + session load session.node.consume_attributes(@json_attribs) greeting = begin " #{Etc.getlogin}@#{Shef.session.node.name}" rescue NameError "" end version puts puts "run `help' for help, `exit' or ^D to quit." puts puts "Ohai2u#{greeting}!" end |
.irb_conf ⇒ Object
50 51 52 |
# File 'lib/chef/shef.rb', line 50 def self.irb_conf @irb_conf || IRB.conf end |
.irb_conf=(conf_hash) ⇒ Object
Set the irb_conf object to something other than IRB.conf usful for testing.
46 47 48 |
# File 'lib/chef/shef.rb', line 46 def self.irb_conf=(conf_hash) @irb_conf = conf_hash end |
.parse_json ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/chef/shef.rb', line 101 def self.parse_json if Chef::Config[:json_attribs] begin json_io = open(Chef::Config[:json_attribs]) rescue SocketError => error fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2) rescue Errno::ENOENT => error fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2) rescue Errno::EACCES => error fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2) rescue Exception => error fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.}", 2) end begin @json_attribs = JSON.parse(json_io.read) rescue JSON::ParserError => error fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error., 2) end end end |
.parse_opts ⇒ Object
135 136 137 138 |
# File 'lib/chef/shef.rb', line 135 def self.parse_opts @options = Options.new @options.parse_opts end |
.running? ⇒ Boolean
Shef assumes it’s running whenever it is defined
40 41 42 |
# File 'lib/chef/shef.rb', line 40 def self.running? true end |
.session ⇒ Object
74 75 76 77 |
# File 'lib/chef/shef.rb', line 74 def self.session client_type.instance.reset! unless client_type.instance.node_built? client_type.instance end |