Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit 164454e

Browse files
committed
Clean up and changing laying layout to leverage modules
1 parent bf998c3 commit 164454e

15 files changed

+318
-259
lines changed

.rvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rvm use ruby-2.1.0@ucslib --create

lib/ucslib.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
# limitations under the License.
1616
#
1717

18+
19+
1820
require "ucslib/version"
19-
require "ucslib/session"
20-
require "ucslib/provision"
21-
require "ucslib/parser"
22-
require "ucslib/update"
23-
require "ucslib/inventory"
24-
require 'ucslib/destroy'
25-
require 'ucslib/manage'
26-
require 'ucslib/stats'
21+
require "ucslib/service/ucs/ucs"
22+
# require "ucslib/service/ucs/session"
23+
# require "ucslib/service/ucs/provision"
24+
# require "ucslib/service/ucs/parser"
25+
# require "ucslib/service/ucs/update"
26+
# require "ucslib/service/ucs/inventory"
27+
# require 'ucslib/service/ucs/destroy'
28+
# require 'ucslib/service/ucs/manage'
29+
# require 'ucslib/service/ucs/stats'
2730

2831
require 'nokogiri'
2932
require 'rest-client'

lib/ucslib/Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A sample Gemfile
2+
source "https://rubygems.org"
3+
4+
# gem "rails"

lib/ucslib/destroy.rb lib/ucslib/service/ucs/destroy.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# limitations under the License.
1616
#
1717

18-
class UCSDestroy
18+
module Destroy
1919

2020
def initialize(tokenjson)
21-
21+
2222
@cookie = "#{JSON.parse(tokenjson)['cookie']}"
2323
ip = "#{JSON.parse(tokenjson)['ip']}"
2424
@url = "https://#{ip}/nuova"
@@ -49,7 +49,7 @@ def delete_org(json)
4949
rescue Exception => e
5050
raise "Error #{e}"
5151
end
52-
52+
5353
end
5454

5555
def delete_vlan(json)
@@ -78,6 +78,6 @@ def delete_vlan(json)
7878
raise "Error #{e}"
7979
end
8080

81-
end
81+
end
8282

8383
end

lib/ucslib/inventory.rb lib/ucslib/service/ucs/inventory.rb

+27-27
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#
1717

1818

19-
class UCSInventory
20-
19+
module Inventory
20+
2121
def discover(tokenjson)
22-
23-
cookie = "#{JSON.parse(tokenjson)['cookie']}"
22+
23+
cookie = "#{JSON.parse(tokenjson)['cookie']}"
2424
ip = "#{JSON.parse(tokenjson)['ip']}"
25-
url = "https://#{ip}/nuova"
25+
url = "https://#{ip}/nuova"
2626

2727
#Start Build the Multi-Class XML
2828
xml_builder = Nokogiri::XML::Builder.new do |xml|
@@ -69,7 +69,7 @@ def discover(tokenjson)
6969
xml.classId("value" => "vmVnicProfCl")
7070
xml.classId("value" => "vmVnicProfInst")
7171
xml.classId("value" => "vmVsan")
72-
}
72+
}
7373
}
7474
end
7575

@@ -80,45 +80,45 @@ def discover(tokenjson)
8080

8181
#Uncomment the following to create a dump to review and debug elements
8282
# fh = File.new("ucs_response_multiclass.xml", "w")
83-
# fh.puts ucs_response_multi_class.inspect
83+
# fh.puts ucs_response_multi_class.inspect
8484
# fh.close
85-
85+
8686
return Nokogiri::XML(ucs_response_multi_class)
87-
87+
8888
end
89-
90-
89+
90+
9191
def list_blades(ucs_multi_class_xml)
92-
92+
9393
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/computeBlade").each do |blade|
94-
94+
9595
puts "Blade : #{blade.attributes["serverId"]} model: #{blade.attributes["model"]}" \
9696
" with serial: #{blade.attributes["serial"]} is powered: #{blade.attributes["operPower"]}"
97-
97+
9898
end
99-
99+
100100
end
101-
101+
102102
def list_vsans(ucs_multi_class_xml)
103103

104104
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/fabricVsan").each do |fabricvsan|
105-
105+
106106
puts "VSAN: #{fabricvsan.attributes["fcoeVlan"]} with FCoE ID: #{fabricvsan.attributes["id"]}" \
107107
" status: #{fabricvsan.attributes["operState"]}"
108108
end
109109

110110
end
111-
111+
112112
def list_vlans(ucs_multi_class_xml)
113113

114114
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/fabricVlan").each do |fabricvlan|
115115

116116
puts "VLAN: #{fabricvlan.attributes["id"]} with name: #{fabricvlan.attributes["name"]}"
117117

118118
end
119-
119+
120120
end
121-
121+
122122
def list_cpus(ucs_multi_class_xml)
123123

124124
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/processorUnit").each do |processorunit|
@@ -130,28 +130,28 @@ def list_cpus(ucs_multi_class_xml)
130130
end
131131

132132
end
133-
133+
134134
def list_memory(ucs_multi_class_xml)
135135

136136
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/computeBlade").each do |blade|
137137

138138
puts "Available Memory: #{blade.attributes["availableMemory"]} Total Memory: #{blade.attributes["totalMemory"]} Speed: #{blade.attributes["memorySpeed"]}"
139139

140140
end
141-
141+
142142
end
143-
143+
144144
def list_service_profiles(ucs_multi_class_xml)
145-
145+
146146
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/lsServer").each do |serviceprofile|
147147

148148
puts "Service Profile: #{serviceprofile.attributes["name"]} in #{serviceprofile.attributes["dn"]} with UUID #{serviceprofile.attributes["uuid"]}" \
149149
" is: #{serviceprofile.attributes["assocState"]}"
150150

