Class: TrainPlugins::Habitat::Connection
- Inherits:
-
Train::Plugins::Transport::BaseConnection
- Object
- Train::Plugins::Transport::BaseConnection
- TrainPlugins::Habitat::Connection
- Includes:
- Platform
- Defined in:
- lib/train-habitat/connection.rb
Instance Attribute Summary collapse
-
#cli_connection ⇒ Object
readonly
Returns the value of attribute cli_connection.
-
#cli_transport ⇒ Object
readonly
Returns the value of attribute cli_transport.
-
#cli_transport_name ⇒ Object
readonly
Returns the value of attribute cli_transport_name.
-
#transport_options ⇒ Object
readonly
Returns the value of attribute transport_options.
Instance Method Summary collapse
- #api_options_provided? ⇒ Boolean
- #cli_options_provided? ⇒ Boolean
- #hab_path ⇒ Object
- #habitat_api_client ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#run_command_via_connection(*args) ⇒ Object
See #run_command in BaseConnection.
-
#run_hab_cli(command, _exec_options = {}) ⇒ Object
Use this to execute a ‘hab` command.
- #uri ⇒ Object
Methods included from Platform
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
16 17 18 19 20 21 22 23 |
# File 'lib/train-habitat/connection.rb', line 16 def initialize( = {}) = super() initialize_cli_connection! if enable_cache :api_call end |
Instance Attribute Details
#cli_connection ⇒ Object (readonly)
Returns the value of attribute cli_connection.
14 15 16 |
# File 'lib/train-habitat/connection.rb', line 14 def cli_connection @cli_connection end |
#cli_transport ⇒ Object (readonly)
Returns the value of attribute cli_transport.
14 15 16 |
# File 'lib/train-habitat/connection.rb', line 14 def cli_transport @cli_transport end |
#cli_transport_name ⇒ Object (readonly)
Returns the value of attribute cli_transport_name.
14 15 16 |
# File 'lib/train-habitat/connection.rb', line 14 def cli_transport_name @cli_transport_name end |
#transport_options ⇒ Object (readonly)
Returns the value of attribute transport_options.
14 15 16 |
# File 'lib/train-habitat/connection.rb', line 14 def end |
Instance Method Details
#api_options_provided? ⇒ Boolean
29 30 31 |
# File 'lib/train-habitat/connection.rb', line 29 def ("api") end |
#cli_options_provided? ⇒ Boolean
33 34 35 36 37 |
# File 'lib/train-habitat/connection.rb', line 33 def TrainPlugins::Habitat::Transport.cli_transport_prefixes.keys.map(&:to_s).any? do |prefix| (prefix) end end |
#hab_path ⇒ Object
54 55 56 |
# File 'lib/train-habitat/connection.rb', line 54 def hab_path "/bin/hab" end |
#habitat_api_client ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/train-habitat/connection.rb', line 58 def habitat_api_client cached_client(:api_call, :HTTPGateway) do # Send all options beginning with api_ to the HTTPGateway, stripping the prefix = {} .each do |option_name, option_value| next unless option_name.to_s.start_with? "api_" [option_name.to_s.sub(/^api_/, "").to_sym] = option_value end HTTPGateway.new() end end |
#run_command_via_connection(*args) ⇒ Object
See #run_command in BaseConnection.
48 49 50 51 52 |
# File 'lib/train-habitat/connection.rb', line 48 def run_command_via_connection(*args) raise CliNotAvailableError(cli_tranport_names) unless cli_connection.run_command(*args) end |
#run_hab_cli(command, _exec_options = {}) ⇒ Object
Use this to execute a ‘hab` command. Do not include the `hab` executable in the invocation.
40 41 42 43 44 45 |
# File 'lib/train-habitat/connection.rb', line 40 def run_hab_cli(command, = {}) raise CliNotAvailableError(cli_tranport_names) unless # TODO: - leverage exec_options to add things like JSON parsing, ENV setting, etc. cli_connection.run_command(hab_path + " " + command) end |
#uri ⇒ Object
25 26 27 |
# File 'lib/train-habitat/connection.rb', line 25 def uri "habitat://#{@options[:host]}" end |