Ejemplo n.º 1
0
 def __init__(self, mng, domain, ips, user, pwd):
     M.__init__(self, domain=domain, user=user, pwd=pwd)
     self._mng = mng
     sepkv = re.match('^[\d.:]+(?P<sep>[,/&|])', ips)
     if sepkv: self['ips'] = L(*ips.split(sepkv.group('sep')))
     else: self['ips'] = L(ips)
      
     #===================================================================
     # Connect APIC
     #===================================================================
     
     for ip in self.ips:
         self._session = acitool.Session('https://%s' % ip, user, pwd)
         resp = self._session.login()
         if resp.ok:
             self._mo_session = acitool.Session('https://%s' % ip, user, pwd)
             resp = self._mo_session.login()
             if resp.ok:
                 self['connected'] = ip
                 self._url = 'https://%s/api/' % ip
                 self.eptracker = EPTracker(self)
                 self.healthmon = HealthMon(self)
                 break
             else:
                 self._mo_session.close()
                 self._session.close()
         else:
             self._session.close()
     else: raise ACIManager.APIC.APIC_CONNECTION_FAILED(self)
     
     for key in acitool.__dict__:
         if re.search('^[A-Z]+\w*', key):
             self.__setattr__(key, ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER(self, acitool.__dict__[key]))
Ejemplo n.º 2
0
        def __init__(self, mng, domain, ips, user, pwd):
            M.__init__(self, domain=domain, user=user, pwd=pwd)
            self._mng = mng
            sepkv = re.match('^[\d.:]+(?P<sep>[,/&|])', ips)
            if sepkv: self['ips'] = L(*ips.split(sepkv.group('sep')))
            else: self['ips'] = L(ips)

            #===================================================================
            # Connect APIC
            #===================================================================

            for ip in self.ips:
                self._session = acitool.Session('https://%s' % ip, user, pwd)
                resp = self._session.login()
                if resp.ok:
                    self._mo_session = acitool.Session('https://%s' % ip, user,
                                                       pwd)
                    resp = self._mo_session.login()
                    if resp.ok:
                        self['connected'] = ip
                        self._url = 'https://%s/api/' % ip
                        self.eptracker = EPTracker(self)
                        self.healthmon = HealthMon(self)
                        break
                    else:
                        self._mo_session.close()
                        self._session.close()
                else:
                    self._session.close()
            else:
                raise ACIManager.APIC.APIC_CONNECTION_FAILED(self)

            for key in acitool.__dict__:
                if re.search('^[A-Z]+\w*', key):
                    self.__setattr__(
                        key,
                        ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER(
                            self, acitool.__dict__[key]))
