Class: ImcHandle

Inherits:
ImcSession
  • Object
show all
Defined in:
lib/ImcSdk.rb

Overview

ImcHandle class is the user interface point for any Imc communication.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip:, username:, password:, port: "80", secure: nil, proxy: nil) ⇒ ImcHandle

Create an object of ImcHandle class

Examples:

handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password")
handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", secure: true)
handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", secure: false)
handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 80)
handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 443)
handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 100, secure: true)
handle = ImcHandle.new(ip: "192.168.1.1",username: "admin",password: "password", port: 100, secure: false)

Parameters:

  • ip (String)

    The IP or Hostname of the IMC Server

  • username (String)

    The username as configured on the Imc Server

  • password (String)

    The password as configured on the Imc Server

  • port (Integer, nil) (defaults to: "80")

    The port number to be used during connection

  • secure (bool, nil) (defaults to: nil)

    true for secure connection, otherwise false

  • proxy (String, nil) (defaults to: nil)

    The proxy object to be used to connect



40
41
42
43
# File 'lib/ImcSdk.rb', line 40

def initialize(ip:, username:, password:, port: "80", secure: nil, proxy: nil)
    super(ip: ip, username: username, password: password, port: port, secure: secure, proxy: proxy)
    self.to_commit = {}
end

Instance Attribute Details

#to_commitObject

ImcHandle class is the user interface point for any Imc communication.

Author:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ImcSdk.rb', line 13

