Example #1
0
 def get_user(self, telnet, uid, silent=False):
     """Gets a single users data
     silent supresses Http404 exception if user not found"""
     telnet.sendline('user -s ' + uid)
     matched_index = telnet.expect([
         r'.+Unknown User:.*' + STANDARD_PROMPT,
         r'.+Usage: user.*' + STANDARD_PROMPT,
         r'(.+)\n' + STANDARD_PROMPT,
     ])
     if matched_index != 2:
         if silent:
             return
         else:
             raise ObjectNotFoundError('Unknown user: %s' % uid)
     result = telnet.match.group(1)
     user = {}
     for line in [l for l in result.splitlines() if l][1:]:
         d = [x for x in line.split() if x]
         if len(d) == 2:
             user[d[0]] = d[1]
         elif len(d) == 4:
             # Not DRY, could be more elegant
             if not d[0] in user:
                 user[d[0]] = {}
             if not d[1] in user[d[0]]:
                 user[d[0]][d[1]] = {}
             if not d[2] in user[d[0]][d[1]]:
                 user[d[0]][d[1]][d[2]] = {}
             user[d[0]][d[1]][d[2]] = d[3]
         # each line has two or four lines so above exhaustive
     return user
Example #2
0
 def get_filter(self, telnet, fid):
     "Return data for one filter as Python dict"
     filters = self._list(telnet)['filters']
     try:
         return {'filter':
             next((m for m in filters if m['fid'] == fid), None)
         }
     except StopIteration:
         raise ObjectNotFoundError('No Filter with fid: %s' % fid)
Example #3
0
 def get_router(self, telnet, order):
     "Return data for one mtrouter as Python dict"
     routers = self._list(telnet)['mtrouters']
     try:
         return {'mtrouter':
             next((m for m in routers if m['order'] == order), None)
         }
     except StopIteration:
         raise ObjectNotFoundError('No MTRouter with order: %s' % order)
Example #4
0
 def simple_group_action(self, telnet, action, gid):
     telnet.sendline('group -%s %s' % (action, gid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown Group: (.+)' + STANDARD_PROMPT,
         r'.+(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         return JsonResponse({'name': gid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown group: %s' % gid)
     else:
         raise ActionFailed(telnet.match.group(1))
Example #5
0
 def simple_smppccm_action(self, telnet, action, cid):
     telnet.sendline('smppccm -%s %s' % (action, cid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown connector: (.+)' + STANDARD_PROMPT,
         r'(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         return JsonResponse({'name': cid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown SMPP Connector: %s' % cid)
     else:
         raise ActionFailed(telnet.match.group(1))
Example #6
0
 def retrieve(self, request, cid):
     """Retreive data for one connector
     Required parameter: cid (connector id)"""
     telnet = request.telnet_list[0]
     connector = self.get_httpccm(telnet, cid, silent=False)
     connector_list = self.get_connector_list(telnet)
     list_data = next(
         (raw_data
          for raw_data in connector_list if raw_data[0] == '#' + cid), None)
     if not list_data:
         raise ObjectNotFoundError('Unknown connector: %s' % cid)
     connector.update(cid=cid,
                      type=list_data[1],
                      method=list_data[2],
                      url=list_data[3])
     return JsonResponse({'connector': connector})
Example #7
0
 def simple_httpccm_action(self, telnet, telnet_list, action, cid):
     telnet.sendline('httpccm -%s %s' % (action, cid))
     matched_index = telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown connector: (.+)' + STANDARD_PROMPT,
         r'(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         telnet.sendline('persist\n')
         if settings.JASMIN_DOCKER or settings.JASMIN_K8S:
             sync_conf_instances(telnet_list)
         return JsonResponse({'name': cid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown HTTP Connector: %s' % cid)
     else:
         raise ActionFailed(telnet.match.group(1))
Example #8
0
 def get_smppccm(self, telnet, cid, silent=False):
     # Some of this could be abstracted out - similar pattern in users.py
     telnet.sendline('smppccm -s ' + cid)
     matched_index = telnet.expect([
         r'.+Unknown connector:.*' + STANDARD_PROMPT,
         r'.+Usage:.*' + STANDARD_PROMPT,
         r'(.+)\n' + STANDARD_PROMPT,
     ])
     if matched_index != 2:
         if silent:
             return
         else:
             raise ObjectNotFoundError('Unknown connector: %s' % cid)
     result = telnet.match.group(1)
     smppccm = {}
     for line in result.splitlines():
         d = [x for x in line.split() if x]
         if len(d) == 2:
             smppccm[d[0]] = d[1]
     return smppccm