Class: Chef::Knife::UcsTemplateCreate

Inherits:
Chef::Knife show all
Includes:
UCSBase
Defined in:
lib/chef/knife/ucs_template_create.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.



37
38
39
# File 'lib/chef/knife/ucs_template_create.rb', line 37

def initial_sleep_delay
  @initial_sleep_delay
end

Instance Method Details

#runObject



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
# File 'lib/chef/knife/ucs_template_create.rb', line 84

def run
  $stdout.sync = true
  
  template_type = "#{Chef::Config[:knife][:template]}".downcase
  case template_type
  when 'vnic'
  
    json = { :vnic_template_name => Chef::Config[:knife][:name], :vnic_template_mac_pool => Chef::Config[:knife][:pool],
             :switch => Chef::Config[:knife][:fabric], :org => Chef::Config[:knife][:org], :vnic_template_VLANs => Chef::Config[:knife][:vlans],
             :vnic_template_native_VLAN => Chef::Config[:knife][:native], :vnic_template_mtu => Chef::Config[:knife][:mtu] }.to_json
    
    xml_response = provisioner.set_vnic_template(json)
    xml_doc = Nokogiri::XML(xml_response)

    xml_doc.xpath("configConfMos/outConfigs/pair/vnicLanConnTempl").each do |vnic|
        puts ''
        puts "vNIC Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" + 
              " Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
    end        

    #Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
    xml_doc.xpath("configConfMos").each do |vnic|
       puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
    end          

  when 'vhba'
  
    json = { :vbha_template_name => Chef::Config[:knife][:name], :wwpn_pool => Chef::Config[:knife][:pool],
             :switch => Chef::Config[:knife][:fabric], :vsan_name => Chef::Config[:knife][:vsan], :org => Chef::Config[:knife][:org] }.to_json       
         		
         		
    #puts provisioner.set_vhba_template(json)
    xml_response = provisioner.set_vhba_template(json)
    xml_doc = Nokogiri::XML(xml_response)
    
    xml_doc.xpath("configConfMos/outConfigs/pair/vnicSanConnTempl").each do |vnic|
        puts ''
        puts "vHBA Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" + 
              " Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
    end        
    
    #Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
    xml_doc.xpath("configConfMos").each do |vnic|
       puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
    end

  when 'serviceprofile'
  
    json = { :service_profile_template_name => Chef::Config[:knife][:name], :service_profile_template_boot_policy => Chef::Config[:knife][:bootpolicy],
             :service_profile_template_host_fw_policy => Chef::Config[:knife][:hostfwpolicy], :service_profile_template_mgmt_fw_policy => Chef::Config[:knife][:mgmtfwpolicy], 
             :org => Chef::Config[:knife][:org] }.to_json       
             # 
             # service_profile_template_name               = JSON.parse(json)['service_profile_template_name']
             # service_profile_template_boot_policy        = JSON.parse(json)['service_profile_template_boot_policy']
             # service_profile_template_host_fw_policy     = JSON.parse(json)['service_profile_template_host_fw_policy']
             # service_profile_template_mgmt_fw_policy     = JSON.parse(json)['service_profile_template_mgmt_fw_policy']
             # service_profile_template_uuid_pool          = JSON.parse(json)['service_profile_template_uuid_pool']
             # service_profile_template_vnics_a            = JSON.parse(json)['service_profile_template_vnics_a'].split(',')
             # service_profile_template_vnic_a_template    = JSON.parse(json)['service_profile_template_vnic_a_template']
             # service_profile_template_vnics_b            = JSON.parse(json)['service_profile_template_vnics_b'].split(',')
             # service_profile_template_vnic_b_template    = JSON.parse(json)['service_profile_template_vnic_b_template'].to_s
             # service_profile_template_wwnn_pool          = JSON.parse(json)['service_profile_template_wwnn_pool'].to_s
             # service_profile_template_vhba_a             = JSON.parse(json)['service_profile_template_vhba_a']
             # service_profile_template_vhba_a_template    = JSON.parse(json)['service_profile_template_vhba_a_template']
             # service_profile_template_vhba_b             = JSON.parse(json)['service_profile_template_vhba_b'].to_s
             # service_profile_template_vhba_b_template    = JSON.parse(json)['service_profile_template_vhba_b_template'].to_s
             # org                                         = JSON.parse(json)['org'].to_s
             #                    
         		
    #puts provisioner.set_vhba_template(json)
    xml_response = provisioner.set_vhba_template(json)
    xml_doc = Nokogiri::XML(xml_response)
    
    xml_doc.xpath("configConfMos/outConfigs/pair/vnicSanConnTempl").each do |vnic|
        puts ''
        puts "vHBA Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" + 
              " Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
    end        
    
    #Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
    xml_doc.xpath("configConfMos").each do |vnic|
       puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
    end          
  else
    "Incorrect options. Please make sure you are using one of the following: vnic,vhba,serviceprofile"
  end
  
end