class ImcHandle < ImcSession

    attr_accessor :to_commit

    # Create an object of ImcHandle class
    #
    # @param ip [String] The IP or Hostname of the IMC Server
    # @param username [String] The username as configured on the Imc Server
    # @param password [String] The password as configured on the Imc Server
    # @param port [Integer, nil] The port number to be used during connection
    # @param secure [bool, nil] true for secure connection, otherwise false
    # @param proxy [String, nil] The proxy object to be used to connect
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password")
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", secure: true)
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", secure: false)
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 80)
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 443)
    # @example
    #   handle = ImcHandle.new (ip: "192.168.1.1",username: "admin",password: "password", port: 100, secure: true)
    # @example
    #   handle = ImcHandle.new(ip: "192.168.1.1",username: "admin",password: "password", port: 100, secure: false)

    def initialize(ip:, username:, password:, port: "80", secure: nil, proxy: nil)
        super(ip: ip, username: username, password: password, port: port, secure: secure, proxy: proxy)
        self.to_commit = {}
    end
    
    #def set_dump_xml()
    #    #Enables the logging of xml requests and responses
    #    super
    #end
    
    #def unset_dump_xml()
        #Disables the logging of xml request and responses
    #    super
    #end
    
    # Initiated a connection to the server referenced by the ImcHandle. A cookie is populated in the ImcHandle, if the login is successful.
    #
    # @param auto_refresh [TrueClass, FalseCalss] If set to true, it refresh the cookie continuously
    # @param force [TrueClass, FalseClass] If set to true it reconnects even if cookie exists and is valid for respective connection.
    # @param timeout [Integer] Timeout value in seconds
    # @return [TrueClass, FalseClass] true on successful connect
    # @example
    #   handle.login()
    # @example
    #   handle.login(auto_refresh: true)
    # @example
    #   handle.login(force: true)
    # @example
    #   handle.login(auto_refresh: true, force: true)
    # @note Where handle is an object of ImcHandle class.
    def (auto_refresh: false, force: false, timeout: "60")
        return (auto_refresh: auto_refresh, force: force, timeout: timeout)
    end
    
    # Disconnects from the server referenced by the ImcHandle.
    #
    # @param timeout [Integer] timeout value in seconds.
    # @return [TrueClass, FalseClass] true on successful disconnect
    #
    # @example
    #   handle.logout()
    # @example
    #   handle.logout(timout: 60)
    # @note Where handle is an object of ImcHandle class.

    def logout(timeout: "60")
        return _logout(timeout: timeout)
    end
    
    #
    # process_xml_elem is a helper method which posts xml elements to the
    # server and returns parsed response. It's role is to operate on the
    # output of methods from Imcmethodfactory, which return xml element
    # node(s).
    #
    # @param elem [] XML Element Object
    # @return [External Method Object, MO List] MO List or External Method Object
    #
    # @example
    #   elem = imcmethodfactory.config_resolve_class(cookie: handle.cookie, class_id: "computeRackUnit")
    #   objs = handle.process_xml_elem(elem)
    #
    def process_xml_elem(elem, timeout: "60")
        response = self.post_elem(elem, timeout: timeout)
        if response.error_code != 0
            raise ImcException.new(response.error_code, response.error_descr)
        end
        if response.is_outconfig_available()
            return response.get_outconfig_child()
        else
            return response
        end
    end

    # Returns a token that is used for IMC authentication.
    #
    # @param timeout [Integer] timeout value(in seconds)
    # @return [String] Token used for IMC Authentication
    #
    # @example
    #   handle.get_auth_token()
    #
    def get_auth_token(timeout: "60")
      
        auth_token = nil
        mo = self.query_classid(class_id: NamingId::COMPUTE_BOARD)
        if mo.nil?
            mo = self.query_classid(class_id: NamingId::COMPUTE_RACK_UNIT)
        end

        if !mo.nil?
            elem = aaa_get_compute_auth_tokens(cookie: self.cookie)
            response = self.post_elem(elem, timeout: timeout)

            if response.error_code != 0
                raise ImcException.new(response.error_code, response.error_descr)
            end

            if response.instance_variable_defined?(:@out_tokens)
                auth_token = response.instance_variable_get(:@out_tokens).split(',').first
            end
        end
        return auth_token
    end

    #
    # Finds an object using it's distinguished name.
    #
    # @param dn [String] distinguished name of the object to be queried for.
    # @param hierarchy [TrueClass, FalseClass] Gets all objects in hierarchy if true
    # @param need_response [TrueClass, FalseClass] returns the response xml node, instead of parsed objects.
    # @param timeout [Integer] timeout value(in seconds)
    # @return [ManagedObject, Array<ManagedObject>, ExternalMethod] Return Managed Object by default, returns Array<ManagedObject> if hierarchy is set to true,
    # returns ExternalMethod if need_response is set to true.
    #
    # @example
    #   obj = handle.query_dn(dn: "sys/rack-unit-1")
    # @example
    #   obj = handle.query_dn(dn: "sys/rack-unit-1", hierarchy: true)
    # @example
    #   obj = handle.query_dn(dn: "sys/rack-unit-1", need_response: true
    # @example
    #   obj = handle.query_dn(dn: "sys/rack-unit-1", hierarchy: true, need_response: true)

    def query_dn(dn:, hierarchy: false, need_response: false, timeout: "60")
        
        if dn.nil?
            raise ValueError.new ("Provide dn.")
        end
        
        elem = config_resolve_dn(self.cookie, dn, hierarchy)
        
        response = self.post_elem(elem, timeout: timeout)
        
        if response.error_code != 0
            raise ImcException.new(response.error_code, response.error_descr)
        end
        
        if need_response
            return response
        end
        
        if hierarchy
            out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
            return out_mo_list
        end
        
        mo = nil
        child = response.get_outconfig_child()
        if child.size > 0
            mo = child[0]
        end
        return mo
    end

    #
    # Finds an object using it's class id.
    #
    # @param class_id [String] class id of the object to be queried for.
    # @param hierarchy [TrueClass, FalseClass] if set to true will return all the child hierarchical objects.
    # @param need_response [TrueClass, FalseClass] if set to true will return only response object.
    # @param timeout [Integer] timeout value(in seconds)
    # @return [Array<ManagedObject>, Method_Response, nil] returns Method_Response if need_response is set to true
    #
    # @example
    #   obj = handle.query_classid(class_id: "computeRackUnit")
    # @example
    #   obj = handle.query_classid(class_id: "computeRackUnit", hierarchy: true)
    # @example
    #   obj = handle.query_classid(class_id: "computeRackUnit", need_response: true)
    #
    def query_classid(class_id:, hierarchy: false, need_response: false, timeout: "60" )

        if class_id.nil?
            raise ValueError("Provide Parameter class_id")
        end
        
        meta_class_id = ImcCoreUtils.find_class_id_in_mo_meta_ignore_case(class_id)
        
        if meta_class_id.nil?
            meta_class_id = class_id
        end
        
        elem = config_resolve_class(self.cookie, class_id = meta_class_id, hierarchy)
        
        response = self.post_elem(elem, timeout: timeout)
        
        if response.error_code != 0
            raise ImcException.new(response.error_code, response.error_descr)
        end
        
        if need_response
            return response
        end
        
        out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
        return out_mo_list
        
    end
    
    #
    # Finds children of a given managed object or distinguished name.
    # Arguments can be specified to query only a specific type(class_id) of children.
    # Arguments can also be specified to query only direct children or the entire hierarchy of children.
    #
    # @param in_mo [ManagedObject] query children managed object under this object.
    # @param in_dn [String] query children managed object for a given managed object of the respective dn.
    # @param class_id [String] by default nil, if given finds only specific childred object for a given class_id.
    # @param hierarchy [TrueClass, FalseClass] if set to true will return all the child hierarchical objects.
    # @param timeout [Integer] timeout value in seconds
    # @return [Array<ManagedObject>, nil]
    #
    # @example
    #    mo_list = handle.query_children(in_mo: mo)
    # @example
    #   mo_list = handle.query_children(in_mo: mo, class_id: "classid")
    # @example
    #   mo_list = handle.query_children(in_dn: dn)
    # @example
    #   mo_list = handle.query_children(in_dn: dn, class_id: "classid")
    #
    def query_children(in_mo: nil, in_dn: nil, class_id: nil, hierarchy: false, timeout: "60")
        if in_mo.nil? and in_dn.nil?
            raise ValueError("[Error]: GetChild: Provide in_mo or in_dn")
        end
        
        if in_mo
            parent_dn = in_mo.dn
        elsif
            parent_dn = in_dn
        end
        
        if class_id
            meta_class_id = ImcCoreUtils.find_class_id_in_mo_meta_ignore_case(class_id)
            if meta_class_id.nil?
                meta_class_id = class_id
            end
        else
            meta_class_id = class_id
        end
        
        elem = config_resolve_children(self.cookie, class_id = meta_class_id, in_dn = parent_dn, hierarchy)
        
        response = post_elem(elem, timeout: timeout)
        
        if response.error_code != 0
            raise ImcException.new(response.error_code, response.error_descr)
        end
        
        out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
        
        return out_mo_list
    end
    #
    # Add a Managed Object to the IMC Server
    #
    # @param mo [ManagedObject] Managed Object to the added to the IMC Server
    # @param modify_present [TrueClass, FalseClass] Over-write an existing object if true
    # @param timeout [Integer] timoeout value(in seconds)
    # @return [nil]
    # @example
    #   handle.add_mo(mo: mo)
    #
    def add_mo(mo:, modify_present: true, timeout: "60")
        if ImcGenUtils::AFFIRMATIVE_LIST.include? modify_present
            if self.query_dn(dn: mo.dn).nil?
                mo.set_prop("status","created")
                else
                mo.set_prop("status", "modified")
            end
        else
            mo.set_prop("status", "created")
        end
        
        self.to_commit[mo.dn] = mo
        _commit(timeout: timeout)
    end
    
    #
    # Modifies a managed object and adds it to the ImcHandle commit buffer (if not already in it)
    #
    # @param mo [ManagedObject] Managed Object with modified properties
    # @param timeout [Integer, nil] timeout value in seconds
    # @return [nil]
    #
    # @example
    #   handle.set_mo(mo: mo)
    #
    def set_mo(mo:, timeout: "60")      
        #mo.instance_variable_set(:@status, "modified")
        mo.set_prop("status", "modified")
        self.to_commit[mo.instance_variable_get(:@dn)] = mo
        _commit(timeout: timeout)
    end

    #
    # Remove a Managed Object from the IMC Server
    #
    # @param mo [ManagedObject] Managed Object to be removed.
    # @param timeout [Integer] timeout value(in seconds).
    # @return [nil] Nothing is returned.
    #
    # @example
    #   handle.remove_mo(mo: mo)
    #
    def remove_mo(mo:, timeout: "60")
        mo.set_prop("status", "deleted")
        if mo.instance_variable_defined?(:@parent_mo) and !mo.parent_mo.nil?
            mo.parent_mo.child_remove(mo)
        end
        
        self.to_commit[mo.dn] = mo
        _commit(timeout: timeout)
    end