Ejemplo n.º 3
0
    class APIC(M):
        class APIC_CONNECTION_FAILED(E):
            def __init__(self, apic):
                E.__init__(
                    self, 'Connection Failed %s@%s:%s' %
                    (apic.user, str(apic.ips), apic.pwd))

        class ACITOOLKIT_CLASS_WRAPPER(object):
            class ACITOOLKIT_METHOD_WRAPPER:
                def __init__(self, apic, cls, key):
                    self.apic = apic
                    self.cls = cls
                    self.key = key

                def __call__(self, *argv):
                    return getattr(self.cls, self.key)(self.apic._mo_session,
                                                       *argv)

            def __init__(self, apic, cls):
                for key in cls.__dict__:
                    if re.search('^[_A-Za-z][A-Za-z]\w*', key):
                        if typeof(cls.__dict__[key]) == 'classmethod':
                            self.__setattr__(
                                key,
                                ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER.
                                ACITOOLKIT_METHOD_WRAPPER(apic, cls, key))

        def __init__(self, mng, domain, ips, user, pwd):
            M.__init__(self, domain=domain, user=user, pwd=pwd)
            self._mng = mng
            sepkv = re.match('^[\d.:]+(?P<sep>[,/&|])', ips)
            if sepkv: self['ips'] = L(*ips.split(sepkv.group('sep')))
            else: self['ips'] = L(ips)

            #===================================================================
            # Connect APIC
            #===================================================================

            for ip in self.ips:
                self._session = acitool.Session('https://%s' % ip, user, pwd)
                resp = self._session.login()
                if resp.ok:
                    self._mo_session = acitool.Session('https://%s' % ip, user,
                                                       pwd)
                    resp = self._mo_session.login()
                    if resp.ok:
                        self['connected'] = ip
                        self._url = 'https://%s/api/' % ip
                        self.eptracker = EPTracker(self)
                        self.healthmon = HealthMon(self)
                        break
                    else:
                        self._mo_session.close()
                        self._session.close()
                else:
                    self._session.close()
            else:
                raise ACIManager.APIC.APIC_CONNECTION_FAILED(self)

            for key in acitool.__dict__:
                if re.search('^[A-Z]+\w*', key):
                    self.__setattr__(
                        key,
                        ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER(
                            self, acitool.__dict__[key]))

        def __del__(self):
            self.healthmon.__del__()
            self.eptracker.__del__()
            self._mo_session.close()
            self._session.close()

        def get(self, *targets):
            if self.connected:
                ret = L()
                for target in targets:
                    if not instof(target, tuple): target = (target, '')
                    else: target = (target[0], '?' + target[1])
                    resp = self._session.get('/api/class/%s.json%s' % target)
                    if resp.status_code == 200:
                        imdata = Struct.JSON2DATA(resp.text).imdata
                        wellform = L()
                        for im in imdata:
                            for key in im:
                                attr = im[key].attributes
                                attr['_model'] = key
                                wellform << attr
                        ret << wellform
                    else:
                        ret << None
                if len(targets) == 1: return ret[0]
                else: return ret
            return None

        def getCount(self, *targets):
            if self.connected:
                ret = L()
                for target in targets:
                    if not instof(target, tuple): target = (target, '')
                    else: target = (target[0], '&' + target[1])
                    resp = self._session.get(
                        '/api/class/%s.json?rsp-subtree-include=count%s' %
                        target)
                    if resp.status_code == 200:
                        ret << int(
                            json.loads(resp.text)['imdata'][0]['moCount']
                            ['attributes']['count'])
                    else:
                        ret << None
                if len(targets) == 1: return ret[0]
                else: return ret
            return None

        def getHealthHist(self):
            if self.connected:
                return M(
                    _tstamp=self._mng.healthmon.health._tstamp,
                    topology=self._mng.healthmon.health[self.domain].topology,
                    tenant=self._mng.healthmon.health[self.domain].tenant)
            return None

        def getHealthNow(self):
            if self.connected:
                ret = M(topology=M(), tenant=M())
                health_hist = self._mng.healthmon.health[self.domain]
                for dn in health_hist.topology:
                    ret.topology[dn] = health_hist.topology[dn][-1]
                for dn in health_hist.tenant:
                    ret.tenant[dn] = health_hist.tenant[dn][-1]
                return ret
            return None

        def getFault(self):
            if self.connected:
                ret = M(critical=L(), major=L(), minor=L(), warning=L())
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"critical")'
                )
                if resp.status_code == 200:
                    imdata = Struct.JSON2DATA(resp.text).imdata
                    for im in imdata:
                        for key in im:
                            attr = im[key].attributes
                            attr['_model'] = key
                            ret.critical << attr
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"major")'
                )
                if resp.status_code == 200:
                    imdata = Struct.JSON2DATA(resp.text).imdata
                    for im in imdata:
                        for key in im:
                            attr = im[key].attributes
                            attr['_model'] = key
                            ret.major << attr
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"minor")'
                )
                if resp.status_code == 200:
                    imdata = Struct.JSON2DATA(resp.text).imdata
                    for im in imdata:
                        for key in im:
                            attr = im[key].attributes
                            attr['_model'] = key
                            ret.minor << attr
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"warning")'
                )
                if resp.status_code == 200:
                    imdata = Struct.JSON2DATA(resp.text).imdata
                    for im in imdata:
                        for key in im:
                            attr = im[key].attributes
                            attr['_model'] = key
                            ret.warning << attr
                return ret
            return None

        def getFaultCount(self):
            if self.connected:
                ret = M()
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"critical")&rsp-subtree-include=count'
                )
                if resp.status_code == 200:
                    ret['critical'] = int(
                        json.loads(resp.text)['imdata'][0]['moCount']
                        ['attributes']['count'])
                else:
                    ret['critical'] = None
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"major")&rsp-subtree-include=count'
                )
                if resp.status_code == 200:
                    ret['major'] = int(
                        json.loads(resp.text)['imdata'][0]['moCount']
                        ['attributes']['count'])
                else:
                    ret['major'] = None
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"minor")&rsp-subtree-include=count'
                )
                if resp.status_code == 200:
                    ret['minor'] = int(
                        json.loads(resp.text)['imdata'][0]['moCount']
                        ['attributes']['count'])
                else:
                    ret['minor'] = None
                resp = self._session.get(
                    '/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"warning")&rsp-subtree-include=count'
                )
                if resp.status_code == 200:
                    ret['warning'] = int(
                        json.loads(resp.text)['imdata'][0]['moCount']
                        ['attributes']['count'])
                else:
                    ret['warning'] = None
                return ret
            return None

        def getEPTrack(self):
            if self.connected:
                return self.eptracker()
            return None