151151
end
152-
152+
153153
end
154-
154+
155155
def list_running_firmware(ucs_multi_class_xml)
156156

157157
ucs_multi_class_xml.xpath("configResolveClasses/outConfigs/firmwareRunning").each do |firmware|
@@ -162,5 +162,5 @@ def list_running_firmware(ucs_multi_class_xml)
162162
end
163163

164164
end
165-
165+
166166
end

lib/ucslib/manage.rb lib/ucslib/service/ucs/manage.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@
1515
# limitations under the License.
1616
#
1717

18-
class UCSManage
18+
module Manage
1919

2020
def initialize(tokenjson)
2121

22-
@cookie = "#{JSON.parse(tokenjson)['cookie']}"
23-
ip = "#{JSON.parse(tokenjson)['ip']}"
24-
@url = "https://#{ip}/nuova"
22+
@cookie = "#{JSON.parse(tokenjson)['cookie']}"
23+
ip = "#{JSON.parse(tokenjson)['ip']}"
24+
@url = "https://#{ip}/nuova"
2525

2626
end
2727

2828

2929
def discover_state
30-
30+
3131
#Start Build of the Multi-Class XML for interogating state
3232
xml_builder = Nokogiri::XML::Builder.new do |xml|
3333
xml.configResolveClasses('cookie' => @cookie, 'inHierarchical' => 'false') {
3434
xml.inIds{
3535
xml.classId("value" => "macpoolPooled")
3636
xml.classId("value" => "uuidpoolPooled")
3737
xml.classId("value" => "fcpoolInitiator")
38-
}
38+
}
3939
}
4040
end
4141

@@ -46,13 +46,13 @@ def discover_state
4646

4747
#Uncomment the following to create a dump to review and debug elements
4848
# fh = File.new("ucs_response_multiclass_state.xml", "w")
49-
# fh.puts ucs_response_multi_class_state.inspect
49+
# fh.puts ucs_response_multi_class_state.inspect
5050
# fh.close
51-
52-
Nokogiri::XML(ucs_response_multi_class_state)
53-
51+
52+
Nokogiri::XML(ucs_response_multi_class_state)
53+
5454
end
55-
55+
5656

5757
def associate_service_profile_template_to_server_pool(json)
5858

@@ -73,8 +73,8 @@ def associate_service_profile_template_to_server_pool(json)
7373
'descr' => '', 'dn' => "org-root/org-#{org}/ls-#{service_profile_template_to_bind}",
7474
'dynamicConPolicyName' => '', 'extIPState' => 'none', 'hostFwPolicyName' => "#{service_profile_host_fw_policy}",
7575
'identPoolName' => "#{service_profile_uuid_pool}", 'localDiskPolicyName' => 'default', 'maintPolicyName' => 'default',
76-
'mgmtAccessPolicyName' => '', 'mgmtFwPolicyName' => "#{service_profile_mgmt_fw_policy}", 'powerPolicyName' => 'default',
77-
'scrubPolicyName' => '', 'solPolicyName' => 'default', 'srcTemplName' => '',
76+
'mgmtAccessPolicyName' => '', 'mgmtFwPolicyName' => "#{service_profile_mgmt_fw_policy}", 'powerPolicyName' => 'default',
77+
'scrubPolicyName' => '', 'solPolicyName' => 'default', 'srcTemplName' => '',
7878
'statsPolicyName' => 'default', 'status' => 'created,modified', 'usrLbl' => '', 'uuid' => '0', 'vconProfileName' => ''){
7979
xml.lsRequirement('name' => "#{service_profile_server_pool}", 'qualifier' => '', 'restrictMigration' => 'no', 'rn' => 'pn-req')
8080
}
@@ -87,13 +87,13 @@ def associate_service_profile_template_to_server_pool(json)
8787

8888
associate_service_profile_template_to_server_pool_xml = xml_builder.to_xml.to_s
8989

90-
#Post
90+
#Post
9191
begin
9292
RestClient.post(@url, associate_service_profile_template_to_server_pool_xml, :content_type => 'text/xml').body
9393
rescue Exception => e
9494
raise "Error #{e}"
95-
end
96-
95+
end
96+
9797
end
98-
98+
9999
end

lib/ucslib/parser.rb lib/ucslib/service/ucs/parser.rb

+19-19
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
# limitations under the License.
1616
#
1717

18-
# require 'nokogiri'
19-
#
20-
# class UCSParser
21-
# class Nokogiri::XML::Node
22-
# TYPENAMES = {1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}
23-
# def to_hash
24-
# {kind:TYPENAMES[node_type],name:name}.tap do |h|
25-
# h.merge! nshref:namespace.href, nsprefix:namespace.prefix if namespace
26-
# h.merge! text:text
27-
# h.merge! attr:attribute_nodes.map(&:to_hash) if element?
28-
# h.merge! kids:children.map(&:to_hash) if element?
29-
# end
30-
# end
31-
# end
32-
# class Nokogiri::XML::Document
33-
# def to_hash; root.to_hash; end
34-
# end
35-
#
36-
# end
18+
require 'nokogiri'
19+
20+
module Parser
21+
class Nokogiri::XML::Node
22+
TYPENAMES = {1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}
23+
def to_hash
24+
{kind:TYPENAMES[node_type],name:name}.tap do |h|
25+
h.merge! nshref:namespace.href, nsprefix:namespace.prefix if namespace
26+
h.merge! text:text
27+
h.merge! attr:attribute_nodes.map(&:to_hash) if element?
28+
h.merge! kids:children.map(&:to_hash) if element?
29+
end
30+
end
31+
end
32+
class Nokogiri::XML::Document
33+
def to_hash; root.to_hash; end
34+
end
35+
36+
end

0 commit comments

Comments
 (0)