#private methods    
private
    #
    # Commit the buffer to the server. Pushes all the configuration changes so far to the server.
    # Configuration could be added to the commit buffer using add_mo(), set_mo(), and remove_mo().
    #
    # @param timeout [Integer] timeout value in seconds.
    # @return [nil]
    # @example
    #   self._commit()
    #
    def _commit(timeout: "60")

        mo_dict = self.to_commit
        if mo_dict.nil? or mo_dict.empty?
            return nil
        end
        
        config_map = ConfigMap.new()
        
        mo_dict.each do |mo_dn, mo|
            config_map.child_add(mo)
            elem = config_conf_mo(self.cookie, mo_dn, config_map, false)
            
            response = post_elem(elem, timeout: timeout)
            
            if response.error_code != 0
                self.to_commit = {}
                raise ImcException.new(response.error_code, response.error_descr)
            end
            
            child = response.get_outconfig_child()
            for pair_ in child do             
                for out_mo in pair_.child do
                    out_mo.sync_mo(mo_dict[out_mo.dn])
                end
            end
            self.to_commit = {}
        end
    end
end

Instance Method Details

#add_mo(mo:, modify_present: true, timeout: "60") ⇒ nil

Add a Managed Object to the IMC Server

Examples:

handle.add_mo(mo: mo)

