Class: TrainPlugins::Juniper::JuniperFile
- Inherits:
-
Object
- Object
- TrainPlugins::Juniper::JuniperFile
- Defined in:
- lib/train-juniper/file_abstraction/juniper_file.rb
Overview
File abstraction for Juniper configuration and operational data
Instance Method Summary collapse
-
#content ⇒ String
Get the content of the virtual file.
-
#download(_local_path) ⇒ Object
File download not supported for network devices.
-
#exist? ⇒ Boolean
Check if the file exists (has content).
-
#initialize(connection, path) ⇒ JuniperFile
constructor
Initialize a new JuniperFile.
-
#to_s ⇒ String
Return string representation of file path.
-
#upload(_content) ⇒ Object
File upload not supported for network devices.
Constructor Details
#initialize(connection, path) ⇒ JuniperFile
Initialize a new JuniperFile
12 13 14 15 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 12 def initialize(connection, path) @connection = connection @path = path end |
Instance Method Details
#content ⇒ String
Get the content of the virtual file
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 22 def content # For Juniper devices, translate file paths to appropriate commands case @path when Constants::CONFIG_PATH_PATTERN # Configuration sections: /config/interfaces -> show configuration interfaces section = ::Regexp.last_match(1) result = @connection.run_command("show configuration #{section}") result.stdout when Constants::OPERATIONAL_PATH_PATTERN # Operational data: /operational/interfaces -> show interfaces section = ::Regexp.last_match(1) result = @connection.run_command("show #{section}") result.stdout else # Default to treating path as a show command result = @connection.run_command("show #{@path}") result.stdout end end |
#download(_local_path) ⇒ Object
File download not supported for network devices
64 65 66 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 64 def download(_local_path) raise NotImplementedError, Constants::DOWNLOAD_NOT_SUPPORTED end |
#exist? ⇒ Boolean
Check if the file exists (has content)
44 45 46 47 48 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 44 def exist? !content.empty? rescue StandardError false end |
#to_s ⇒ String
Return string representation of file path
52 53 54 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 52 def to_s @path end |
#upload(_content) ⇒ Object
File upload not supported for network devices
58 59 60 |
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 58 def upload(_content) raise NotImplementedError, Constants::UPLOAD_NOT_SUPPORTED end |