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

Commit 406e707

Browse files
committed
refactor and fixes 0.1.8
1 parent 164454e commit 406e707

13 files changed

+225
-280
lines changed

README.md

+78-96
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
## ucslib (beta)
22

3-
Ruby Client Library for Cisco UCS Manager that could be used by DevOps toolchains - Puppet or Chef and other custom tools in order to provide MaaS (Metal-as-a-Service) for installing and running OpenStack, CloudStack or Hadoop, etc on Cisco UCS. ucslib accepts JSON as configuration.
3+
Ruby Client Library for Cisco UCS Manager that could be used for Infrastructure Automation.
44

55
To see an example of how ucslib is being used, checkout the ucs and ucs-solo Chef Cookbooks created by Velankani Information Systems, Inc here - https://github.com/velankanisys/chef-cookbooks
66

77
In addition there is a knife plugin that use ucslib as well - https://github.com/velankanisys/knife-ucs
88

9-
** Version 0.1.7 has been released **
9+
** Version 0.1.8 has been released **
10+
11+
0.1.8
12+
13+
Namespace updates (clean up) and support for ruby 2.1.0
1014

1115
0.1.7
1216
Multi-chassis server pool creation
@@ -36,104 +40,82 @@ Bug fixes.
3640

3741
gem install ucslib
3842

39-
## Usage (example irb session)
43+
## Usage (example pry session)
44+
45+
[1] pry(main)> require 'ucslib'
46+
=> true
47+
[2] pry(main)> authjson = { :username => 'admin', :password => 'admin', :ip => '172.16.192.175' }.to_json
48+
=> "{\"username\":\"admin\",\"password\":\"admin\",\"ip\":\"172.16.192.175\"}"
49+
[3] pry(main)> ucs = UCS.new(authjson)
50+
Your credentials are username: admin password: admin ip: 172.16.192.175 url https://172.16.192.175/nuova
51+
=> #<UCS:0x007fd269d1eb18>
52+
[4] pry(main)> token = ucs.get_token(authjson)
53+
=> "{\"cookie\":\"1398284131/87cdd12e-7cb4-4e0d-b39d-e39a827e3870\",\"username\":\"admin\",\"password\":\"admin\",\"ip\":\"172.16.192.175\"}"
54+
[5] pry(main)> inventory = ucs.discover(token)
55+
56+
Hit q to quit
57+
58+
=> #(Document:0x3fd4a6f99e70 {
59+
name = "document",
60+
children = [
61+
#(Element:0x3fd4a6f9954c {
62+
name = "configResolveClasses",
63+
attributes = [
64+
#(Attr:0x3fd4a6f99254 {
65+
name = "cookie",
66+
value = "1398284407/c298b159-0cee-434a-ae55-c116b8cd19fe"
67+
}),
68+
#(Attr:0x3fd4a6f99240 { name = "response", value = "yes" })],
69+
children = [
70+
#(Text " "),
71+
#(Element:0x3fd4a6fa1b20 {
72+
name = "outConfigs",
73+
children = [
74+
#(Text " "),
75+
#(Element:0x3fd4a6fa10d0 {
76+
name = "topSystem",
77+
attributes = [
78+
#(Attr:0x3fd4a6fa0e3c {
79+
name = "address",
80+
value = "172.16.192.175"
81+
}),
82+
#(Attr:0x3fd4a6fa0e28 {
83+
name = "currentTime",
84+
value = "2014-04-23T20:29:13.906"
85+
}),
86+
#(Attr:0x3fd4a6fa0e14 { name = "descr", value = "" }),
87+
#(Attr:0x3fd4a6fa0e00 { name = "dn", value = "sys" }),
88+
#(Attr:0x3fd4a6fa0dec { name = "ipv6Addr", value = "::" }),
89+
#(Attr:0x3fd4a6fa0dd8 { name = "mode", value = "cluster" }),
90+
#(Attr:0x3fd4a6fa0dc4 {
91+
name = "name",
92+
value = "UCSPE-172-16-192-175"
93+
}),
94+
#(Attr:0x3fd4a6fa0db0 { name = "owner", value = "" }),
95+
#(Attr:0x3fd4a6fa0d9c { name = "site", value = "" }),
96+
#(Attr:0x3fd4a6fa0d88 {
97+
name = "systemUpTime",
98+
value = "00:06:18:58"
99+
[6] pry(main)>ucs.list_blades(inventory)
100+
Blade : 1/1 model: N20-B6620-1 with serial: 3324 is powered: on
101+
Blade : 1/2 model: N20-B6620-1 with serial: 3325 is powered: on
102+
Blade : 1/5 model: UCSB-B200-M3 with serial: 3327 is powered: on
103+
Blade : 1/6 model: N20-B6625-1 with serial: 3328 is powered: on
104+
Blade : 1/3 model: N20-B6620-2 with serial: 3326 is powered: on
105+
Blade : 1/7 model: N20-B6740-2 with serial: 3329 is powered: on
106+
=> 0
107+
[7] pry(main)>vlan200 = { :vlan_id => '200', :vlan_name => 'OpenStack-Mgmt' }.to_json
108+
=> "{\"vlan_id\":\"200\",\"vlan_name\":\"OpenStack-Mgmt\"}"
109+
[8] pry(main)> ucs.set_vlan(vlan200)
110+
=> " <configConfMos cookie=\"1398291606/fe13664b-b79d-4ac7-9d0f-98cedffd1c5e\" response=\"yes\"> <outConfigs> <pair key=\"fabric/lan/net-OpenStack-Mgmt\"> <fabricVlan childAction=\"deleteNonPresent\" cloud=\"ethlan\" compressionType=\"included\" configIssues=\"\" defaultNet=\"no\" dn=\"fabric/lan/net-OpenStack-Mgmt\" epDn=\"\" fltAggr=\"0\" global=\"0\" id=\"200\" ifRole=\"network\" ifType=\"virtual\" local=\"0\" locale=\"external\" mcastPolicyName=\"\" name=\"OpenStack-Mgmt\" operMcastPolicyName=\"\" operState=\"ok\" peerDn=\"\" policyOwner=\"local\" pubNwDn=\"\" pubNwId=\"1\" pubNwName=\"\" sharing=\"none\" status=\"created\" switchId=\"dual\" transport=\"ether\" type=\"lan\"/> </pair> </outConfigs> </configConfMos>"
111+
[9] pry(main)> ucs.delete_vlan(vlan200)
112+
=> " <configConfMos cookie=\"1398291606/fe13664b-b79d-4ac7-9d0f-98cedffd1c5e\" response=\"yes\"> <outConfigs> <pair key=\"fabric/lan/net-OpenStack-Mgmt\"> <fabricVlan cloud=\"ethlan\" compressionType=\"included\" configIssues=\"\" defaultNet=\"no\" dn=\"fabric/lan/net-OpenStack-Mgmt\" epDn=\"\" fltAggr=\"0\" global=\"0\" id=\"200\" ifRole=\"network\" ifType=\"virtual\" local=\"0\" locale=\"external\" mcastPolicyName=\"\" name=\"OpenStack-Mgmt\" operMcastPolicyName=\"org-root/mc-policy-default\" operState=\"ok\" peerDn=\"\" policyOwner=\"local\" pubNwDn=\"\" pubNwId=\"1\" pubNwName=\"\" sharing=\"none\" status=\"deleted\" switchId=\"dual\" transport=\"ether\" type=\"lan\"/> </pair> </outConfigs> </configConfMos>"
113+
[10] pry(main)>
40114

