rubyipmi 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +33 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +267 -0
  7. data/README.rdoc +18 -0
  8. data/Rakefile +49 -0
  9. data/VERSION +1 -0
  10. data/lib/rubyipmi.rb +80 -0
  11. data/lib/rubyipmi/commands/basecommand.rb +171 -0
  12. data/lib/rubyipmi/freeipmi/commands/basecommand.rb +60 -0
  13. data/lib/rubyipmi/freeipmi/commands/bmc.rb +37 -0
  14. data/lib/rubyipmi/freeipmi/commands/bmcconfig.rb +57 -0
  15. data/lib/rubyipmi/freeipmi/commands/bmcinfo.rb +76 -0
  16. data/lib/rubyipmi/freeipmi/commands/chassis.rb +123 -0
  17. data/lib/rubyipmi/freeipmi/commands/chassisconfig.rb +100 -0
  18. data/lib/rubyipmi/freeipmi/commands/lan.rb +111 -0
  19. data/lib/rubyipmi/freeipmi/commands/power.rb +72 -0
  20. data/lib/rubyipmi/freeipmi/connection.rb +43 -0
  21. data/lib/rubyipmi/freeipmi/errorcodes.rb +15 -0
  22. data/lib/rubyipmi/ipmitool/commands/basecommand.rb +60 -0
  23. data/lib/rubyipmi/ipmitool/commands/bmc.rb +95 -0
  24. data/lib/rubyipmi/ipmitool/commands/chassis.rb +106 -0
  25. data/lib/rubyipmi/ipmitool/commands/chassisconfig.rb +52 -0
  26. data/lib/rubyipmi/ipmitool/commands/lan.rb +162 -0
  27. data/lib/rubyipmi/ipmitool/commands/power.rb +74 -0
  28. data/lib/rubyipmi/ipmitool/connection.rb +46 -0
  29. data/lib/rubyipmi/ipmitool/errorcodes.rb +18 -0
  30. data/lib/rubyipmi/observablehash.rb +20 -0
  31. data/rubyipmi.gemspec +91 -0
  32. data/spec/bmc_spec.rb +35 -0
  33. data/spec/chassis_config_spec.rb +38 -0
  34. data/spec/chassis_spec.rb +24 -0
  35. data/spec/connection_spec.rb +31 -0
  36. data/spec/lan_spec.rb +61 -0
  37. data/spec/power_spec.rb +40 -0
  38. data/spec/rubyipmi_spec.rb +59 -0
  39. data/spec/spec_helper.rb +12 -0
  40. metadata +181 -0
