Class: PuppetX::Eos::Extension
- Inherits:
-
Object
- Object
- PuppetX::Eos::Extension
- Defined in:
- lib/puppet_x/eos/modules/extension.rb
Overview
The Extensio class provides management of extensions in EOS. Extensions are simply RPM packages that can loaded onto the switch. This class allows installing, deleting and configuring extensions
Constant Summary collapse
- BOOTEXT =
'/mnt/flash/boot-extensions'
Instance Method Summary collapse
-
#autoload?(name) ⇒ Boolean
Returns if file is loaded on boot or not.
-
#delete(name) ⇒ Boolean
Uninstalls and removes and extension from an EOS node.
-
#get ⇒ Hash<Hash<String, String>>
Retrieves all of the extenions loaded in EOS and returns an array of hashes using the ‘show extensions’ command over eAPI.
-
#initialize(api) ⇒ Extension
constructor
A new instance of Extension.
-
#install(url, force) ⇒ Boolean
Copies and installs the extension from a remote server to the node running EOS using the eAPI coopy command.
-
#load(name, force) ⇒ Boolean
Loads an existing extension into EOS.
-
#set_autoload(enabled, name, force) ⇒ Boolean
Configures the extension to persistent on system restarts.
Constructor Details
#initialize(api) ⇒ Extension
Returns a new instance of Extension.
47 48 49 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 47 def initialize(api) @api = api end |
Instance Method Details
#autoload?(name) ⇒ Boolean
Returns if file is loaded on boot or not
80 81 82 83 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 80 def autoload?(name) name = URI(name).to_s.split('/')[-1] File.open(BOOTEXT).read.scan(/#{name}[\sforce\n|\n]/).size > 0 end |
#delete(name) ⇒ Boolean
Uninstalls and removes and extension from an EOS node. The extension will be unloaded and deleted from /mnt/flash
125 126 127 128 129 130 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 125 def delete(name) name = URI(name).to_s.split('/')[-1] set_autoload(:false, name, false) @api.enable("no extension #{name}") @api.enable("delete extension:#{name}") == [{}] end |
#get ⇒ Hash<Hash<String, String>>
Retrieves all of the extenions loaded in EOS and returns an array of hashes using the ‘show extensions’ command over eAPI.
Example:
[{
"ruby-1.9.3-1.swix": {
"status": "installed", # installed, forceInstalled
"version": "1.9.3.484",
"presence": "present",
"release": "32.eos4",
"numRpms": 10,
"error": false
}
}]
70 71 72 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 70 def get @api.enable('show extensions') end |
#install(url, force) ⇒ Boolean
Copies and installs the extension from a remote server to the node running EOS using the eAPI coopy command.
94 95 96 97 98 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 94 def install(url, force) force = false if force.nil? @api.enable("copy #{url} extension:") load(url, force) end |
#load(name, force) ⇒ Boolean
Loads an existing extension into EOS. The extension must already be copied over to the node using #create
110 111 112 113 114 115 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 110 def load(name, force) name = URI(name).to_s.split('/')[-1] command = "extension #{name}" command << ' force' if force @api.enable(command) == [{}] end |
#set_autoload(enabled, name, force) ⇒ Boolean
Configures the extension to persistent on system restarts
@param force Specifies if the force keyword should be used
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/puppet_x/eos/modules/extension.rb', line 141 def set_autoload(enabled, name, force) enabled = :true if enabled.nil? force = false if force.nil? name = URI(name).to_s.split('/')[-1] entry = "#{name}" entry << ' force' if force case enabled when :true if File.open(BOOTEXT).read.scan(/#{name}[\sforce\n|\n]/).size == 0 File.open(BOOTEXT, 'a') { |f| f << "#{entry}\n" } return true end when :false contents = File.readlines(BOOTEXT) contents.delete("#{name}\n") File.open(BOOTEXT, 'w') do |f| f.puts(contents) end return true end false end |