Ejemplo n.º 4
0
 class APIC(M):
     
     class APIC_CONNECTION_FAILED(E):
         def __init__(self, apic): E.__init__(self, 'Connection Failed %s@%s:%s' % (apic.user, str(apic.ips), apic.pwd))
          
     class ACITOOLKIT_CLASS_WRAPPER(object):
         
         class ACITOOLKIT_METHOD_WRAPPER:
             def __init__(self, apic, cls, key): self.apic = apic; self.cls = cls; self.key = key
             def __call__(self, *argv):
                 return getattr(self.cls, self.key)(self.apic._mo_session, *argv)
         
         def __init__(self, apic, cls):
             for key in cls.__dict__:
                 if re.search('^[_A-Za-z][A-Za-z]\w*', key):
                     if typeof(cls.__dict__[key]) == 'classmethod':
                         self.__setattr__(key, ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER.ACITOOLKIT_METHOD_WRAPPER(apic, cls, key))
         
     def __init__(self, mng, domain, ips, user, pwd):
         M.__init__(self, domain=domain, user=user, pwd=pwd)
         self._mng = mng
         sepkv = re.match('^[\d.:]+(?P<sep>[,/&|])', ips)
         if sepkv: self['ips'] = L(*ips.split(sepkv.group('sep')))
         else: self['ips'] = L(ips)
          
         #===================================================================
         # Connect APIC
         #===================================================================
         
         for ip in self.ips:
             self._session = acitool.Session('https://%s' % ip, user, pwd)
             resp = self._session.login()
             if resp.ok:
                 self._mo_session = acitool.Session('https://%s' % ip, user, pwd)
                 resp = self._mo_session.login()
                 if resp.ok:
                     self['connected'] = ip
                     self._url = 'https://%s/api/' % ip
                     self.eptracker = EPTracker(self)
                     self.healthmon = HealthMon(self)
                     break
                 else:
                     self._mo_session.close()
                     self._session.close()
             else:
                 self._session.close()
         else: raise ACIManager.APIC.APIC_CONNECTION_FAILED(self)
         
         for key in acitool.__dict__:
             if re.search('^[A-Z]+\w*', key):
                 self.__setattr__(key, ACIManager.APIC.ACITOOLKIT_CLASS_WRAPPER(self, acitool.__dict__[key]))
                 
     def __del__(self):
         self.healthmon.__del__()
         self.eptracker.__del__()
         self._mo_session.close()
         self._session.close()
         
     def get(self, *targets):
         if self.connected:
             ret = L()
             for target in targets:
                 if not instof(target, tuple): target = (target, '')
                 else: target = (target[0], '?' + target[1])
                 resp = self._session.get('/api/class/%s.json%s' % target)
                 if resp.status_code == 200:
                     imdata = Struct.JSON2DATA(resp.text).imdata
                     wellform = L()
                     for im in imdata:
                         for key in im:
                             attr = im[key].attributes
                             attr['_model'] = key
                             wellform << attr
                     ret << wellform
                 else: ret << None
             if len(targets) == 1: return ret[0]
             else: return ret
         return None
     
     def getCount(self, *targets):
         if self.connected:
             ret = L()
             for target in targets:
                 if not instof(target, tuple): target = (target, '')
                 else: target = (target[0], '&' + target[1])
                 resp = self._session.get('/api/class/%s.json?rsp-subtree-include=count%s' % target)
                 if resp.status_code == 200:
                     ret << int(json.loads(resp.text)['imdata'][0]['moCount']['attributes']['count'])
                 else: ret << None
             if len(targets) == 1: return ret[0]
             else: return ret
         return None
     
     def getHealthHist(self):
         if self.connected:
             return M(_tstamp=self._mng.healthmon.health._tstamp,
                      topology=self._mng.healthmon.health[self.domain].topology,
                      tenant=self._mng.healthmon.health[self.domain].tenant)
         return None
     
     def getHealthNow(self):
         if self.connected:
             ret = M(topology=M(), tenant=M())
             health_hist = self._mng.healthmon.health[self.domain]
             for dn in health_hist.topology: ret.topology[dn] = health_hist.topology[dn][-1]
             for dn in health_hist.tenant: ret.tenant[dn] = health_hist.tenant[dn][-1]
             return ret
         return None
     
     def getFault(self):
         if self.connected:
             ret = M(critical=L(), major=L(), minor=L(), warning=L())
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"critical")')
             if resp.status_code == 200:
                 imdata = Struct.JSON2DATA(resp.text).imdata
                 for im in imdata:
                     for key in im:
                         attr = im[key].attributes
                         attr['_model'] = key
                         ret.critical << attr
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"major")')
             if resp.status_code == 200:
                 imdata = Struct.JSON2DATA(resp.text).imdata
                 for im in imdata:
                     for key in im:
                         attr = im[key].attributes
                         attr['_model'] = key
                         ret.major << attr
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"minor")')
             if resp.status_code == 200:
                 imdata = Struct.JSON2DATA(resp.text).imdata
                 for im in imdata:
                     for key in im:
                         attr = im[key].attributes
                         attr['_model'] = key
                         ret.minor << attr
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"warning")')
             if resp.status_code == 200:
                 imdata = Struct.JSON2DATA(resp.text).imdata
                 for im in imdata:
                     for key in im:
                         attr = im[key].attributes
                         attr['_model'] = key
                         ret.warning << attr
             return ret
         return None
     
     def getFaultCount(self):
         if self.connected:
             ret = M()
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"critical")&rsp-subtree-include=count')
             if resp.status_code == 200: ret['critical'] = int(json.loads(resp.text)['imdata'][0]['moCount']['attributes']['count'])
             else: ret['critical'] = None
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"major")&rsp-subtree-include=count')
             if resp.status_code == 200: ret['major'] = int(json.loads(resp.text)['imdata'][0]['moCount']['attributes']['count'])
             else: ret['major'] = None
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"minor")&rsp-subtree-include=count')
             if resp.status_code == 200: ret['minor'] = int(json.loads(resp.text)['imdata'][0]['moCount']['attributes']['count'])
             else: ret['minor'] = None
             resp = self._session.get('/api/class/faultInfo.json?query-target-filter=eq(faultInfo.severity,"warning")&rsp-subtree-include=count')
             if resp.status_code == 200: ret['warning'] = int(json.loads(resp.text)['imdata'][0]['moCount']['attributes']['count'])
             else: ret['warning'] = None
             return ret
         return None
     
     def getEPTrack(self):
         if self.connected:
             return self.eptracker()
         return None