Class: TrainPlugins::Juniper::JuniperFile

Inherits:
Object
  • Object
show all
Defined in:
lib/train-juniper/file_abstraction/juniper_file.rb

Overview

File abstraction for Juniper configuration and operational data

Instance Method Summary collapse

Constructor Details

#initialize(connection, path) ⇒ JuniperFile

Initialize a new JuniperFile

Parameters:

  • connection (Connection)

    The Juniper connection instance

  • path (String)

    The virtual file path



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

#contentString

Get the content of the virtual file

Examples:

file = connection.file('/config/interfaces')
file.content  # Returns output of 'show configuration interfaces'

Returns:

  • (String)

    The command output based on the path



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

Raises:

  • (NotImplementedError)

    always raises as download is not supported



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)

Returns:

  • (Boolean)

    true if the file has content, false otherwise



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_sString

Return string representation of file path

Returns:

  • (String)

    the 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

Raises:

  • (NotImplementedError)

    always raises as upload is not supported



58
59
60
# File 'lib/train-juniper/file_abstraction/juniper_file.rb', line 58

def upload(_content)
  raise NotImplementedError, Constants::UPLOAD_NOT_SUPPORTED
end