Parameters:

  • mo (ManagedObject)

    Managed Object to the added to the IMC Server

  • modify_present (TrueClass, FalseClass) (defaults to: true)

    Over-write an existing object if true

  • timeout (Integer) (defaults to: "60")

    timoeout value(in seconds)

Returns:

  • (nil)


303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/ImcSdk.rb', line 303

def add_mo(mo:, modify_present: true, timeout: "60")
    if ImcGenUtils::AFFIRMATIVE_LIST.include? modify_present
        if self.query_dn(dn: mo.dn).nil?
            mo.set_prop("status","created")
            else
            mo.set_prop("status", "modified")
        end
    else
        mo.set_prop("status", "created")
    end
    
    self.to_commit[mo.dn] = mo
    _commit(timeout: timeout)
end

#get_auth_token(timeout: "60") ⇒ String

Returns a token that is used for IMC authentication.

Examples:

handle.get_auth_token()

Parameters:

  • timeout (Integer) (defaults to: "60")

    timeout value(in seconds)

Returns:

  • (String)

    Token used for IMC Authentication



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ImcSdk.rb', line 122

def get_auth_token(timeout: "60")
  
    auth_token = nil
    mo = self.query_classid(class_id: NamingId::COMPUTE_BOARD)
    if mo.nil?
        mo = self.query_classid(class_id: NamingId::COMPUTE_RACK_UNIT)
    end

    if !mo.nil?
        elem = aaa_get_compute_auth_tokens(cookie: self.cookie)
        response = self.post_elem(elem, timeout: timeout)

        if response.error_code != 0
            raise ImcException.new(response.error_code, response.error_descr)
        end

        if response.instance_variable_defined?(:@out_tokens)
            auth_token = response.instance_variable_get(:@out_tokens).split(',').first
        end
    end
    return auth_token
end

#login(auto_refresh: false, force: false, timeout: "60") ⇒ TrueClass, FalseClass

Note:

Where handle is an object of ImcHandle class.

Initiated a connection to the server referenced by the ImcHandle. A cookie is populated in the ImcHandle, if the login is successful.

Examples:

handle.()
handle.(auto_refresh: true)
handle.(force: true)
handle.(auto_refresh: true, force: true)

Parameters:

  • auto_refresh (TrueClass, FalseCalss) (defaults to: false)

    If set to true, it refresh the cookie continuously

  • force (TrueClass, FalseClass) (defaults to: false)

    If set to true it reconnects even if cookie exists and is valid for respective connection.

  • timeout (Integer) (defaults to: "60")

    Timeout value in seconds

Returns:

  • (TrueClass, FalseClass)

    true on successful connect



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

def (auto_refresh: false, force: false, timeout: "60")
    return (auto_refresh: auto_refresh, force: force, timeout: timeout)
end

#logout(timeout: "60") ⇒ TrueClass, FalseClass

Note:

Where handle is an object of ImcHandle class.

