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_router(self, order):
     "Return data for one mtrouter as Python dict"
     routers = self._list()['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 #3
0
 def get_filter(self, fid):
     "Return data for one filter as Python dict"
     filters = self._list()['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 #4
0
 def simple_httpccm_action(self, telnet, 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')
         return JsonResponse({'name': cid})
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown HTTP Connector: %s' % cid)
     else:
         raise ActionFailed(telnet.match.group(1))
Example #5
0
	def simple_group_action(self, action, gid):
		self.telnet.sendline('group -%s %s' % (action, gid))
		matched_index = self.telnet.expect([
			r'.+Successfully(.+)' + STANDARD_PROMPT,
			r'.+Unknown Group: (.+)' + STANDARD_PROMPT,
			r'.+(.*)' + STANDARD_PROMPT,
		])
		if matched_index == 0:
			self.telnet.sendline('persist\n')
			return {'name': gid}
		elif matched_index == 1:
			raise ObjectNotFoundError('Unknown group: %s' % gid)
		else:
			raise ActionFailed(self.telnet.match.group(1))
 def simple_smppccm_action(self, action, cid):
     self.telnet.sendline('smppccm -%s %s' % (action, cid))
     matched_index = self.telnet.expect([
         r'.+Successfully(.+)' + STANDARD_PROMPT,
         r'.+Unknown connector: (.+)' + STANDARD_PROMPT,
         r'(.*)' + STANDARD_PROMPT,
     ])
     if matched_index == 0:
         self.telnet.sendline('persist\n')
         return {'name': cid}
     elif matched_index == 1:
         raise ObjectNotFoundError('Unknown SMPP Connector: %s' % cid)
     else:
         raise ActionFailed(self.telnet.match.group(1))
Example #7
0
 def retrieve(self, cid):
     """Retreive data for one connector
     Required parameter: cid (connector id)"""
     connector = self.get_httpccm(cid, silent=False)
     connector_list = self.get_connector_list()
     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 {'connector': connector}
Example #8
0
 def get_httpccm(self, telnet, cid, silent=False):
     #Some of this could be abstracted out - similar pattern in users.py
     telnet.sendline('httpccm -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)
     httpccm = {}
     for line in result.splitlines():
         d = [x for x in line.split() if x]
         if len(d) == 2:
             httpccm[d[0]] = d[1]
     return httpccm