Class: Chef::Knife::UcsPoolList

Inherits:
Chef::Knife show all
Includes:
UCSBase
Defined in:
lib/chef/knife/ucs_pool_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UCSBase

#connection, #destroyer, included, #inventory, #locate_config_value, #manager, #msg_pair, #provisioner

Instance Attribute Details

#initial_sleep_delayObject

Returns the value of attribute initial_sleep_delay.



30
31
32
# File 'lib/chef/knife/ucs_pool_list.rb', line 30

def initial_sleep_delay
  @initial_sleep_delay
end

Instance Method Details

#runObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/chef/knife/ucs_pool_list.rb', line 48

def run
  $stdout.sync = true

  #Using Chef's UI (much better looking:)) instead of list methods provided by ucslib.
  pool_type = "#{Chef::Config[:knife][:type]}".downcase
  case pool_type
  when 'wwpn'
    wwpnpool_list = [
      ui.color('Organization', :bold),
      ui.color('WWPN',         :bold),
      ui.color('Assigned To',  :bold),
      ui.color('Assigned',     :bold)
    ]
    manager.xpath("configResolveClasses/outConfigs/fcpoolInitiator").each do |wwpnpool|
      extracted_org_names = "#{wwpnpool.attributes["assignedToDn"]}"
      org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
      org_names.each do |orgs| #Ugly...refactor
        orgs.each do |org|
          @org = org
        end
      end
      wwpnpool_list << "#{@org}"
      wwpnpool_list << "#{wwpnpool.attributes["id"]}"
      extracted_service_profile_names = "#{wwpnpool.attributes["assignedToDn"]}"
      service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
      service_profile_names.each do |service_profile_name| #Ugly...refactor
      hostnames = service_profile_name
      hostnames.each do |host_name|
            @host = host_name
          end
      end
      wwpnpool_list << "#{@host}"
      wwpnpool_list << begin
        state = "#{wwpnpool.attributes["assigned"]}"
        case state
        when 'yes'
           ui.color(state, :green)
        when 'assigning'
           ui.color(state, :yellow)
        else
           ui.color(state, :red)
        end        
    end
  end
    puts ui.list(wwpnpool_list, :uneven_columns_across, 4)

  when 'uuid'
    uuidpool_list = [
      ui.color('Organization', :bold),
      ui.color('UUID Suffix',  :bold),
      ui.color('Assigned To',  :bold),
      ui.color('Assigned',     :bold)
    ]
    manager.xpath("configResolveClasses/outConfigs/uuidpoolPooled").each do |uuidpool|
      extracted_org_names = "#{uuidpool.attributes["assignedToDn"]}"
      org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
      org_names.each do |orgs| #Ugly...refactor
        orgs.each do |org|
          @org = org
        end
      end
      uuidpool_list << "#{@org}"
      uuidpool_list << "#{uuidpool.attributes["id"]}"
      extracted_service_profile_names = "#{uuidpool.attributes["assignedToDn"]}"
      service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
      service_profile_names.each do |service_profile_name| #Ugly...refactor
      hostnames = service_profile_name
      hostnames.each do |host_name|
            @host = host_name
          end
      end
      uuidpool_list << "#{@host}"
      uuidpool_list << begin
        state = "#{uuidpool.attributes["assigned"]}"
        case state
        when 'yes'
           ui.color(state, :green)
        when 'assigning'
           ui.color(state, :yellow)
        else
           ui.color(state, :red)
        end        
    end
  end
    puts ui.list(uuidpool_list, :uneven_columns_across, 4)

  when 'mac' 
    macpool_list = [
       ui.color('Organization',   :bold),
       ui.color('Mac Address',    :bold),
       ui.color('Assigned To',    :bold),
       ui.color('vNIC',           :bold),
       ui.color('Assigned',       :bold)
     ]
     
    manager.xpath("configResolveClasses/outConfigs/macpoolPooled").each do |macpool|
      extracted_org_names = "#{macpool.attributes["assignedToDn"]}"
      org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
      org_names.each do |orgs| #Ugly...refactor
        orgs.each do |org|
          @org = org
        end
      end
      macpool_list << "#{@org}"
      macpool_list << "#{macpool.attributes["id"]}"
      extracted_service_profile_names = "#{macpool.attributes["assignedToDn"]}"
      service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
      service_profile_names.each do |service_profile_name| #Ugly...refactor
      hostnames = service_profile_name
      hostnames.each do |host_name|
            @host = host_name
          end
      end
      vnics = extracted_service_profile_names.to_s.scan(/ether-vNIC-(\w+)/)
      vnics.each do |vnic| #Ugly...refactor
        assgined_vnics = vnic
        assgined_vnics.each do |vnic|
          @vnic = vnic
        end
      end
      macpool_list << "#{@host}"
      macpool_list << "#{@vnic}"
      macpool_list << begin
        state = "#{macpool.attributes["assigned"]}"
        case state
        when 'yes'
           ui.color(state, :green)
        when 'assigning'
           ui.color(state, :yellow)
        else
           ui.color(state, :red)
        end
      end
    end
    puts ui.list(macpool_list, :uneven_columns_across, 5)
  else
    puts "Incorrect options. Please make sure you are using one of the following: mac,uuid,wwpn"        
  end       
end