Permalink
Browse files

Merge pull request #14 from cdearborn/pull-req-master-d48a3171fc

Indigo support: Switch config json generation [1/5]
  • Loading branch information...
2 parents 70d70b3 + d48a317 commit afb2b77ed89db736401097df8f442ea20ea1f802 @galthaus galthaus committed Apr 13, 2012
@@ -0,0 +1,101 @@
+# Copyright 2012, Dell
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+def setup_interface(unique_vlans, interfaces, a_node, conduit, interface_id )
+ a_node["crowbar"]["network"].each do |network_name, network|
+ next if network["conduit"] != conduit
+ vlan = network["vlan"]
+ unique_vlans[vlan] = ""
+
+ interfaces[interface_id] = {} if interfaces[interface_id].nil?
+ vlans_for_interface = interfaces[interface_id]
+ vlans_for_interface[vlan] = network["use_vlan"]
+ end
+end
+
+admin_ip = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address
+
+unique_vlans={}
+interfaces = {}
+next_lag_id=1
+lags = {}
+
+search(:node, "*:*").each do |a_node|
+ node_map = Chef::Recipe::Barclamp::Inventory.build_node_map(a_node)
+
+ node_map.each do |conduit, conduit_info|
+ if_list = conduit_info["if_list"]
+ team_mode = conduit_info["team_mode"] rescue nil
+
+ interface_id=""
+ if if_list.size > 1 && team_mode != 5 && team_mode != 6
+
+ lag_ports = []
+ found_lag_port = false
+
+ if_list.each do |intf|
+ switch_unit=a_node["crowbar_ohai"]["switch_config"][intf]["switch_unit"]
+ switch_port=a_node["crowbar_ohai"]["switch_config"][intf]["switch_port"]
+ next if switch_unit == -1
+
+ found_lag_port = true
+ lag_ports << "#{switch_unit}/0/#{switch_port}"
+ end
+
+ # Only create the LAG if at least one interface is connected to the switch
+ if found_lag_port
+ lag_ports.sort!
+
+ lag_id = next_lag_id
+ next_lag_id += 1
+
+ lag = {}
+ lag["lag_id"] = lag_id
+ lag["ports"] = lag_ports
+
+ lags[lag_id] = lag
+
+ setup_interface(unique_vlans, interfaces, a_node, conduit, lag_id.to_s )
+ end
+ else
+ if_list.each do |intf|
+ switch_unit=a_node["crowbar_ohai"]["switch_config"][intf]["switch_unit"]
+ switch_port=a_node["crowbar_ohai"]["switch_config"][intf]["switch_port"]
+ next if switch_unit == -1
+
+ setup_interface(unique_vlans, interfaces, a_node, conduit, "#{switch_unit}/0/#{switch_port}" )
+ end
+ end
+ end
+end
+
+directory "/opt/dell/switch" do
+ mode 0755
+ owner "root"
+ group "root"
+end
+
+template "/opt/dell/switch/switch_config.json" do
+ mode 0644
+ owner "root"
+ group "root"
+ source "switch_config.erb"
+ variables(
+ :admin_node_ip => admin_ip,
+ :unique_vlans => unique_vlans.keys.sort,
+ :lags => lags,
+ :interfaces => interfaces
+ )
+end
@@ -0,0 +1,56 @@
+{
+ "sysloginfo": [
+ {
+ "loglevel":"WARN",
+ "logservers":[
+ {
+ "serverip":"<%= @admin_node_ip %>",
+ "port_num":514,
+ "description":"Crowbar admin node"
+ }
+ ]
+ }
+ ],
+
+ "vlans": [
+ <% @unique_vlans.each do | vlan| %>
+ {
+ "vlan_name": "vlan<%= vlan %>",
+ "vlan_id": <%= vlan %>
+ }<%= "," if vlan != @unique_vlans.last %>
+ <% end %>
+ ],
+
+ "LAGs": [
+ <% lag_ids = @lags.keys.sort %>
+ <% lag_ids.each do |lag_id| %>
+ {
+ "lag_id": <%= lag_id %>,
+ "ports": [
+ <% ports = @lags[lag_id]["ports"] %>
+ <% ports.each do |port_key| %>
+ { "port_id": "<%= port_key %>" }<%= "," if port_key != ports.last %>
+ <% end %>
+ ]
+ }<%= "," if lag_id != lag_ids.last %>
+ <% end %>
+ ],
+
+ "interfaces": [
+ <% interface_ids = @interfaces.keys.sort %>
+ <% interface_ids.each do |interface_id| %>
+ {
+ "id": "<%= interface_id %>",
+ "vlans": [
+ <% vlans = @interfaces[interface_id].keys.sort %>
+ <% vlans.each do |vlan| %>
+ {
+ "vlan_name": "vlan<%= vlan %>",
+ "vlan_mode": "<%= @interfaces[interface_id][vlan] ? "TAGGED" : "UNTAGGED" %>"
+ }<%= "," if vlan != vlans.last %>
+ <% end %>
+ ]
+ }<%= "," if interface_id != interface_ids.last %>
+ <% end %>
+ ]
+}
@@ -0,0 +1,7 @@
+
+name "switch_config"
+description "Switch configuration - Generates switch configuration"
+run_list("recipe[network::switch_config]")
+default_attributes()
+override_attributes()
+
@@ -218,8 +218,13 @@ def transition(inst, name, state)
@logger.debug("Network transition: Entering #{name} for #{state}")
if state == "discovered"
+
db = ProposalObject.find_proposal "network", inst
role = RoleObject.find_role_by_name "network-config-#{inst}"
+ if NodeObject.find_node_by_name(name)["crowbar"]["admin_node"]
+ @logger.error("Admin node transitioning to discovered state. Adding switch_config role.")
+ result = add_role_to_instance_and_node("network", inst, name, db, role, "switch_config")
+ end
@logger.debug("Network transition: make sure that network role is on all nodes: #{name} for #{state}")
result = add_role_to_instance_and_node("network", inst, name, db, role, "network")

0 comments on commit afb2b77

Please sign in to comment.