Disconnects from the server referenced by the ImcHandle.

Examples:

handle.logout()
handle.logout(timout: 60)

Parameters:

  • timeout (Integer) (defaults to: "60")

    timeout value in seconds.

Returns:

  • (TrueClass, FalseClass)

    true on successful disconnect



85
86
87
# File 'lib/ImcSdk.rb', line 85

def logout(timeout: "60")
    return _logout(timeout: timeout)
end

#process_xml_elem(elem, timeout: "60") ⇒ External Method Object, MO List

process_xml_elem is a helper method which posts xml elements to the server and returns parsed response. It’s role is to operate on the output of methods from Imcmethodfactory, which return xml element node(s).

Examples:

elem = imcmethodfactory.config_resolve_class(cookie: handle.cookie, class_id: "computeRackUnit")
objs = handle.process_xml_elem(elem)

Parameters:

  • elem

    XML Element Object

Returns:

  • (External Method Object, MO List)

    MO List or External Method Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ImcSdk.rb', line 102

def process_xml_elem(elem, timeout: "60")
    response = self.post_elem(elem, timeout: timeout)
    if response.error_code != 0
        raise ImcException.new(response.error_code, response.error_descr)
    end
    if response.is_outconfig_available()
        return response.get_outconfig_child()
    else
        return response
    end
end

#query_children(in_mo: nil, in_dn: nil, class_id: nil, hierarchy: false, timeout: "60") ⇒ Array<ManagedObject>?

Finds children of a given managed object or distinguished name. Arguments can be specified to query only a specific type(class_id) of children. Arguments can also be specified to query only direct children or the entire hierarchy of children.

Examples:

mo_list = handle.query_children(in_mo: mo)
mo_list = handle.query_children(in_mo: mo, class_id: "classid")
mo_list = handle.query_children(in_dn: dn)
mo_list = handle.query_children(in_dn: dn, class_id: "classid")

Parameters:

  • in_mo (ManagedObject) (defaults to: nil)

    query children managed object under this object.

  • in_dn (String) (defaults to: nil)

    query children managed object for a given managed object of the respective dn.

  • class_id (String) (defaults to: nil)

    by default nil, if given finds only specific childred object for a given class_id.

  • hierarchy (TrueClass, FalseClass) (defaults to: false)

    if set to true will return all the child hierarchical objects.

  • timeout (Integer) (defaults to: "60")

    timeout value in seconds

Returns:

  • (Array<ManagedObject>, nil)


261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/ImcSdk.rb', line 261

def query_children(in_mo: nil, in_dn: nil, class_id: nil, hierarchy: false, timeout: "60")
    if in_mo.nil? and in_dn.nil?
        raise ValueError("[Error]: GetChild: Provide in_mo or in_dn")
    end
    
    if in_mo
        parent_dn = in_mo.dn
    elsif
        parent_dn = in_dn
    end
    
    if class_id
        meta_class_id = ImcCoreUtils.find_class_id_in_mo_meta_ignore_case(class_id)
        if meta_class_id.nil?
            meta_class_id = class_id
        end
    else
        meta_class_id = class_id
    end
    
    elem = config_resolve_children(self.cookie, class_id = meta_class_id, in_dn = parent_dn, hierarchy)
    
    response = post_elem(elem, timeout: timeout)
    
    if response.error_code != 0
        raise ImcException.new(response.error_code, response.error_descr)
    end
    
    out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
    
    return out_mo_list
end

#query_classid(class_id:, hierarchy: false, need_response: false, timeout: "60") ⇒ Array<ManagedObject>, ...

Finds an object using it’s class id.

Examples:

obj = handle.query_classid(class_id: "computeRackUnit")
obj = handle.query_classid(class_id: "computeRackUnit", hierarchy: true)
obj = handle.query_classid(class_id: "computeRackUnit", need_response: true)

Parameters:

  • class_id (String)

    class id of the object to be queried for.

  • hierarchy (TrueClass, FalseClass) (defaults to: false)

    if set to true will return all the child hierarchical objects.

  • need_response (TrueClass, FalseClass) (defaults to: false)

    if set to true will return only response object.

  • timeout (Integer) (defaults to: "60")

    timeout value(in seconds)

