def create(self, request): """Create a group. One POST parameter required, the group identifier (a string) --- # YAML omit_serializer: true parameters: - name: gid description: Group identifier required: true type: string paramType: form """ telnet = request.telnet telnet.sendline('group -a') telnet.expect(r'Adding a new Group(.+)\n' + INTERACTIVE_PROMPT) if not 'gid' in request.data: raise MissingKeyError('Missing gid (group identifier)') telnet.sendline('gid ' + request.data['gid'] + '\n') telnet.expect(INTERACTIVE_PROMPT) telnet.sendline('ok\n') matched_index = telnet.expect([ r'.+Successfully added(.+)\[(.+)\][\n\r]+' + STANDARD_PROMPT, r'.+Error: (.+)[\n\r]+' + INTERACTIVE_PROMPT, r'.+(.*)(' + INTERACTIVE_PROMPT + '|' + STANDARD_PROMPT + ')', ]) if matched_index == 0: gid = telnet.match.group(2).strip() telnet.sendline('persist\n') return JsonResponse({'name': gid}) else: raise ActionFailed(telnet.match.group(1))
def create(self, request): """Create an SMPP Client Connector. Required parameter: cid (connector id) --- # YAML omit_serializer: true parameters: - name: cid description: Connector identifier required: true type: string paramType: form """ telnet = request.telnet telnet.sendline('smppccm -a') telnet.expect(r'Adding a new connector(.+)\n' + INTERACTIVE_PROMPT) updates = request.data if not 'cid' in request.data: raise MissingKeyError('Missing cid (connector identifier)') set_ikeys(telnet, {"cid": request.data["cid"]}) telnet.sendline('persist\n') telnet.expect(r'.*' + STANDARD_PROMPT) if settings.JASMIN_DOCKER or settings.JASMIN_K8S: sync_conf_instances(request.telnet_list) return JsonResponse({'cid': request.data['cid']})
def create(self, request): """Create a group. One POST parameter required, the group identifier (a string) --- # YAML omit_serializer: true parameters: - name: gid description: Group identifier required: true type: string paramType: form """ telnet = request.telnet telnet.sendline('group -a') telnet.expect(r'Adding a new Group(.+)\n' + INTERACTIVE_PROMPT) if not 'gid' in request.data: raise MissingKeyError('Missing gid (group identifier)') set_ikeys(telnet, {"gid": request.data["gid"]}) telnet.sendline('persist') telnet.expect(r'.*' + STANDARD_PROMPT) if settings.JASMIN_DOCKER or settings.JASMIN_K8S: sync_conf_instances(request.telnet_list) return JsonResponse({'name': request.data["gid"]})
def create(self, request): """Create a User. Required parameters: username, password, uid (user identifier), gid (group identifier), --- # YAML omit_serializer: true parameters: - name: uid description: Username identifier required: true type: string paramType: form - name: gid description: Group identifier required: true type: string paramType: form - name: username description: Username required: true type: string paramType: form - name: password description: Password required: true type: string paramType: form """ telnet = request.telnet data = request.data try: uid, gid, username, password = \ data['uid'], data['gid'], data['username'], data['password'] except Exception: raise MissingKeyError( 'Missing parameter: uid, gid, username and/or password required' ) telnet.sendline('user -a') telnet.expect(r'Adding a new User(.+)\n' + INTERACTIVE_PROMPT) set_ikeys(telnet, { 'uid': uid, 'gid': gid, 'username': username, 'password': password }) telnet.sendline('persist\n') telnet.expect(r'.*' + STANDARD_PROMPT) if settings.JASMIN_DOCKER or settings.JASMIN_K8S: sync_conf_instances(request.telnet_list) return JsonResponse({'user': self.get_user(telnet, uid)})
def create(self, request): """Create Filter. Required parameters: type, fid, parameters --- # YAML omit_serializer: true parameters: - name: type description: One of TransparentFilter, ConnectorFilter, UserFilter, GroupFilter, SourceAddrFilter, DestinationAddrFilter, ShortMessageFilter, DateIntervalFilter, TimeIntervalFilter, TagFilter, EvalPyFilter required: true type: string paramType: form - name: fid description: Filter id, used to identify filter required: true type: string paramType: form - name: parameter description: Parameter required: false type: string paramType: form """ telnet = request.telnet data = request.data try: ftype, fid = data['type'], data['fid'] except IndexError: raise MissingKeyError( 'Missing parameter: type or fid required') ftype = ftype.lower() telnet.sendline('filter -a') telnet.expect(r'Adding a new Filter(.+)\n' + INTERACTIVE_PROMPT) ikeys = OrderedDict({'type': ftype, 'fid': fid}) if ftype != 'transparentfilter': try: parameter = data['parameter'] except MultiValueDictKeyError: raise MissingKeyError('%s filter requires parameter' % ftype) if ftype == 'connectorfilter': ikeys['cid'] = parameter elif ftype == 'userfilter': ikeys['uid'] = parameter elif ftype == 'groupfilter': ikeys['gid'] = parameter elif ftype == 'sourceaddrfilter': ikeys['source_addr'] = parameter elif ftype == 'destinationaddrfilter': ikeys['destination_addr'] = parameter elif ftype == 'shortmessagefilter': ikeys['short_message'] = parameter elif ftype == 'dateintervalfilter': ikeys['dateInterval'] = parameter elif ftype == 'timeintervalfilter': ikeys['timeInterval'] = parameter elif ftype == 'tagfilter': ikeys['tag'] = parameter elif ftype == 'evalpyfilter': ikeys['pyCode'] = parameter set_ikeys(telnet, ikeys) telnet.sendline('persist\n') telnet.expect(r'.*' + STANDARD_PROMPT) if settings.JASMIN_DOCKER or settings.JASMIN_K8S: sync_conf_instances(request.telnet_list) return JsonResponse({'filter': self.get_filter(telnet, fid)})
def create(self, request): """Create MTRouter. Required parameters: type, order, smppconnectors, httpconnectors More than one connector is allowed only for RandomRoundrobinMTRoute --- # YAML omit_serializer: true parameters: - name: type description: One of DefaultRoute, StaticMTRoute, RandomRoundrobinMTRoute required: true type: string paramType: form - name: order description: Router order, also used to identify router required: true type: string paramType: form - name: rate description: Router rate, may be zero for free required: true type: float paramType: form - name: smppconnectors description: List of SMPP connector ids. required: false type: array paramType: form - name: httpconnectors description: List of HTTP connector ids. required: false type: array paramType: form - name: filters description: List of filters, required except for DefaultRoute required: false type: array paramType: form """ data = request.data try: rtype, order, rate = data['type'], data['order'], data['rate'] except IndexError: raise MissingKeyError('Missing parameter: type or order required') rtype = rtype.lower() ikeys = OrderedDict({'type': rtype}) if rtype != 'defaultroute': try: filters = data['filters'].split(',') except MultiValueDictKeyError: raise MissingKeyError('%s router requires filters' % rtype) ikeys['filters'] = ';'.join(filters) ikeys['order'] = order smppconnectors = data.get('smppconnectors', '') httpconnectors = data.get('httpconnectors', '') connectors = [ 'smppc(%s)' % c.strip() for c in smppconnectors.split(',') if c.strip() ] + ['http(%s)' % c for c in httpconnectors.split(',') if c.strip()] if rtype == 'randomroundrobinmtroute': if len(connectors) < 2: raise MutipleValuesRequiredKeyError( 'Round Robin route requires at least two connectors') ikeys['connectors'] = ';'.join(connectors) else: if len(connectors) != 1: raise MissingKeyError('one and only one connector required') ikeys['connector'] = connectors[0] ikeys['rate'] = rate for telnet in request.telnet_list: telnet.sendline('mtrouter -a') telnet.expect(r'Adding a new MT Route(.+)\n' + INTERACTIVE_PROMPT) set_ikeys(telnet, ikeys) telnet.sendline('persist\n') telnet.expect(r'.*' + STANDARD_PROMPT) return JsonResponse( {'mtrouter': self.get_router(request.telnet_list[0], order)})