@@ -0,0 +1,106 @@
1
+ module Rubyipmi::Ipmitool
2
+
3
+ class Chassis < Rubyipmi::Ipmitool::BaseCommand
4
+
5
+ def initialize(opts = ObservableHash.new)
6
+ super("ipmitool", opts)
7
+
8
+ end
9
+
10
+ # Turn the led light on / off or with a delay
11
+ def identify(status=false, delay=0)
12
+ if status
13
+ if delay <= 0
14
+ options["cmdargs"] = "chassis identify -1"
15
+ else
16
+ options["cmdargs"] = "chassis identify #{delay}"
17
+ end
18
+ else
19
+ options["cmdargs"] = "chassis identify 0"
20
+ end
21
+ # Run the command
22
+ value = runcmd
23
+ options.delete_notify("cmdargs")
24
+ return value
25
+ end
26
+
27
+ # Access to the power command created on the fly
28
+ def power
29
+ @power ||= Rubyipmi::Ipmitool::Power.new(@options)
30
+ end
31
+
32
+ # Access to the config command created on the fly
33
+ def config
34
+ @config ||= Rubyipmi::Ipmitool::ChassisConfig.new(@options)
35
+ end
36
+
37
+ # set boot device from given boot device
38
+ def bootdevice(device, reboot=false,persistent=false)
39
+ if config.bootdevices.include?(device)
40
+ status = config.bootdevice(device, persistent)
41
+ if reboot and status
42
+ power.cycle
43
+ end
44
+
45
+ else
46
+ raise "Device with name: #{device} is not a valid boot device for host #{options["hostname"]}"
47
+ end
48
+ end
49
+
50
+ # set boot device to pxe with option to reboot
51
+ def bootpxe(reboot=false,persistent=false)
52
+ status = config.bootpxe(persistent)
53
+ # Only reboot if setting the boot flag was successful
54
+ if reboot and status
55
+ power.cycle
56
+ end
57
+ end
58
+
59
+ # set boot device to disk with option to reboot
60
+ def bootdisk(reboot=false,persistent=false)
61
+ config.bootdisk(persistent)
62
+ # Only reboot if setting the boot flag was successful
63
+ if reboot and status
64
+ power.cycle
65
+ end
66
+
67
+ end
68
+
69
+ # set boot device to cdrom with option to reboot
70
+ def bootcdrom(reboot=false,persistent=false)
71
+ config.bootcdrom(persistent)
72
+ # Only reboot if setting the boot flag was successful
73
+ if reboot and status
74
+ power.cycle
75
+ end
76
+ end
77
+
78
+ # boot into bios setup with option to reboot
79
+ def bootbios(reboot=false,persistent=false)
80
+ config.bootbios(persistent)
81
+ # Only reboot if setting the boot flag was successful
82
+ if reboot and status
83
+ power.cycle
84
+ end
85
+ end
86
+
87
+ def status
88
+ options["cmdargs"] = "chassis status"
89
+ value = runcmd
90
+ options.delete_notify("cmdargs")
91
+ return { :result => @result, :value => value }
92
+ end
93
+
94
+ # A currently unsupported method to retrieve the led status
95
+ def identifystatus
96
+ options["cmdargs"] = "chassis identify status"
97
+ value = runcmd
98
+ options.delete_notify("cmdargs")
99
+ if value
100
+ @result.chomp.split(":").last.strip
101
+ end
102
+ end
103
+
104
+
105
+ end
106
+ end
@@ -0,0 +1,52 @@
1
+ module Rubyipmi::Ipmitool
2
+
3
+ class ChassisConfig < Rubyipmi::Ipmitool::BaseCommand
4
+
5
+ def initialize(opts = ObservableHash.new)
6
+ super("ipmitool", opts)
7
+
8
+ end
9
+
10
+ # Get the current boot device
11
+ def bootdevice
12
+ # Not available with ipmitool
13
+ false
14
+ end
15
+
16
+ # Set the boot device
17
+ def bootdevice(device, persistent=false)
18
+ @options["cmdargs"] = "chassis bootdev #{device}"
19
+ value = runcmd
20
+ @options.delete_notify("cmdargs")
21
+ return value
22
+ end
23
+
24
+ # Get list of available boot devices
25
+ def bootdevices
26
+ # ideally we should get this list from the ipmidevice
27
+ # However ipmitool only has a static list
28
+ ["pxe", "disk", "safe", "diag", "cdrom", "bios", "floppy"]
29
+ end
30
+
31
+ # shortcut to set boot device to pxe
32
+ def bootpxe(persistent=false)
33
+ bootdevice("pxe")
34
+ end
35
+
36
+ # shortcut to set boot device to disk
37
+ def bootdisk(persistent=false)
38
+ bootdevice("disk")
39
+ end
40
+
41
+ # shortcut to set boot device to cdrom
42
+ def bootcdrom(persistent=false)
43
+ bootdevice("cdrom")
44
+ end
45
+
46
+ # shortcut to boot into bios setup
47
+ def bootbios(persistent=false)
48
+ bootdevice("bios")
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,162 @@
1
+ module Rubyipmi::Ipmitool
2
+
3
+ class Lan < Rubyipmi::Ipmitool::BaseCommand
4
+
5
+ attr_accessor :info
6
+ attr_accessor :channel
7
+
8
+ def initialize(opts = ObservableHash.new)
9
+ super("ipmitool", opts)
10
+ @info = {}
11
+ @channel = 2
12
+
13
+ end
14
+
15
+ def info
16
+ if @info.length < 1
17
+ parse(print)
18
+ else
19
+ @info
20
+ end
21
+ end
22
+
23
+ def print
24
+ @options["cmdargs"] = "lan print"
25
+ value = runcmd
26
+ @options.delete_notify("cmdargs")
27
+ if value
28
+ @result
29
+ end
30
+ end
31
+
32
+ # def snmp
33
+ # if @info.length < 1
34
+ # parse(print)
35
+ # end
36
+ # # Some systems do not report the snmp string
37
+ # @info["snmp community string"]
38
+ # end
39
+
40
+ def ip
41
+ if @info.length < 1
42
+ parse(print)
43
+ end
44
+ @info["ip address"]
45
+ end
46
+
47
+ def mac
48
+ if @info.length < 1
49
+ parse(print)
50
+ end
51
+ @info["mac address"]
52
+ end
53
+
54
+ def subnet
55
+ if @info.length < 1
56
+ parse(print)
57
+ end
58
+ @info["subnet mask"]
59
+ end
60
+
61
+ def gateway
62
+ if @info.length < 1
63
+ parse(print)
64
+ end
65
+ @info["default gateway ip"]
66
+ end
67
+
68
+ # def vlanid
69
+ # if @info.length < 1
70
+ # parse(print)
71
+ # end
72
+ # @info["802.1q vlan id"]
73
+ # end
74
+
75
+ # def snmp=(community)
76
+ # @options["cmdargs"] = "lan set #{channel} snmp #{community}"
77
+ # value = runcmd
78
+ # @options.delete_notify("cmdargs")
79
+ # return value
80
+ # end
81
+
82
+ def set_ip(address, static=true)
83
+ @options["cmdargs"] = "lan set #{channel} ipaddr #{address}"
84
+ value = runcmd
85
+ @options.delete_notify("cmdargs")
86
+ return value
87
+ end
88
+
89
+ def set_subnet(subnet)
90
+ @options["cmdargs"] = "lan set #{channel} netmask #{subnet}"
91
+ value = runcmd
92
+ @options.delete_notify("cmdargs")
93
+ return value
94
+ end
95
+
96
+ def set_gateway(address)
97
+ @options["cmdargs"] = "lan set #{channel} defgw #{address}"
98
+ value = runcmd
99
+ @options.delete_notify("cmdargs")
100
+ return value
101
+ end
102
+
103
+ def dhcp?
104
+ if @info.length < 1
105
+ parse(print)
106
+ end
107
+ @info["ip address source"].match(/dhcp/i) != nil
108
+ end
109
+
110
+ def static?
111
+ if @info.length < 1
112
+ parse(print)
113
+ end
114
+ @info["ip address source"].match(/static/i) != nil
115
+ end
116
+
117
+ # def vlanid=(vlan)
118
+ # @options["cmdargs"] = "lan set #{channel} vlan id #{vlan}"
119
+ # value = runcmd
120
+ # @options.delete_notify("cmdargs")
121
+ # return value
122
+ # end
123
+
124
+
125
+ def parse(landata)
126
+ multikey = ""
127
+ multivalue = {}
128
+
129
+ landata.lines.each do |line|
130
+ # clean up the data from spaces
131
+ item = line.split(':', 2)
132
+ key = item.first.strip.downcase
133
+ value = item.last.strip
134
+ @info[key] = value
135
+
136
+ end
137
+ return @info
138
+ end
139
+
140
+
141
+
142
+
143
+ end
144
+ end
145
+
146
+ #Set in Progress : Set Complete
147
+ #Auth Type Support :
148
+ #Auth Type Enable : Callback :
149
+ # : User : NONE MD2 MD5 PASSWORD OEM
150
+ # : Operator : NONE MD2 MD5
151
+ # : Admin : MD2 MD5
152
+ # : OEM :
153
+ #IP Address Source : DHCP Address
154
+ #IP Address : 192.168.1.41
155
+ #Subnet Mask : 255.255.255.0
156
+ #MAC Address : 00:17:a4:49:ab:70
157
+ #BMC ARP Control : ARP Responses Enabled, Gratuitous ARP Disabled
158
+ #Gratituous ARP Intrvl : 0.0 seconds
159
+ #Default Gateway IP : 192.168.1.1
160
+ #802.1q VLAN ID : Disabled
161
+ #802.1q VLAN Priority : 0
162
+ #Cipher Suite Priv Max : Not Available
@@ -0,0 +1,74 @@
1
+ module Rubyipmi::Ipmitool
2
+
3
+ class Power < Rubyipmi::Ipmitool::BaseCommand
4
+
5
+ def initialize(opts = ObservableHash.new)
6
+ super("ipmitool", opts)
7
+ end
8
+
9
+ # The command function is a wrapper that actually calls the run method
10
+ def command(opt)
11
+ @options["cmdargs"] = "power #{opt}"
12
+ value = runcmd
13
+ @options.delete_notify("cmdargs")
14
+ return value
15
+ end
16
+
17
+ # Turn on the system
18
+ def on
19
+ command("on")
20
+ end
21
+
22
+ # Turn off the system
23
+ def off
24
+ command("off")
25
+ end
26
+
27
+ # Power cycle the system
28
+ def cycle
29
+ # if the system is off turn it on
30
+ if off?
31
+ on
32
+ else
33
+ command("cycle")
34
+ end
35
+
36
+ end
37
+
38
+ # Perform a power reset on the system
39
+ def reset
40
+ command("reset")
41
+ end
42
+
43
+ # Perform a soft shutdown, like briefly pushing the power button
44
+ def softShutdown
45
+ command("soft")
46
+ end
47
+
48
+ def powerInterrupt
49
+ command("diag")
50
+ end
51
+
52
+ # Get the power status of the system, will show either on or off
53
+ def status
54
+ value = command("status")
55
+ if value
56
+ @result.match(/(off|on)/).to_s
57
+ end
58
+ end
59
+
60
+ # Test to see if the power is on
61
+ def on?
62
+ status == "on"
63
+
64
+ end
65
+
66
+ # Test to see if the power is off
67
+ def off?
68
+ status == "off"
69
+ end
70
+
71
+
72
+
73
+ end
74
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubyipmi/ipmitool/errorcodes'
2
+ require 'rubyipmi/observablehash'
3
+ require 'rubyipmi/commands/basecommand'
4
+ require 'rubyipmi/ipmitool/commands/basecommand'
5
+
6
+ Dir[File.dirname(__FILE__) + '/commands/*.rb'].each do |file|
7
+ require "#{file.split(".rb").first}"
8
+ end
9
+
10
+ module Rubyipmi
11
+ module Ipmitool
12
+
13
+ class Connection
14
+
15
+ attr_accessor :options
16
+
17
+
18
+ def initialize(user, pass, host)
19
+ @options = Rubyipmi::ObservableHash.new
20
+ raise("Must provide a host to connect to") unless host
21
+ @options["H"] = host
22
+ # Credentials can also be stored in the freeipmi configuration file
23
+ # So they are not required
24
+ @options["U"] = user if user
25
+ @options["P"] = pass if pass
26
+ # default to IPMI 2.0 communication
27
+ #@options["I"] = "lanplus"
28
+
29
+ #getWorkArounds
30
+ end
31
+
32
+ def provider
33
+ return "ipmitool"
34
+ end
35
+
36
+ def bmc
37
+ @bmc ||= Rubyipmi::Ipmitool::Bmc.new(@options)
38
+ end
39
+
40
+ def chassis
41
+ @chassis ||= Rubyipmi::Ipmitool::Chassis.new(@options)
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module Rubyipmi
2
+ module Ipmitool
3
+ class ErrorCodes
4
+
5
+ @@code = {
6
+ "Authentication type NONE not supported" => {"I" => "lanplus"},
7
+
8
+ }
9
+
10
+ def self.code
11
+ @@code
12
+ end
13
+ end
14
+
15
+
16
+ end
17
+ end
18
+