Returns:

  • (Array<ManagedObject>, Method_Response, nil)

    returns Method_Response if need_response is set to true



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/ImcSdk.rb', line 211

def query_classid(class_id:, hierarchy: false, need_response: false, timeout: "60" )

    if class_id.nil?
        raise ValueError("Provide Parameter class_id")
    end
    
    meta_class_id = ImcCoreUtils.find_class_id_in_mo_meta_ignore_case(class_id)
    
    if meta_class_id.nil?
        meta_class_id = class_id
    end
    
    elem = config_resolve_class(self.cookie, class_id = meta_class_id, hierarchy)
    
    response = self.post_elem(elem, timeout: timeout)
    
    if response.error_code != 0
        raise ImcException.new(response.error_code, response.error_descr)
    end
    
    if need_response
        return response
    end
    
    out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
    return out_mo_list
    
end

#query_dn(dn:, hierarchy: false, need_response: false, timeout: "60") ⇒ ManagedObject, ...

Finds an object using it’s distinguished name.

returns ExternalMethod if need_response is set to true.

Examples:

obj = handle.query_dn(dn: "sys/rack-unit-1")
obj = handle.query_dn(dn: "sys/rack-unit-1", hierarchy: true)
obj = handle.query_dn(dn: "sys/rack-unit-1", need_response: true
obj = handle.query_dn(dn: "sys/rack-unit-1", hierarchy: true, need_response: true)

Parameters:

  • dn (String)

    distinguished name of the object to be queried for.

  • hierarchy (TrueClass, FalseClass) (defaults to: false)

    Gets all objects in hierarchy if true

  • need_response (TrueClass, FalseClass) (defaults to: false)

    returns the response xml node, instead of parsed objects.

  • timeout (Integer) (defaults to: "60")

    timeout value(in seconds)

Returns:

  • (ManagedObject, Array<ManagedObject>, ExternalMethod)

    Return Managed Object by default, returns Array<ManagedObject> if hierarchy is set to true,



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ImcSdk.rb', line 164

def query_dn(dn:, hierarchy: false, need_response: false, timeout: "60")
    
    if dn.nil?
        raise ValueError.new ("Provide dn.")
    end
    
    elem = config_resolve_dn(self.cookie, dn, hierarchy)
    
    response = self.post_elem(elem, timeout: timeout)
    
    if response.error_code != 0
        raise ImcException.new(response.error_code, response.error_descr)
    end
    
    if need_response
        return response
    end
    
    if hierarchy
        out_mo_list = ImcCoreUtils.extract_molist_from_method_response(response, hierarchy)
        return out_mo_list
    end
    
    mo = nil
    child = response.get_outconfig_child()
    if child.size > 0
        mo = child[0]
    end
    return mo
end

#remove_mo(mo:, timeout: "60") ⇒ nil

Remove a Managed Object from the IMC Server

Examples:

handle.remove_mo(mo: mo)

Parameters:

  • mo (ManagedObject)

    Managed Object to be removed.

  • timeout (Integer) (defaults to: "60")

    timeout value(in seconds).

Returns:

  • (nil)

    Nothing is returned.



345
346
347
348
349
350
351
352
353
# File 'lib/ImcSdk.rb', line 345

def remove_mo(mo:, timeout: "60")
    mo.set_prop("status", "deleted")
    if mo.instance_variable_defined?(:@parent_mo) and !mo.parent_mo.nil?
        mo.parent_mo.child_remove(mo)
    end
    
    self.to_commit[mo.dn] = mo
    _commit(timeout: timeout)
end

#set_mo(mo:, timeout: "60") ⇒ nil

Modifies a managed object and adds it to the ImcHandle commit buffer (if not already in it)

Examples:

handle.set_mo(mo: mo)

Parameters:

  • mo (ManagedObject)

    Managed Object with modified properties

  • timeout (Integer, nil) (defaults to: "60")

    timeout value in seconds

Returns:

  • (nil)


328
329
330
331
332
333
# File 'lib/ImcSdk.rb', line 328

def set_mo(mo:, timeout: "60")      
    #mo.instance_variable_set(:@status, "modified")
    mo.set_prop("status", "modified")
    self.to_commit[mo.instance_variable_get(:@dn)] = mo
    _commit(timeout: timeout)
end