-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jeffmccune/ar21_snmp_community
(ARISTA-21) Use snmp_community flush for management
- Loading branch information
Showing
9 changed files
with
532 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# encoding: utf-8 | ||
|
||
require 'puppet/type' | ||
require 'puppet_x/net_dev/eos_api' | ||
Puppet::Type.type(:snmp_community).provide(:eos) do | ||
|
||
# Create methods that set the @property_hash for the #flush method | ||
mk_resource_methods | ||
|
||
# Mix in the api as instance methods | ||
include PuppetX::NetDev::EosProviderMethods | ||
# Mix in the api as class methods | ||
extend PuppetX::NetDev::EosProviderMethods | ||
# Mix in common provider class methods (e.g. self.prefetch) | ||
extend PuppetX::NetDev::EosProviderClassMethods | ||
|
||
def self.instances | ||
communities = api.snmp_communities | ||
communities.each { |hsh| hsh[:ensure] = :present } | ||
communities.map { |resource_hash| new(resource_hash) } | ||
end | ||
|
||
def initialize(resource = {}) | ||
super(resource) | ||
@property_flush = {} | ||
end | ||
|
||
def exists? | ||
@property_hash[:ensure] == :present | ||
end | ||
|
||
def create | ||
@property_flush = resource.to_hash.select do |key, _| | ||
[:name, :group, :acl].include? key | ||
end | ||
@property_flush[:ensure] = :present | ||
end | ||
|
||
def destroy | ||
@property_flush = { name: name, ensure: :absent } | ||
end | ||
|
||
def group=(value) | ||
@property_flush[:group] = value | ||
end | ||
|
||
def acl=(value) | ||
@property_flush[:acl] = value | ||
end | ||
|
||
def flush | ||
new_property_hash = @property_hash.merge(@property_flush) | ||
new_property_hash[:name] = name | ||
|
||
case new_property_hash[:ensure] | ||
when :absent, 'absent' | ||
api.snmp_community_destroy(name: name) | ||
else | ||
api.snmp_community_set(new_property_hash) | ||
end | ||
|
||
@property_hash = new_property_hash | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- !ruby/sym name: jeff | ||
!ruby/sym group: rw | ||
!ruby/sym acl: stest1 | ||
- !ruby/sym name: private | ||
!ruby/sym group: rw | ||
- !ruby/sym name: public | ||
!ruby/sym group: ro |
2 changes: 2 additions & 0 deletions
2
spec/fixtures/fixture_get_snmp_communities_non_existent_acl.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
- output: "\nCommunity name: jeff\nCommunity access: read-write\nAccess list: stest1\n\nCommunity name: jeff2\nCommunity access: read-only\nAccess list: stest1\n\nCommunity name: jeff3\nCommunity access: read-only\nAccess list: stest1\n\nCommunity name: jeff4\nCommunity access: read-only\nAccess list: stest2 (non-existent)\n\nCommunity name: private\nCommunity access: read-write\n\nCommunity name: public\nCommunity access: read-only\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
- output: "\nCommunity name: jeff\nCommunity access: read-write\nAccess list: stest1\n\nCommunity name: private\nCommunity access: read-write\n\nCommunity name: public\nCommunity access: read-only\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.