Class: Cisco::Upgrade

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/upgrade.rb

Overview

Upgrade - node util class for upgrading Cisco devices

Class Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Class Method Details

.box_online?Boolean

Return true if box is online and config mode is ready to be used

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/cisco_node_utils/upgrade.rb', line 79

def self.box_online?
  output = config_set('upgrade', 'is_box_online')
  output[0]['body'] == {}
end

.clear_statusObject

Delete install logs from previous installation



24
25
26
# File 'lib/cisco_node_utils/upgrade.rb', line 24

def self.clear_status
  config_set('upgrade', 'clear_status')
end

.delete(image, uri = 'bootflash:') ⇒ Object

Deletes ‘image’ from ‘uri’



29
30
31
32
33
# File 'lib/cisco_node_utils/upgrade.rb', line 29

def self.delete(image, uri='bootflash:')
  config_set('upgrade', 'delete', image: image, uri: uri)
rescue Cisco::CliError => e
  raise e
end

.delete_boot(uri = 'bootflash:') ⇒ Object

Deletes currently booted image



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cisco_node_utils/upgrade.rb', line 36

def self.delete_boot(uri='bootflash:')
  # Incase of a N9K, N3K and N9Kv the system and kickstart images are
  # the same.
  # Incase of a N5K, N6K and N7K the system and kickstart images are
  # different.
  system_image = config_get('show_version', 'system_image').split('/')[-1]
  kickstart_image = config_get('show_version', 'boot_image').split('/')[-1]
  if kickstart_image == system_image
    config_set('upgrade', 'delete_boot', image: system_image, uri: uri)
  else
    config_set('upgrade', 'delete_boot', image: system_image,
                                         uri:   uri)
    config_set('upgrade', 'delete_boot', image: kickstart_image,
                                         uri:   uri)
  end
rescue Cisco::CliError => e
  raise e
end

.image_version(image = nil, uri = nil) ⇒ Object

Returns version of the ‘image’



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cisco_node_utils/upgrade.rb', line 56

def self.image_version(image=nil, uri=nil)
  # Returns version of currently booted image by default
  if image && uri
    config_get('upgrade', 'image_version', image: image, uri: uri)
  else
    version = config_get('show_version', 'version')
    # show version displays version differently for release and
    # development builds.
    # Eg: release build
    #       NXOS: version 7.0(3)I4(2)
    # Eg: development build
    #       NXOS: version 7.0(3)IFD6(1) [build 7.0(3)IGD7(0.65)]
    return version unless version[/build\s+\S+/]
    version.split(' ')[-1].split(']')[0]
  end
end

.packageObject

Return the nxos image installed on the device



74
75
76
# File 'lib/cisco_node_utils/upgrade.rb', line 74

def self.package
  config_get('show_version', 'system_image')
end

.save_configObject



84
85
86
87
88
# File 'lib/cisco_node_utils/upgrade.rb', line 84

def self.save_config
  config_set('upgrade', 'save_config')
rescue Cisco::CliError => e
  raise e
end

.upgrade(image, uri = 'bootflash:', del_boot = false, force_all = false) ⇒ Object

Attempts to upgrade the device to ‘image’



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cisco_node_utils/upgrade.rb', line 101

def self.upgrade(image, uri='bootflash:', del_boot=false,
                 force_all=false)
  delete_boot(uri) if del_boot
  force_all ? upgrade_str = 'upgrade_force' : upgrade_str = 'upgrade'
  begin
    Cisco::Logger.debug("Upgrading to version: #{image}")
    config_set('upgrade', upgrade_str, image: image, uri: uri)
  rescue Cisco::RequestFailed, Cisco::CliError => e1
    # raise if install command failed
    raise e1 if e1.class == Cisco::CliError
    # Catch 'Backend Processing Error'. Install continues inspite of the
    # error thrown. Resend install command and expect a CliError.
    begin
      config_set('upgrade', upgrade_str, image: image, uri: uri)
    rescue Cisco::CliError => e2
      raise e2 unless
        e2.message.include?('Another install procedure may be in progress')
    end
  end
end

.upgraded?Boolean

Returns True if device upgraded

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
# File 'lib/cisco_node_utils/upgrade.rb', line 91

def self.upgraded?
  return false unless config_get('upgrade', 'upgraded')
  (0..500).each do
    sleep 1
    return true if box_online?
  end
  fail 'Configuration is still blocked'
end