knife-ucs 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -3
- data/configs/hosfw.json +18 -0
- data/knife-ucs.gemspec +5 -4
- data/lib/chef/knife/ucs_base.rb +12 -0
- data/lib/chef/knife/ucs_blades_list.rb +2 -0
- data/lib/chef/knife/ucs_cpus_list.rb +2 -0
- data/lib/chef/knife/ucs_org_create.rb +5 -3
- data/lib/chef/knife/ucs_org_delete.rb +3 -1
- data/lib/chef/knife/ucs_orgs_list.rb +2 -0
- data/lib/chef/knife/ucs_policy_create.rb +108 -0
- data/lib/chef/knife/ucs_policy_delete.rb +57 -0
- data/lib/chef/knife/ucs_policy_update.rb +107 -0
- data/lib/chef/knife/ucs_pool_create.rb +21 -27
- data/lib/chef/knife/ucs_pool_delete.rb +3 -1
- data/lib/chef/knife/ucs_pool_list.rb +189 -0
- data/lib/chef/knife/ucs_runningfirmware_list.rb +2 -0
- data/lib/chef/knife/ucs_serviceprofile_create.rb +3 -0
- data/lib/chef/knife/ucs_serviceprofile_delete.rb +3 -1
- data/lib/chef/knife/ucs_serviceprofiles_list.rb +2 -0
- data/lib/chef/knife/ucs_set.rb +75 -12
- data/lib/chef/knife/ucs_template_create.rb +174 -0
- data/lib/chef/knife/ucs_template_delete.rb +59 -0
- data/lib/chef/knife/ucs_vlan_create.rb +8 -6
- data/lib/chef/knife/ucs_vlan_delete.rb +5 -4
- data/lib/chef/knife/ucs_vlans_list.rb +2 -0
- data/lib/chef/knife/ucs_vsans_list.rb +2 -0
- data/lib/knife-ucs/version.rb +1 -1
- metadata +51 -11
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -27,7 +29,7 @@ class Chef
|
|
27
29
|
|
28
30
|
def run
|
29
31
|
|
30
|
-
|
32
|
+
#TBD
|
31
33
|
|
32
34
|
end
|
33
35
|
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
3
|
+
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife/ucs_base'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class UcsPoolList < Knife
|
25
|
+
|
26
|
+
include Knife::UCSBase
|
27
|
+
|
28
|
+
banner "knife ucs pool list (options)"
|
29
|
+
|
30
|
+
attr_accessor :initial_sleep_delay
|
31
|
+
|
32
|
+
option :type,
|
33
|
+
:long => "--pool-type POOLTYPE",
|
34
|
+
:description => "The policy type <mac,uuid,wwpn,wwnn>",
|
35
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:type] = f }
|
36
|
+
|
37
|
+
option :org,
|
38
|
+
:long => "--org ORG",
|
39
|
+
:description => "The organization to use",
|
40
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:org] = f }
|
41
|
+
|
42
|
+
option :name,
|
43
|
+
:long => "--policy-name POLICYNAME",
|
44
|
+
:description => "The policy name to use",
|
45
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:name] = f }
|
46
|
+
|
47
|
+
|
48
|
+
def run
|
49
|
+
$stdout.sync = true
|
50
|
+
|
51
|
+
#Using Chef's UI (much better looking:)) instead of list methods provided by ucslib.
|
52
|
+
pool_type = "#{Chef::Config[:knife][:type]}".downcase
|
53
|
+
case pool_type
|
54
|
+
when 'wwpn'
|
55
|
+
wwpnpool_list = [
|
56
|
+
ui.color('Organization', :bold),
|
57
|
+
ui.color('WWPN', :bold),
|
58
|
+
ui.color('Assigned To', :bold),
|
59
|
+
ui.color('Assigned', :bold)
|
60
|
+
]
|
61
|
+
manager.xpath("configResolveClasses/outConfigs/fcpoolInitiator").each do |wwpnpool|
|
62
|
+
extracted_org_names = "#{wwpnpool.attributes["assignedToDn"]}"
|
63
|
+
org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
|
64
|
+
org_names.each do |orgs| #Ugly...refactor
|
65
|
+
orgs.each do |org|
|
66
|
+
@org = org
|
67
|
+
end
|
68
|
+
end
|
69
|
+
wwpnpool_list << "#{@org}"
|
70
|
+
wwpnpool_list << "#{wwpnpool.attributes["id"]}"
|
71
|
+
extracted_service_profile_names = "#{wwpnpool.attributes["assignedToDn"]}"
|
72
|
+
service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
|
73
|
+
service_profile_names.each do |service_profile_name| #Ugly...refactor
|
74
|
+
hostnames = service_profile_name
|
75
|
+
hostnames.each do |host_name|
|
76
|
+
@host = host_name
|
77
|
+
end
|
78
|
+
end
|
79
|
+
wwpnpool_list << "#{@host}"
|
80
|
+
wwpnpool_list << begin
|
81
|
+
state = "#{wwpnpool.attributes["assigned"]}"
|
82
|
+
case state
|
83
|
+
when 'yes'
|
84
|
+
ui.color(state, :green)
|
85
|
+
when 'assigning'
|
86
|
+
ui.color(state, :yellow)
|
87
|
+
else
|
88
|
+
ui.color(state, :red)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
puts ui.list(wwpnpool_list, :uneven_columns_across, 4)
|
93
|
+
|
94
|
+
when 'uuid'
|
95
|
+
uuidpool_list = [
|
96
|
+
ui.color('Organization', :bold),
|
97
|
+
ui.color('UUID Suffix', :bold),
|
98
|
+
ui.color('Assigned To', :bold),
|
99
|
+
ui.color('Assigned', :bold)
|
100
|
+
]
|
101
|
+
manager.xpath("configResolveClasses/outConfigs/uuidpoolPooled").each do |uuidpool|
|
102
|
+
extracted_org_names = "#{uuidpool.attributes["assignedToDn"]}"
|
103
|
+
org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
|
104
|
+
org_names.each do |orgs| #Ugly...refactor
|
105
|
+
orgs.each do |org|
|
106
|
+
@org = org
|
107
|
+
end
|
108
|
+
end
|
109
|
+
uuidpool_list << "#{@org}"
|
110
|
+
uuidpool_list << "#{uuidpool.attributes["id"]}"
|
111
|
+
extracted_service_profile_names = "#{uuidpool.attributes["assignedToDn"]}"
|
112
|
+
service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
|
113
|
+
service_profile_names.each do |service_profile_name| #Ugly...refactor
|
114
|
+
hostnames = service_profile_name
|
115
|
+
hostnames.each do |host_name|
|
116
|
+
@host = host_name
|
117
|
+
end
|
118
|
+
end
|
119
|
+
uuidpool_list << "#{@host}"
|
120
|
+
uuidpool_list << begin
|
121
|
+
state = "#{uuidpool.attributes["assigned"]}"
|
122
|
+
case state
|
123
|
+
when 'yes'
|
124
|
+
ui.color(state, :green)
|
125
|
+
when 'assigning'
|
126
|
+
ui.color(state, :yellow)
|
127
|
+
else
|
128
|
+
ui.color(state, :red)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
puts ui.list(uuidpool_list, :uneven_columns_across, 4)
|
133
|
+
|
134
|
+
when 'mac'
|
135
|
+
macpool_list = [
|
136
|
+
ui.color('Organization', :bold),
|
137
|
+
ui.color('Mac Address', :bold),
|
138
|
+
ui.color('Assigned To', :bold),
|
139
|
+
ui.color('vNIC', :bold),
|
140
|
+
ui.color('Assigned', :bold)
|
141
|
+
]
|
142
|
+
|
143
|
+
manager.xpath("configResolveClasses/outConfigs/macpoolPooled").each do |macpool|
|
144
|
+
extracted_org_names = "#{macpool.attributes["assignedToDn"]}"
|
145
|
+
org_names = extracted_org_names.to_s.scan(/\/(org-\w+)/)
|
146
|
+
org_names.each do |orgs| #Ugly...refactor
|
147
|
+
orgs.each do |org|
|
148
|
+
@org = org
|
149
|
+
end
|
150
|
+
end
|
151
|
+
macpool_list << "#{@org}"
|
152
|
+
macpool_list << "#{macpool.attributes["id"]}"
|
153
|
+
extracted_service_profile_names = "#{macpool.attributes["assignedToDn"]}"
|
154
|
+
service_profile_names = extracted_service_profile_names.to_s.scan(/ls-(\w+)/)
|
155
|
+
service_profile_names.each do |service_profile_name| #Ugly...refactor
|
156
|
+
hostnames = service_profile_name
|
157
|
+
hostnames.each do |host_name|
|
158
|
+
@host = host_name
|
159
|
+
end
|
160
|
+
end
|
161
|
+
vnics = extracted_service_profile_names.to_s.scan(/ether-vNIC-(\w+)/)
|
162
|
+
vnics.each do |vnic| #Ugly...refactor
|
163
|
+
assgined_vnics = vnic
|
164
|
+
assgined_vnics.each do |vnic|
|
165
|
+
@vnic = vnic
|
166
|
+
end
|
167
|
+
end
|
168
|
+
macpool_list << "#{@host}"
|
169
|
+
macpool_list << "#{@vnic}"
|
170
|
+
macpool_list << begin
|
171
|
+
state = "#{macpool.attributes["assigned"]}"
|
172
|
+
case state
|
173
|
+
when 'yes'
|
174
|
+
ui.color(state, :green)
|
175
|
+
when 'assigning'
|
176
|
+
ui.color(state, :yellow)
|
177
|
+
else
|
178
|
+
ui.color(state, :red)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
puts ui.list(macpool_list, :uneven_columns_across, 5)
|
183
|
+
else
|
184
|
+
puts "Incorrect options. Please make sure you are using one of the following: mac,uuid,wwpn"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -45,6 +47,7 @@ class Chef
|
|
45
47
|
def run
|
46
48
|
$stdout.sync = true
|
47
49
|
|
50
|
+
#TBD
|
48
51
|
|
49
52
|
end
|
50
53
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -27,7 +29,7 @@ class Chef
|
|
27
29
|
|
28
30
|
def run
|
29
31
|
|
30
|
-
|
32
|
+
#TBD
|
31
33
|
|
32
34
|
end
|
33
35
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
data/lib/chef/knife/ucs_set.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
2
3
|
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
3
5
|
# License:: Apache License, Version 2.0
|
4
6
|
#
|
5
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -36,7 +38,7 @@ class Chef
|
|
36
38
|
|
37
39
|
option :config,
|
38
40
|
:long => "--config-item CONFIGIETM",
|
39
|
-
:description => "The item to configure which includes ntp, timezone, power, chassis-discovery",
|
41
|
+
:description => "The item to configure which includes syslog, ntp, timezone, power, chassis-discovery, local-disk-policy",
|
40
42
|
:proc => Proc.new { |f| Chef::Config[:knife][:config] = f }
|
41
43
|
|
42
44
|
option :power,
|
@@ -59,12 +61,55 @@ class Chef
|
|
59
61
|
:description => "The timezone for this UCS Domain",
|
60
62
|
:proc => Proc.new { |f| Chef::Config[:knife][:timezone] = f }
|
61
63
|
|
64
|
+
option :localdiskpolicy,
|
65
|
+
:long => "--local-disk-policy POLICY",
|
66
|
+
:description => "The local disk policy to use: no-local-storage,any-configuration,no-raid,raid-1",
|
67
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:localdiskpolicy] = f }
|
68
|
+
|
69
|
+
|
70
|
+
option :org,
|
71
|
+
:long => "--org ORG",
|
72
|
+
:description => "The organization to use",
|
73
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:org] = f }
|
74
|
+
|
75
|
+
option :syslogserver,
|
76
|
+
:long => "--syslog-server SYSLOGSERVER",
|
77
|
+
:description => "The syslog server to use <hostname or IP>",
|
78
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:syslogserver] = f }
|
79
|
+
|
80
|
+
option :syslogfacility,
|
81
|
+
:long => "--syslog-facility SYSLOGFACILITY",
|
82
|
+
:description => "The syslog facility to use <local0-local7>",
|
83
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:syslogfacility] = f }
|
84
|
+
|
85
|
+
option :syslogseverity,
|
86
|
+
:long => "--syslog-severity SYSLOGSEVERITY",
|
87
|
+
:description => "The syslog severity level to use <debugging,emergencies,information,alerts,warnings,errors,critical>",
|
88
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:syslogseverity] = f }
|
62
89
|
|
63
90
|
def run
|
64
91
|
$stdout.sync = true
|
65
92
|
|
66
|
-
config_item = "#{Chef::Config[:knife][:config]}"
|
93
|
+
config_item = "#{Chef::Config[:knife][:config]}".downcase
|
67
94
|
case config_item
|
95
|
+
when 'syslog'
|
96
|
+
json = { :syslog_server => Chef::Config[:knife][:syslogserver],
|
97
|
+
:facility => Chef::Config[:knife][:syslogfacility],
|
98
|
+
:severity => Chef::Config[:knife][:syslogseverity] }.to_json
|
99
|
+
|
100
|
+
xml_response = provisioner.set_syslog_server(json)
|
101
|
+
xml_doc = Nokogiri::XML(xml_response)
|
102
|
+
|
103
|
+
xml_doc.xpath("configConfMos/outConfigs/pair/commSyslogClient").each do |syslog|
|
104
|
+
puts ''
|
105
|
+
puts "Syslog Server: #{ui.color("#{syslog.attributes['hostname']}", :blue)} status: #{ui.color("#{syslog.attributes['status']}", :green)}"
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
xml_doc.xpath("configConfMos").each do |syslog|
|
110
|
+
puts "#{syslog.attributes['errorCode']} #{ui.color("#{syslog.attributes['errorDescr']}", :red)}"
|
111
|
+
end
|
112
|
+
|
68
113
|
when 'ntp'
|
69
114
|
json = { :ntp_server => Chef::Config[:knife][:ntp] }.to_json
|
70
115
|
|
@@ -73,10 +118,10 @@ class Chef
|
|
73
118
|
|
74
119
|
xml_doc.xpath("configConfMos/outConfigs/pair/commNtpProvider").each do |ntp|
|
75
120
|
puts ''
|
76
|
-
puts "NTP Server: #{ui.color("#{ntp.attributes['name']}", :
|
121
|
+
puts "NTP Server: #{ui.color("#{ntp.attributes['name']}", :blue)} status: #{ui.color("#{ntp.attributes['status']}", :green)}"
|
77
122
|
end
|
78
123
|
|
79
|
-
|
124
|
+
|
80
125
|
xml_doc.xpath("configConfMos").each do |ntp|
|
81
126
|
puts "#{ntp.attributes['errorCode']} #{ui.color("#{ntp.attributes['errorDescr']}", :red)}"
|
82
127
|
end
|
@@ -89,10 +134,10 @@ class Chef
|
|
89
134
|
|
90
135
|
xml_doc.xpath("configConfMos/outConfigs/pair/computePsuPolicy").each do |power|
|
91
136
|
puts ''
|
92
|
-
puts "Power Policy: #{ui.color("#{power.attributes['name']}", :
|
137
|
+
puts "Power Policy: #{ui.color("#{power.attributes['name']}", :blue)} status: #{ui.color("#{power.attributes['status']}", :green)}"
|
93
138
|
end
|
94
139
|
|
95
|
-
|
140
|
+
|
96
141
|
xml_doc.xpath("configConfMos").each do |power|
|
97
142
|
puts "#{power.attributes['errorCode']} #{ui.color("#{power.attributes['errorDescr']}", :red)}"
|
98
143
|
end
|
@@ -105,10 +150,10 @@ class Chef
|
|
105
150
|
|
106
151
|
xml_doc.xpath("configConfMos/outConfigs/pair/computeChassisDiscPolicy").each do |chassis|
|
107
152
|
puts ''
|
108
|
-
puts "Chassis Discovery Policy: #{ui.color("#{chassis.attributes['action']}", :
|
153
|
+
puts "Chassis Discovery Policy: #{ui.color("#{chassis.attributes['action']}", :blue)} status: #{ui.color("#{chassis.attributes['status']}", :green)}"
|
109
154
|
end
|
110
155
|
|
111
|
-
|
156
|
+
|
112
157
|
xml_doc.xpath("configConfMos").each do |chassis|
|
113
158
|
puts "#{chassis.attributes['errorCode']} #{ui.color("#{chassis.attributes['errorDescr']}", :red)}"
|
114
159
|
end
|
@@ -121,19 +166,37 @@ class Chef
|
|
121
166
|
|
122
167
|
xml_doc.xpath("configConfMos/outConfigs/pair/commDateTime").each do |timezone|
|
123
168
|
puts ''
|
124
|
-
puts "Timezone: #{ui.color("#{timezone.attributes['timezone']}", :
|
169
|
+
puts "Timezone: #{ui.color("#{timezone.attributes['timezone']}", :blue)} status: #{ui.color("#{timezone.attributes['status']}", :green)}"
|
125
170
|
end
|
126
171
|
|
127
|
-
|
172
|
+
|
128
173
|
xml_doc.xpath("configConfMos").each do |timezone|
|
129
174
|
puts "#{timezone.attributes['errorCode']} #{ui.color("#{timezone.attributes['errorDescr']}", :red)}"
|
130
175
|
end
|
176
|
+
|
177
|
+
when 'local-disk-policy'
|
178
|
+
json = { :local_disk_policy => Chef::Config[:knife][:localdiskpolicy], :org => Chef::Config[:knife][:org] }.to_json
|
179
|
+
|
180
|
+
|
181
|
+
xml_response = provisioner.set_local_disk_policy(json)
|
182
|
+
xml_doc = Nokogiri::XML(xml_response)
|
183
|
+
|
184
|
+
xml_doc.xpath("configConfMos/outConfigs/pair/storageLocalDiskConfigPolicy").each do |localdiskpolicy|
|
185
|
+
puts ''
|
186
|
+
puts "Local Disk Policy: #{ui.color("#{localdiskpolicy.attributes['mode']}", :blue)} status: #{ui.color("#{localdiskpolicy.attributes['status']}", :green)}"
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
xml_doc.xpath("configConfMos").each do |localdiskpolicy|
|
191
|
+
puts "#{localdiskpolicy.attributes['errorCode']} #{ui.color("#{localdiskpolicy.attributes['errorDescr']}", :red)}"
|
192
|
+
end
|
193
|
+
|
194
|
+
|
131
195
|
else
|
132
196
|
puts ''
|
133
|
-
puts "Incorrect options.
|
197
|
+
puts "Incorrect options. Type --help to list options"
|
134
198
|
puts ''
|
135
199
|
end
|
136
|
-
|
137
200
|
end
|
138
201
|
end
|
139
202
|
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Author:: Murali Raju (<murali.raju@appliv.com>)
|
2
|
+
# Author:: Velankani Engineering <eng@velankani.net>
|
3
|
+
# Copyright:: Copyright (c) 2012 Murali Raju.
|
4
|
+
# Copyright:: Copyright (c) 2012 Velankani Information Systems, Inc
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife/ucs_base'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class UcsTemplateCreate < Knife
|
25
|
+
|
26
|
+
include Knife::UCSBase
|
27
|
+
|
28
|
+
deps do
|
29
|
+
require 'readline'
|
30
|
+
require 'chef/json_compat'
|
31
|
+
require 'chef/knife/bootstrap'
|
32
|
+
Chef::Knife::Bootstrap.load_deps
|
33
|
+
end
|
34
|
+
|
35
|
+
banner "knife ucs template create (options)"
|
36
|
+
|
37
|
+
attr_accessor :initial_sleep_delay
|
38
|
+
|
39
|
+
option :template,
|
40
|
+
:long => "--template-type TEMPLATE",
|
41
|
+
:description => "The template type <vnic,vhba,serviceprofile>",
|
42
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:template] = f }
|
43
|
+
|
44
|
+
option :name,
|
45
|
+
:long => "--template-name TEMPLATENAME",
|
46
|
+
:description => "The template name",
|
47
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:name] = f }
|
48
|
+
|
49
|
+
option :pool,
|
50
|
+
:long => "--pool-name POOLNAME",
|
51
|
+
:description => "The pool name to use for this template <macpool, wwnnpool, wwpnpool>",
|
52
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:pool] = f }
|
53
|
+
|
54
|
+
option :fabric,
|
55
|
+
:long => "--fabric FABRIC",
|
56
|
+
:description => "Fabric: A or B switch",
|
57
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:fabric] = f }
|
58
|
+
|
59
|
+
option :org,
|
60
|
+
:long => "--org ORG",
|
61
|
+
:description => "The organization to use",
|
62
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:org] = f }
|
63
|
+
|
64
|
+
option :vlans,
|
65
|
+
:long => "--vlans VLANS",
|
66
|
+
:description => "The vlans IDs to use separated by commas <vlan1,vlan2,vlan3>",
|
67
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:vlans] = f }
|
68
|
+
|
69
|
+
option :vsan,
|
70
|
+
:long => "--vsan-name VSAN",
|
71
|
+
:description => "The vsan name to use",
|
72
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:vsan] = f }
|
73
|
+
|
74
|
+
option :native,
|
75
|
+
:long => "--native-vlan VLAN",
|
76
|
+
:description => "The native vlan name",
|
77
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:native] = f }
|
78
|
+
|
79
|
+
option :mtu,
|
80
|
+
:long => "--mtu MTU",
|
81
|
+
:description => "The MTU value",
|
82
|
+
:proc => Proc.new { |f| Chef::Config[:knife][:mtu] = f }
|
83
|
+
|
84
|
+
def run
|
85
|
+
$stdout.sync = true
|
86
|
+
|
87
|
+
template_type = "#{Chef::Config[:knife][:template]}".downcase
|
88
|
+
case template_type
|
89
|
+
when 'vnic'
|
90
|
+
|
91
|
+
json = { :vnic_template_name => Chef::Config[:knife][:name], :vnic_template_mac_pool => Chef::Config[:knife][:pool],
|
92
|
+
:switch => Chef::Config[:knife][:fabric], :org => Chef::Config[:knife][:org], :vnic_template_VLANs => Chef::Config[:knife][:vlans],
|
93
|
+
:vnic_template_native_VLAN => Chef::Config[:knife][:native], :vnic_template_mtu => Chef::Config[:knife][:mtu] }.to_json
|
94
|
+
|
95
|
+
xml_response = provisioner.set_vnic_template(json)
|
96
|
+
xml_doc = Nokogiri::XML(xml_response)
|
97
|
+
|
98
|
+
xml_doc.xpath("configConfMos/outConfigs/pair/vnicLanConnTempl").each do |vnic|
|
99
|
+
puts ''
|
100
|
+
puts "vNIC Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" +
|
101
|
+
" Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
|
102
|
+
end
|
103
|
+
|
104
|
+
#Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
|
105
|
+
xml_doc.xpath("configConfMos").each do |vnic|
|
106
|
+
puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
|
107
|
+
end
|
108
|
+
|
109
|
+
when 'vhba'
|
110
|
+
|
111
|
+
json = { :vbha_template_name => Chef::Config[:knife][:name], :wwpn_pool => Chef::Config[:knife][:pool],
|
112
|
+
:switch => Chef::Config[:knife][:fabric], :vsan_name => Chef::Config[:knife][:vsan], :org => Chef::Config[:knife][:org] }.to_json
|
113
|
+
|
114
|
+
|
115
|
+
#puts provisioner.set_vhba_template(json)
|
116
|
+
xml_response = provisioner.set_vhba_template(json)
|
117
|
+
xml_doc = Nokogiri::XML(xml_response)
|
118
|
+
|
119
|
+
xml_doc.xpath("configConfMos/outConfigs/pair/vnicSanConnTempl").each do |vnic|
|
120
|
+
puts ''
|
121
|
+
puts "vHBA Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" +
|
122
|
+
" Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
|
123
|
+
end
|
124
|
+
|
125
|
+
#Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
|
126
|
+
xml_doc.xpath("configConfMos").each do |vnic|
|
127
|
+
puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
|
128
|
+
end
|
129
|
+
|
130
|
+
when 'serviceprofile'
|
131
|
+
|
132
|
+
json = { :service_profile_template_name => Chef::Config[:knife][:name], :service_profile_template_boot_policy => Chef::Config[:knife][:bootpolicy],
|
133
|
+
:service_profile_template_host_fw_policy => Chef::Config[:knife][:hostfwpolicy], :service_profile_template_mgmt_fw_policy => Chef::Config[:knife][:mgmtfwpolicy],
|
134
|
+
:org => Chef::Config[:knife][:org] }.to_json
|
135
|
+
#
|
136
|
+
# service_profile_template_name = JSON.parse(json)['service_profile_template_name']
|
137
|
+
# service_profile_template_boot_policy = JSON.parse(json)['service_profile_template_boot_policy']
|
138
|
+
# service_profile_template_host_fw_policy = JSON.parse(json)['service_profile_template_host_fw_policy']
|
139
|
+
# service_profile_template_mgmt_fw_policy = JSON.parse(json)['service_profile_template_mgmt_fw_policy']
|
140
|
+
# service_profile_template_uuid_pool = JSON.parse(json)['service_profile_template_uuid_pool']
|
141
|
+
# service_profile_template_vnics_a = JSON.parse(json)['service_profile_template_vnics_a'].split(',')
|
142
|
+
# service_profile_template_vnic_a_template = JSON.parse(json)['service_profile_template_vnic_a_template']
|
143
|
+
# service_profile_template_vnics_b = JSON.parse(json)['service_profile_template_vnics_b'].split(',')
|
144
|
+
# service_profile_template_vnic_b_template = JSON.parse(json)['service_profile_template_vnic_b_template'].to_s
|
145
|
+
# service_profile_template_wwnn_pool = JSON.parse(json)['service_profile_template_wwnn_pool'].to_s
|
146
|
+
# service_profile_template_vhba_a = JSON.parse(json)['service_profile_template_vhba_a']
|
147
|
+
# service_profile_template_vhba_a_template = JSON.parse(json)['service_profile_template_vhba_a_template']
|
148
|
+
# service_profile_template_vhba_b = JSON.parse(json)['service_profile_template_vhba_b'].to_s
|
149
|
+
# service_profile_template_vhba_b_template = JSON.parse(json)['service_profile_template_vhba_b_template'].to_s
|
150
|
+
# org = JSON.parse(json)['org'].to_s
|
151
|
+
#
|
152
|
+
|
153
|
+
#puts provisioner.set_vhba_template(json)
|
154
|
+
xml_response = provisioner.set_vhba_template(json)
|
155
|
+
xml_doc = Nokogiri::XML(xml_response)
|
156
|
+
|
157
|
+
xml_doc.xpath("configConfMos/outConfigs/pair/vnicSanConnTempl").each do |vnic|
|
158
|
+
puts ''
|
159
|
+
puts "vHBA Template: #{ui.color("#{vnic.attributes['name']}", :blue)} Type: #{ui.color("#{vnic.attributes['templType']}", :blue)}" +
|
160
|
+
" Fabric: #{ui.color("#{vnic.attributes['switchId']}", :blue)} status: #{ui.color("#{vnic.attributes['status']}", :green)}"
|
161
|
+
end
|
162
|
+
|
163
|
+
#Ugly...refactor later to parse error with better exception handling. Nokogiri xpath search for elements might be an option
|
164
|
+
xml_doc.xpath("configConfMos").each do |vnic|
|
165
|
+
puts "#{vnic.attributes['errorCode']} #{ui.color("#{vnic.attributes['errorDescr']}", :red)}"
|
166
|
+
end
|
167
|
+
else
|
168
|
+
"Incorrect options. Please make sure you are using one of the following: vnic,vhba,serviceprofile"
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|