UCSAPI 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/UCSAPI.rb +77 -6
  2. metadata +4 -4
data/lib/UCSAPI.rb CHANGED
@@ -48,7 +48,7 @@ require 'rexml/document'
48
48
  require 'rest_client'
49
49
  require 'logger'
50
50
  require 'ostruct'
51
- VERSION = '0.0.6'
51
+ VERSION = '0.0.7'
52
52
 
53
53
  #At the moment this is one big class with lots of methods. Refactoring due later :)
54
54
  class UCSM
@@ -161,7 +161,8 @@ VERSION = '0.0.6'
161
161
  #* The caller will send a REXML object with the XMLAPI command in it
162
162
  #* Send the XMLAPI call to UCS and catch any exceptions (log and quit if we do)
163
163
  def dispatch(xml)
164
- @log.info("UCSAPI::Session.dispatch sending " + xml.to_s)
164
+ @log.info("dispatch starting")
165
+ @log.info("dispatch called with " + xml.to_s)
165
166
 
166
167
  # The RestClient.post method expects text, not a REXML object
167
168
  post = xml.to_s
@@ -220,6 +221,7 @@ VERSION = '0.0.6'
220
221
  end
221
222
 
222
223
  #Build an XMLAPI call to find an object(s) via the class name
224
+ #If you supply a :inFilter hash of property/value, we'll add a filter element
223
225
  #Returns an *Array* of found objects
224
226
  #* Build the XMLAPI call from the opts parameters
225
227
  #* Send the XMLAPI object to dispatch, get an XML object back
@@ -235,7 +237,17 @@ VERSION = '0.0.6'
235
237
  request = REXML::Document.new('<configResolveClass />')
236
238
  request.root.add_attribute("inHierarchical",inHierarchical)
237
239
  request.root.add_attribute("classId",opts[:classId])
238
-
240
+ if opts[:inFilter]
241
+ filterHash = opts[:inFilter]
242
+ filterType = filterHash["type"]
243
+ filterProperty = filterHash["property"]
244
+ filterValue = filterHash["value"]
245
+ inFilter = request.root.add_element("inFilter")
246
+ inFilter.add_element(filterType, { "class" => opts[:classId], "property" => filterProperty, "value" => filterValue})
247
+ end
248
+
249
+ puts request.to_s
250
+
239
251
  response = dispatch(request)
240
252
 
241
253
  outConfig = response.root.elements[1]
@@ -250,7 +262,7 @@ VERSION = '0.0.6'
250
262
 
251
263
  @log.info "configResolveClass returning " + found.size.to_s + " objects"
252
264
  else
253
- @log.error "configResolveClass ERROR No items found for classId = " + opts[:classId]
265
+ @log.error "configResolveClass ERROR No items found for classId = " + opts[:classId] + " with filter: " + opts[:inFilter].to_s
254
266
  end
255
267
  else
256
268
  @log.error "configResolveClass ERROR Please supply a :classId option like configResolveClass( :classId => 'equipmentChassis' )" unless opts[:classId]
@@ -414,10 +426,69 @@ VERSION = '0.0.6'
414
426
  found = configResolveClass( :classId => classId)
415
427
  end
416
428
 
417
- @log.info("chassis ended")
429
+ @log.info("blade ended")
418
430
  found
419
431
  end
420
432
 
433
+ #Adapter pattern method to make finding service profiles easier
434
+ #Returns an *Array* of found objects
435
+ #Logic is simple here:
436
+ #* You can just provide a dn, we just get that and we're done
437
+ #* If you provide a :name, then we treat it as a wildcard and search that field
438
+ #* If you provide an :org, we get all the profiles under that
439
+ #* If you provide only a :chassis, we get all service profiles associated to blades in that chassis
440
+ #* If you provide a :chassis and a :blade we get the associated service profile
441
+ #* If you provide a :pnDn then it's the same as :chassis and :blade
442
+ #* If you provide a :inFilter hash with "type", "property", and "value" in it, we'll send on the search
443
+ #* If you provide a :uuid we'll get that profile
444
+ #* If you provide a :template name, we'll get all profiles based on that template
445
+ #* If you provide nothing, we get all blades
446
+ def server(opts={})
447
+ @log.info("server started")
448
+
449
+ classId = 'lsServer'
450
+ found = Array.new
451
+
452
+ if opts[:dn]
453
+ found = configResolveDn( :dn => opts[:dn] )
454
+ elsif opts[:name]
455
+ inFilter = { "type" => "wcard", "property" => "name", "value" => opts[:name] }
456
+ found = configResolveClass( :classId => classId, :inFilter => inFilter)
457
+ elsif opts[:org]
458
+ found = configResolveChildren( :inDn => 'org-'+opts[:org], :classId => classId )
459
+ elsif opts[:uuid]
460
+ inFilter = { "type" => "wcard", "property" => "uuid", "value" => opts[:uuid] }
461
+ found = configResolveClass( :classId => classId, :inFilter => inFilter)
462
+ elsif opts[:template]
463
+ inFilter = { "type" => "wcard", "property" => "srcTemplName", "value" => opts[:template] }
464
+ found = configResolveClass( :classId => classId, :inFilter => inFilter)
465
+ elsif opts[:chassis]
466
+ if opts[:chassis] =~ /chassis-/
467
+ pnDn = opts[:chassis]
468
+ else
469
+ pnDn = 'chassis-' + opts[:chassis]
470
+ end
471
+ if opts[:blade]
472
+ pnDn << "/"
473
+ if opts[:blade] =~ /blade-/
474
+ pnDn << opts[:blade]
475
+ else
476
+ pnDn << 'blade-' + opts[:blade]
477
+ end
478
+ end
479
+ inFilter = { "type" => "wcard", "property" => "pnDn", "value" => pnDn }
480
+ found = configResolveClass( :classId => classId, :inFilter => inFilter)
481
+ elsif opts[:inFilter]
482
+ @log.error ":inFilter must be a hash of type, property, value" unless opts[:inFilter].class == Hash
483
+ found = configResolveClass( :classId => classId, :inFilter => opts[:inFilter])
484
+ else
485
+ found = configResolveClass( :classId => classId)
486
+ end
487
+
488
+ @log.info("server ended")
489
+ found
490
+ end
491
+
421
492
  #Adapter pattern method to make finding PSUs easier
422
493
  #Returns an *Array* of found objects
423
494
  #The logic works like this:
@@ -493,7 +564,7 @@ VERSION = '0.0.6'
493
564
  found = configResolveChildren( :classId => classId, :inDn => module_dn )
494
565
  end
495
566
  else
496
- @log.error "UCSM.fan Missing :module parameter"
567
+ @log.error "Missing :module parameter"
497
568
  end
498
569
  elsif opts[:fabric]
499
570
  fabric_dn = 'sys/switch-' + opts[:fabric].to_s
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: UCSAPI
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Chambers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-01 00:00:00 +01:00
18
+ date: 2010-10-02 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency