Class: Cisco::Yum
- Inherits:
-
Object
- Object
- Cisco::Yum
- Defined in:
- lib/cisco_node_utils/yum.rb
Overview
This Yum class provides cisco package management functions through nxapi.
Constant Summary collapse
Class Method Summary collapse
- .decompose_name(file_name) ⇒ Object
- .get_vrf ⇒ Object
- .install(pkg, vrf = nil) ⇒ Object
-
.query(pkg) ⇒ Object
returns version of package, or false if package doesn’t exist.
- .remove(pkg) ⇒ Object
- .validate(pkg) ⇒ Object
Class Method Details
.decompose_name(file_name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cisco_node_utils/yum.rb', line 27 def self.decompose_name(file_name) # ex: chef-12.0.0alpha.2+20150319.git.1.b6f-1.el5.x86_64.rpm name_ver_arch_regex = /^([\w\-\+]+)-(\d+\..*)\.(\w{4,})(?:\.rpm)?$/ # ex n9000_sample-1.0.0-7.0.3.x86_64.rpm name_ver_arch_regex_nx = /^(.*)-([\d\.]+-[\d\.]+)\.(\w{4,})\.rpm$/ # ex: b+z-ip2.x64_64 name_arch_regex = /^([\w\-\+]+)\.(\w+)$/ file_name.match(name_ver_arch_regex) || file_name.match(name_ver_arch_regex_nx) || file_name.match(name_arch_regex) end |
.get_vrf ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/cisco_node_utils/yum.rb', line 61 def self.get_vrf # Detect current namespace from agent environment inode = File::Stat.new("/proc/self/ns/net").ino # -L reqd for guestshell's find command vrfname = File.basename(`find -L /var/run/netns/ -inum #{inode}`.chop) vrf = "vrf " + vrfname unless vrfname.empty? vrf end |
.install(pkg, vrf = nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cisco_node_utils/yum.rb', line 70 def self.install(pkg, vrf = nil) vrf = vrf.nil? ? get_vrf : "vrf #{vrf}" @@node.config_set("yum", "install", pkg, vrf) # HACK: The current nxos host installer is a multi-part command # which may fail at a later stage yet return a false positive; # therefore a post-validation check is needed here to verify the # actual outcome. validate(pkg) end |
.query(pkg) ⇒ Object
returns version of package, or false if package doesn’t exist
82 83 84 85 86 87 88 |
# File 'lib/cisco_node_utils/yum.rb', line 82 def self.query(pkg) raise TypeError unless pkg.is_a? String raise ArgumentError if pkg.empty? b = @@node.config_get("yum", "query", pkg) raise "Multiple matching packages found for #{pkg}" if b and b.size > 1 b.nil? ? nil : b.first end |
.remove(pkg) ⇒ Object
90 91 92 |
# File 'lib/cisco_node_utils/yum.rb', line 90 def self.remove(pkg) @@node.config_set("yum", "remove", pkg) end |
.validate(pkg) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cisco_node_utils/yum.rb', line 42 def self.validate(pkg) file_name = pkg.strip.gsub(':', '/').split('/').last pkg_info = Yum.decompose_name(file_name) if pkg_info.nil? query_name = file_name else if pkg_info[3].nil? query_name = pkg_info[1] else query_name = "#{pkg_info[1]}.#{pkg_info[3]}" end end should_ver = pkg_info[2] if pkg_info && pkg_info[3] ver = query(query_name) if ver.nil? || (!should_ver.nil? && should_ver != ver) raise "Failed to install the requested rpm" end end |