Class: Puppet::NetDev::CE::UserApi
- Defined in:
- lib/puppet/provider/ce/api/user/user_api.rb
Instance Method Summary collapse
-
#create_user(resource) ⇒ Object
password is a must to create a new user.
- #delete_user(resource) ⇒ Object
- #get_user ⇒ Object
-
#initialize ⇒ UserApi
constructor
A new instance of UserApi.
- #set_user(resource) ⇒ Object
Constructor Details
#initialize ⇒ UserApi
Returns a new instance of UserApi.
22 23 24 |
# File 'lib/puppet/provider/ce/api/user/user_api.rb', line 22 def initialize super() end |
Instance Method Details
#create_user(resource) ⇒ Object
password is a must to create a new user
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/provider/ce/api/user/user_api.rb', line 64 def create_user(resource) session = Puppet::NetDev::CE::Device.session set_user_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><aaa xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><lam><users><user operation="merge"><userName>' + (resource[:name]).to_s + '</userName>' if resource[:password] set_user_xml += '<password>' + (resource[:password]).to_s + '</password>' end set_user_xml += '</user></users></lam></aaa></config></edit-config></rpc>' session.rpc.do_config(set_user_xml) end |
#delete_user(resource) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/puppet/provider/ce/api/user/user_api.rb', line 78 def delete_user(resource) session = Puppet::NetDev::CE::Device.session delete_user_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><aaa xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><lam><users><user operation="delete"><userName>' + (resource[:name]).to_s + '</userName></user></users></lam></aaa></config></edit-config></rpc>' session.rpc.do_config(delete_user_xml) end |
#get_user ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet/provider/ce/api/user/user_api.rb', line 26 def get_user user_array = [] session = Puppet::NetDev::CE::Device.session get_user_xml = '<rpc><get><filter type="subtree"><aaa xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><lam><users><user><userName></userName><password></password></user></users></lam></aaa></filter></get></rpc>' user_all = session.rpc.do_config(get_user_xml) user_elements = user_all.first_element_child.first_element_child.first_element_child user_elements.element_children.each do |user_elem| user_doc = Nokogiri::XML(user_elem.to_s) username = user_doc.xpath('/user/userName').text property_hash = { ensure: :present } property_hash[:name] = username property_hash[:user] = username property_hash[:password] = '******' user_array << property_hash end user_array end |
#set_user(resource) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/provider/ce/api/user/user_api.rb', line 49 def set_user(resource) session = Puppet::NetDev::CE::Device.session set_user_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><aaa xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><lam><users><user operation="merge"><userName>' + (resource[:name]).to_s + '</userName>' if resource[:password] set_user_xml += '<password>' + (resource[:password]).to_s + '</password>' end set_user_xml += '</user></users></lam></aaa></config></edit-config></rpc>' session.rpc.do_config(set_user_xml) end |