Class: Puppet::Util::NetworkDevice::Cisco_ios::Device

Inherits:
Base_ios
  • Object
show all
Defined in:
lib/puppet/util/network_device/cisco_ios/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Device

Returns a new instance of Device.



12
13
14
15
16
17
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 12

def initialize(url, options = {})
  super(url)
  @enable_password = options[:enable_password] || parse_enable(@url.query)
  @initialized = false
  transport.default_prompt = /[#>]\s?\z/n
end

Instance Attribute Details

#enable_passwordObject

Returns the value of attribute enable_password.



10
11
12
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 10

def enable_password
  @enable_password
end

#switchObject

Returns the value of attribute switch.



10
11
12
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 10

def switch
  @switch
end

Instance Method Details

#connect_transportObject



23
24
25
26
27
28
29
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 23

def connect_transport
  transport.connect
  
  transport.command("terminal length 0", :noop => false) do |out|
    enable if out =~ />\s?\z/n
  end
end

#enableObject



41
42
43
44
45
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 41

def enable
  raise "Can't issue \"enable\" to enter privileged, no enable password set" unless enable_password
  transport.command("enable", {:prompt => /^Password:/, :noop => false})
  transport.command(enable_password, :noop => false)
end

#factsObject



68
69
70
71
72
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 68

def facts
  # This is here till we can fork Puppet
  init
  @facts.facts_to_hash
end

#initObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 47

def init
  # TODO: Stop being an Idiot ...
  unless @initialized
    connect_transport
    init_facts
    init_switch
    @initialized = true
  end
  return self
end

#init_factsObject



63
64
65
66
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 63

def init_facts
  @facts ||= Puppet::Util::NetworkDevice::Cisco_ios::Facts.new(transport)
  @facts.retrieve
end

#init_switchObject



58
59
60
61
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 58

def init_switch
  @switch ||= Puppet::Util::NetworkDevice::Cisco_ios::Model::Switch.new(transport, @facts.facts_to_hash)
  @switch.retrieve
end

#loginObject



31
32
33
34
35
36
37
38
39
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 31

def 
  return if transport.handles_login?
  if @url.user != ''
    transport.command(@url.user, {:prompt => /^Password:/, :noop => false})
  else
    transport.expect(/^Password:/)
  end
  transport.command(@url.password, :noop => false)
end

#parse_enable(query) ⇒ Object



19
20
21
# File 'lib/puppet/util/network_device/cisco_ios/device.rb', line 19

def parse_enable(query)
  return $1 if query =~ /enable=(.*)/
end