Kaspar Schiess avatar Kaspar Schiess committed 591dd0b

Implements views

Comments (0)

Files changed (8)

 require 'iscsi/target_group'
 require 'iscsi/target'
 require 'iscsi/lu'
+require 'iscsi/view'
 require 'iscsi/hash_parser'
 require 'iscsi/context'

lib/iscsi/context.rb

     def initialize verbose=false
       @categories = Hash.new { |h,k| h[k] = Category.new }
       @runner = ::Runner.new(verbose)
+      @stmf_view_cache = {}
     end
     def cat category
       @categories[category]
     define_category :target, :targets, Target, 'stmfadm list-target -v'
     define_category :target_group, :target_groups, TargetGroup, 'stmfadm list-tg -v'
     define_category :lu, :lus, LU, 'stmfadm list-lu -v'
+
+    def views lu
+      ArrayEnum.new(stmf_views(lu)) { |node| 
+        View.new(self, node, lu) }
+    end
+    def stmf_views lu
+      @stmf_view_cache[lu] ||= begin
+        parser = HashParser.new
+        command = "stmfadm list-view -l #{lu}"
+        parser.parse runner.shell(command)
+      end
+    end
   end
 end
 module ISCSI
   class LU < Entity
+    def views
+      context.views(name)
+    end
   end
 end

lib/iscsi/view.rb

+module ISCSI
+  class View < Entity
+    def initialize(context, node, lu_name)
+      super context, node
+      @lu_name = lu_name
+    end
+    
+    def target_group
+      context.target_group(@node[:target_group].value)
+    end
+    
+    def lu
+      context.lu(@lu_name)
+    end
+    
+    def lun
+      Integer(
+        @node[:lun].value)
+    end
+  end
+end

spec/fixture/lu_view0.txt

+View Entry: 0
+    Host group   : All
+    Target group : vol1
+    LUN          : 0

spec/fixture/lu_view1.txt

+View Entry: 0
+    Host group   : All
+    Target group : vol2
+    LUN          : 0

spec/fixture/target_groups.txt

         Member: iqn.2010-08.org.illumos:01:test
 Target Group: tg3
         Member: foo
-Target Group: tg4
+Target Group: vol1
         Member: iqn.2010-01.com.sdlkfjasldfjlaksjfdlk

spec/lib/iscsi/context_spec.rb

   let(:fake_runner) { FakeRunner.new(
     /^stmfadm list-target/ => fixture('target_list.txt'), 
     /^stmfadm list-tg/     => fixture('target_groups.txt'), 
-    /^stmfadm list-lu/     => fixture('lus.txt')) }
+    /^stmfadm list-lu/     => fixture('lus.txt'), 
+    /^stmfadm list-view -l 600144F085698100000050CB43400009/ => fixture('lu_view0.txt')) }
   before(:each) { 
     flexmock(ctx, runner: fake_runner) }
   
       end 
     end
   end
+  describe '#views(LU)[0]' do
+    slet(:view) { ctx.views('600144F085698100000050CB43400009')[0] }
+    
+    it "should link to a LU" do
+      view.lu.name.should == '600144F085698100000050CB43400009'
+    end 
+    it "should have a target group" do
+      view.target_group.name.should == "vol1"
+    end 
+    it "should have a LUN" do
+      view.lun.should == 0
+    end 
+  end
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.