logicminds / rubyipmi

Command line wrapper for ipmitool and freeipmi
GNU Lesser General Public License v2.1
35 stars 32 forks source link

Need a way to set privilege level #23

Closed mrichar1 closed 9 years ago

mrichar1 commented 9 years ago

Both ipmitool and freeipmi assume a default privilege level for the connection (administrator and operator respectively). This will result in an error if the user isn't at this level.

Both toolsets have a flag to pass in a specific priv (-L and -l) - can rubyipmi be extended to support setting the privilege level in the connection object?

Thanks!

logicminds commented 9 years ago

I thought the privilege (operator, administrator) was assigned to the user at user creation time? It seems weird that the CLI/Rubyipmi would be able to override the role that is assigned to the user.

To answer your question about extending support. Yes it would be really simple to add the priv option to the connection object. Basically would need to do the following in the initialize method of the connection object.

If you want to code this yourself and issue a pull request it should be fairly simple to do. Otherwise I can probably take care of this next week.

class Connection
def initialize
...
@options['L'] = opts[:priv] if opts.keys?(:priv)
# should probably check to make sure the priv type matches one of these
#-L <privlvl>
#              Force session privilege level.  Can be CALLBACK, USER, OPERATOR, ADMINISTRATOR. #Default is ADMINISTRATOR.
end

then call


conn = Rubyipmi.connect("username", "password", "hostname", {:priv => 'OPERATOR'})
logicminds commented 9 years ago

@mrichar1 just pushed branch 0.8.0 with this support. https://github.com/logicminds/rubyipmi/tree/0.8.0

I haven't merged to master yet until I can get my integration tests to pass. Feel free to test using this branch.

The privilege is optional as I am seeing weird issues sometimes when using it. Just provide this option to test out.

conn = Rubyipmi.connect("username", "password", "hostname", 'any', {:privilege => 'OPERATOR'})
# PRIV_TYPES = ['CALLBACK', 'USER', 'OPERATOR', 'ADMINISTRATOR']
mrichar1 commented 9 years ago

Hi,

I've done some testing and it seems to work as expected, both with ipmitool and freeipmi.

Many thanks!

logicminds commented 9 years ago

this has now been merge to master. Will release to ruby gems shortly.