Class: QemuToolkit::ISCSITarget
- Inherits:
-
Object
- Object
- QemuToolkit::ISCSITarget
- Defined in:
- lib/qemu-toolkit/iscsi_target.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#iqn ⇒ Object
readonly
Returns the value of attribute iqn.
Instance Method Summary collapse
- #disks ⇒ Object
- #ensure_exists ⇒ Object
-
#initialize(iqn, address, backend) ⇒ ISCSITarget
constructor
A new instance of ISCSITarget.
- #mapped? ⇒ Boolean
-
#target_list ⇒ Object
A cached ‘list target -vS’.
Constructor Details
#initialize(iqn, address, backend) ⇒ ISCSITarget
Returns a new instance of ISCSITarget.
3 4 5 6 7 8 9 10 11 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 3 def initialize(iqn, address, backend) @iqn, @address = iqn, address @backend = backend # Keep track if disks has ever returned an array of size > 0. This would # mean that the target is connected and will stay connected until we # change that. @mapped = false end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
14 15 16 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 14 def address @address end |
#iqn ⇒ Object (readonly)
Returns the value of attribute iqn.
13 14 15 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 13 def iqn @iqn end |
Instance Method Details
#disks ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 45 def disks luns = [] state = 0 last_lun = nil target_list.each_line do |line| case state when 0 state += 1 if line.match(/^Target: #{Regexp.escape(iqn)}\n/m) lun = nil when 1 if md=line.match(/^\s+LUN: (\d+)\n/m) last_lun = md[1] end if last_lun && md=line.match(/^\s+OS Device Name: (\/dev\/rdsk\/.*)\n/m) luns << [Integer(last_lun), md[1]] end state += 1 if line.match(/^Target: /) end end luns.sort_by { |no,_| no }.map { |_, dev| p0ify(dev) } end |
#ensure_exists ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 20 def ensure_exists # If the target is mapped already, nothing to do. return if mapped? # Map the target begin @backend.iscsiadm :add, 'static-config', "#{iqn},#{address}", '2>/dev/null' rescue # Ignore already mapped targets end print "Waiting for iSCSI disks to come online..." while !mapped? print '.' sleep 0.5 # takes a short while until login end puts 'OK.' end |
#mapped? ⇒ Boolean
16 17 18 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 16 def mapped? disks.size > 0 end |
#target_list ⇒ Object
A cached ‘list target -vS’
41 42 43 |
# File 'lib/qemu-toolkit/iscsi_target.rb', line 41 def target_list @backend.iscsiadm :list, :target, '-vS' end |