Class: UCSAPI::UCS

Inherits:
Object
  • Object
show all
Includes:
Nuova, UCSMO
Defined in:
lib/UCSAPI.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ UCS

Returns a new instance of UCS.


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/UCSAPI.rb', line 46

def initialize(opts={})

  raise "No parameters" if opts == nil 
  @log = Logger.new(STDOUT)
  @log.level = Logger::ERROR
  @log.progname = self.class.to_s

  @log.info("initialize starting")
  @api = API.new(opts)
  @log.info("initialize ending")
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api


44
45
46
# File 'lib/UCSAPI.rb', line 44

def api
  @api
end

Instance Method Details

#fabric(opts = {}) ⇒ Object

Logic is simple:

  • If you give us a dn, return one Fabric

  • If you provide a text ID, return one Fabric

  • If you provide nothing, return FabricArray


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/UCSAPI.rb', line 78

def fabric(opts={})
  @log.info("fabric started")

  classId = 'networkElement'
  if opts[:dn] 
    element = @api.configResolveDn( :dn => opts[:dn])
    found = Fabric.create(@api,element)  
  elsif opts[:id] then
    dn = 'sys/switch-' + opts[:id]
    element = @api.configResolveDn( :dn => dn )
    found = Fabric.create(@api,element)  
  else
    classId = 'networkElement'    
    elements = @api.configResolveClass( :classId => classId)
    found = FabricArray.create(@api,elements)     
  end
  
  @log.info "fabric ended"
  found 
end

#fabrics(opts = {}) ⇒ Object


99
100
101
102
103
104
105
106
# File 'lib/UCSAPI.rb', line 99

def fabrics(opts={})   
  @log.info("fabrics started")

  found = fabric(opts)
  
  @log.info("fabrics ended")
  found
end

#loginObject


58
59
60
# File 'lib/UCSAPI.rb', line 58

def 
  @api. if @api.session.cookie = ""
end

#logoutObject


70
71
72
# File 'lib/UCSAPI.rb', line 70

def logout
  @api.logout
end

#sessionObject


66
67
68
# File 'lib/UCSAPI.rb', line 66

def session
  @api.session
end