示例#1
0
class ZenDeviceUuidFinder():
    '''
    This class returns the name and UUID of a device when
    provided a query
    '''
    def __init__(self, query):
        self.router = 'DeviceRouter'
        self.method = 'getDeviceUuidsByName'
        self.query = query
        self.uuid = None
        self.data = {'query': self.query}
        self.api_call = ZenAPIConnector(self.router, self.method, self.data)
        self.response = self.api_call.send()
        self.response_json = self.response.json()
        self.count = len(self.response_json['result']['data'])

    def getFirstUuid(self):
        try:
            return self.response_json['result']['data'][0]['uuid']
        except (KeyError, TypeError):
            return None

    def getAllUuids(self):
        try:
            return [x['uuid'] for x in self.response_json['result']['data']]
        except (KeyError, TypeError):
            return None

    def getCount(self):
        return self.count

    def first(self):
        return self.getFirstUuid()
示例#2
0
 def checkJobStatus(self, jobid):
     self.method = 'getInfo'
     self.data = {'jobid': jobid}
     api = ZenAPIConnector(self.router, self.method, self.data)
     result = api.send()
     try:
         status = result.json()['result']['data']['status']
     except (KeyError, ValueError):
         status = 'UNKNOWN! Invalid Job ID or other failure'
     return status
示例#3
0
class ZenDeviceUidFinder():
    '''
    This class returns the name and UID (path) of a device when
    provided a query
    '''
    def __init__(self, name=None, ip=None):
        self.router = 'DeviceRouter'
        self.method = 'getDevices'
        self.params = {}
        if name is not None:
            self.params['name'] = name
        if ip is not None:
            self.params['ipAddress'] = ip
        self.data = {'params': self.params}
        self.api_call = ZenAPIConnector(self.router,
                                        self.method,
                                        self.data)
        self.response = self.api_call.send()
        self.response_json = self.response.json()
        self.count = len(self.response_json['result']['devices'])

    def getFirstUid(self):
        try:
            return self.response_json['result']['devices'][0]['uid']
        except (KeyError, TypeError):
            return None

    def getAllUids(self):
        try:
            return [x['uid'] for x in self.response_json['result']['devices']]
        except (KeyError, TypeError):
            return None

    def getCount(self):
        return self.count

    def first(self):
        return self.getFirstUid()