Commits

Kaspar Schiess committed c692479

Pseudo code for listing the views

  • Participants
  • Parent commits b8a29f4

Comments (0)

Files changed (5)

 group :test do
   gem 'rspec'
   gem 'flexmock'
+  
+  gem 'guard-rspec'
+  gem 'growl'
+  gem 'rb-fsevent'
 end

File Gemfile.lock

   remote: https://rubygems.org/
   specs:
     clamp (0.5.0)
+    coderay (1.0.8)
     diff-lcs (1.1.3)
     flexmock (1.2.0)
+    growl (1.0.3)
+    guard (1.5.4)
+      listen (>= 0.4.2)
+      lumberjack (>= 1.0.2)
+      pry (>= 0.9.10)
+      thor (>= 0.14.6)
+    guard-rspec (0.5.9)
+      guard (>= 0.8.4)
+    listen (0.6.0)
+    lumberjack (1.0.2)
+    method_source (0.8.1)
     mixlib-shellout (1.1.0)
+    pry (0.9.10)
+      coderay (~> 1.0.5)
+      method_source (~> 0.8)
+      slop (~> 3.3.1)
+    rb-fsevent (0.9.2)
     rspec (2.12.0)
       rspec-core (~> 2.12.0)
       rspec-expectations (~> 2.12.0)
     rspec-expectations (2.12.0)
       diff-lcs (~> 1.1.3)
     rspec-mocks (2.12.0)
+    slop (3.3.3)
+    thor (0.16.0)
 
 PLATFORMS
   ruby
 DEPENDENCIES
   clamp
   flexmock
+  growl
+  guard-rspec
   mixlib-shellout
+  rb-fsevent
   rspec
+guard 'rspec', :version => 2 do
+  watch(%r{^spec/.+_spec\.rb$})
+  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
+  watch('spec/spec_helper.rb')  { "spec" }
+end
+
 class CommandLine < Clamp::Command
   subcommand 'list', 'Lists all targets with the corresponding attribtues' do
     def execute
-      shares = ISCSI::Context.new
-      shares.targets.each do |target|
+      ctx = ISCSI::Context.new
+      ctx.targets.each do |target|
         puts target.name
         p target.groups.map(&:name)
+        
+        pp target.views
       end
     end
   end

File lib/iscsi/target.rb

 module ISCSI
   class Target < Entity
+    # Returns all target groups this target is in. 
     def groups
       context.target_groups.
         select { |e| e.targets.include?(self) }
     end
+    
+    # Returns all views of this target sorted by LUN. 
+    #
+    def views
+      views = []
+      my_groups = self.groups
+       
+      # Looping over all LU, then looping over all views. Store those
+      # views in 'views' that concern a target group of ours.
+      #
+      context.lus.
+        each { |lu| 
+          lu.views.each { |view| 
+            if my_groups.include?(view.group) 
+              views << view
+            end } }
+            
+      # Return sorted by LUN
+      views.sort_by { |view| view.lun }
+    end
   end
 end