Class: Cisco::Yum
Overview
This Yum class provides cisco package management functions through nxapi.
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
.detect_vrf ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/cisco_node_utils/yum.rb', line 43
def self.detect_vrf
inode = File::Stat.new('/proc/self/ns/net').ino
vrfname = File.basename(`find -L /var/run/netns/ -inum #{inode}`.chop)
vrf = 'vrf ' + vrfname unless vrfname.empty?
vrf
end
|
.install(pkg, vrf = nil) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cisco_node_utils/yum.rb', line 53
def self.install(pkg, vrf=nil)
vrf = vrf.nil? ? detect_vrf : "vrf #{vrf}"
config_set('yum', 'install', pkg, vrf)
validate_installed(pkg)
end
|
.query(pkg) ⇒ Object
returns version of package, or false if package doesn’t exist
65
66
67
68
69
70
71
|
# File 'lib/cisco_node_utils/yum.rb', line 65
def self.query(pkg)
fail TypeError unless pkg.is_a? String
fail ArgumentError if pkg.empty?
b = config_get('yum', 'query', pkg)
fail "Multiple matching packages found for #{pkg}" if b && b.size > 1
b.nil? ? nil : b.first
end
|
.remove(pkg) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cisco_node_utils/yum.rb', line 73
def self.remove(pkg)
config_set('yum', 'deactivate', pkg)
while (try ||= 1) < 20
o = config_set('yum', 'remove', pkg)
break unless o[/operation is in progress, please try again later/]
sleep 1
try += 1
end
end
|
.validate_installed(pkg) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cisco_node_utils/yum.rb', line 25
def self.validate_installed(pkg)
patch_data = config_get('yum', 'query_all')
patch_data.each do |name_arch, version, _state|
next if name_arch.rindex('.').nil?
arch = name_arch.slice!(name_arch.rindex('.')..-1).delete('.')
version = arch = '' if name_arch == pkg
if pkg.match(name_arch) && pkg.match(version) && pkg.match(arch)
return true
end
end
fail 'Failed to install the requested rpm'
end
|