class PuppetX::Eos::Extension
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
Constants
- BOOTEXT
Public Class Methods
# File lib/puppet_x/eos/modules/extension.rb, line 47 def initialize(api) @api = api end
Public Instance Methods
Returns if file is loaded on boot or not
@param [String] name The name of the file
@return [Boolean] True if it loades on boot otherwise False
# 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
Uninstalls and removes and extension from an EOS node. The extension will be unloaded and deleted from /mnt/flash
@params [String] name The name of the extension to remove
@return [Boolean] True if the command succeeds or False if it does
not succeed
# 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
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 } }]
@return [Hash<Hash<String, String>>] Nested hash describing
the extension details. If there are no extensions then an empty Hash is returned
# File lib/puppet_x/eos/modules/extension.rb, line 70 def get @api.enable('show extensions') end
Copies and installs the extension from a remote server to the node running EOS using the eAPI coopy command.
@param [String] url The full url to the RPM @param [String] force Specifies the use of the force keyword
@return [Boolean] True if the installation succeeds and False if it
does not succeed
# 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
Loads an existing extension into EOS. The extension must already be copied over to the node using create
@params [String] name The name of the extension to load @param [Hash] opt Options for loading the extions @option opts [Boolean] :force Appends force to the command
@return [Boolean] True if the command succeeds or False if it does
not succeed
# 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
Configures the extension to persistent on system restarts
@param [String] enabled Whether or not the extension is enabled @param [String] name The name of the extension @param force Specifies if the force keyword should be used
@return [Boolean] True if the extension was set to autoload or False
if it was not
# 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