41115

42-
Just do "require ucslib" in your apps. Below is an IRB session to highlight some capabilities.
43116

117+
Just do "require ucslib" in your apps. Below is an IRB session to highlight some capabilities.
44118

45-
$ucslib git:(master) ✗ irb
46-
47-
1.9.3p194 :001 > require 'ucslib'
48-
=> true
49-
1.9.3p194 :002 > auth_json = { :username => 'admin', :password => 'admin', :ip => '172.16.75.137' }.to_json
50-
=> "{\"username\":\"admin\",\"password\":\"admin\",\"ip\":\"172.16.75.137\"}"
51-
1.9.3p194 :003 > ucs_session = UCSToken.new
52-
=> #<UCSToken:0x007ff4d92062c0>
53-
1.9.3p194 :004 > token_json = ucs_session.get_token(auth_json)
54-
=> "{\"cookie\":\"1336941096/ea496248-d200-4a10-8e46-c73b59971864\",\"username\":\"admin\",\"password\":\"admin\",\"ip\":\"172.16.75.137\"}"
55-
1.9.3p194 :005 > ucs_inventory = UCSInventory.new
56-
=> #<UCSInventory:0x007ff4d92cd8c0>
57-
1.9.3p194 :006 > ucs_provision = UCSProvision.new(token_json)
58-
=> #<UCSProvision:0x007ff4d92c0378 @cookie="1336941096/ea496248-d200-4a10-8e46-c73b59971864", @url="https://172.16.75.137/nuova">
59-
1.9.3p194 :007 > xml_dump = ucs_inventory.discover(token_json)
60-
61-
1.9.3p194 :008 > ucs_inventory.methods
62-
=> [:discover, :list_blades, :list_vsans, :list_vlans, :list_cpus, :list_memory, :list_service_profiles, :list_running_firmware, :to_json, :nil?, :##=, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :##, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
63-
1.9.3p194 :009 >
64-
65-
1.9.3p194 :009 > ucs_inventory.list_blades(xml_dump)
66-
Blade : 1/5 model: UCSB-B200-M3 with serial: 1049 is powered: off
67-
Blade : 1/6 model: N20-B6625-1 with serial: 1053 is powered: off
68-
Blade : 1/1 model: N20-B6620-1 with serial: 1045 is powered: on
69-
Blade : 1/7 model: N20-B6740-2 with serial: 1052 is powered: off
70-
Blade : 1/2 model: N20-B6620-1 with serial: 1054 is powered: off
71-
Blade : 1/4 model: N20-B6620-1 with serial: 1051 is powered: off
72-
Blade : 1/3 model: N20-B6620-1 with serial: 1055 is powered: off
73-
=> 0
74-
1.9.3p194 :010 >
75-
76-
1.9.3p194 :010 > vlan_json = { :vlan_id => '200', :vlan_name => 'OpenStack-Mgmt' }.to_json
77-
=> "{\"vlan_id\":\"200\",\"vlan_name\":\"OpenStack-Mgmt\"}"
78-
79-
1.9.3p194 :011 > ucs_provision.methods
80-
=> [:set_power_policy, :set_chassis_discovery_policy, :set_time_zone, :set_ntp, :create_server_port, :create_network_uplink_port, :create_fc_uplink_port, :create_port_channel, :create_org, :set_local_disk_policy, :create_local_boot_policy, :create_pxe_boot_policy, :create_san_boot_policy, :create_management_ip_pool, :create_vlan, :create_mac_pool, :create_vnic_template, :create_vsan, :create_wwnn_pool, :create_wwpn_pool, :create_vhba_template, :create_uuid_pool, :create_service_profile_template, :create_service_profiles_from_template, :create_service_profiles, :to_json, :nil?, :##=, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :##, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
81-
1.9.3p194 :012 >
82-
83-
1.9.3p194 :012 > ucs_provision.create_vlan(vlan_json)
84-
=> " <configConfMos cookie=\"1336941096/ea496248-d200-4a10-8e46-c73b59971864\" response=\"yes\"> <outConfigs> <pair key=\"fabric/lan/net-OpenStack-Mgmt\"> <fabricVlan childAction=\"deleteNonPresent\" defaultNet=\"no\" dn=\"fabric/lan/net-OpenStack-Mgmt\" epDn=\"\" id=\"200\" ifRole=\"network\" ifType=\"virtual\" locale=\"external\" name=\"OpenStack-Mgmt\" operState=\"ok\" peerDn=\"\" pubNwDn=\"\" pubNwId=\"0\" pubNwName=\"\" sharing=\"none\" status=\"created\" switchId=\"dual\" transport=\"ether\" type=\"lan\"/> </pair> </outConfigs> </configConfMos>"
85-
1.9.3p194 :013 >
86-
87-
1.9.3p194 :015 > xml_dump = ucs_inventory.discover(token_json)
88-
89-
1.9.3p194 :015 > ucs_inventory.list_vlans(xml_dump)
90-
VLAN: 1 with name: default
91-
VLAN: 1 with name: default
92-
VLAN: 5 with name: human-resource
93-
VLAN: 1 with name: default
94-
VLAN: 3 with name: finance
95-
VLAN: 5 with name: human-resource
96-
VLAN: 1 with name: default
97-
VLAN: 3 with name: finance
98-
VLAN: 100 with name: Tenant-1
99-
VLAN: 200 with name: OpenStack-Mgmt
100-
=> 0
101-
1.9.3p194 :016 >
102-
103-
1.9.3p194 :016 > ucs_stats = UCSStats.new
104-
105-
1.9.3p194 :017 > statsxml = ucs_stats.fetch(token_json)
106-
107-
1.9.3p194 :017 > ucs.show_sample(statsml,'fcStats')
108-
109-
The attributes for fcStats for dn=sys/switch-B/slot-1/switch-fc/port-32/stats are:
110-
bytesRx = 125283780333316
111-
bytesRxDelta = 142669360
112-
bytesRxDeltaAvg = 142706128
113-
bytesRxDeltaMax = 146404048
114-
bytesRxDeltaMin = 139044968
115-
bytesTx = 42023875724480
116-
bytesTxDelta = 29946840
117-
bytesTxDeltaAvg = 29842170
118-
bytesTxDeltaMax = 31907484
119-
bytesTxDeltaMin = 27672184
120-
intervals = 58982460
121-
packetsRx = 67694612103
122-
packetsRxDelta = 78357
123-
packetsRxDeltaAvg = 78476
124-
packetsRxDeltaMax = 80258
125-
packetsRxDeltaMin = 76814
126-
packetsTx = 22997688197
127-
packetsTxDelta = 18346
128-
packetsTxDeltaAvg = 18318
129-
packetsTxDeltaMax = 19393
130-
packetsTxDeltaMin = 17218
131-
suspect = no
132-
thresholded =
133-
timeCollected = 2012-11-16T13:40:32.362
134-
update = 65539
135-
136-
1.9.3p194 :018 > ucs.show_all(statsml,'fcStats') # output omitted
137119

138120
## Features
139121

0 commit comments

Comments
 (0)