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) return JsonResponse({'user': self.get_user(telnet, uid)})
def create(self, data): """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 """ try: rtype, order, rate = data['type'], data['order'], data['rate'] except IndexError: raise MissingKeyError( 'Missing parameter: type or order required') rtype = rtype.lower() self.telnet.sendline('mtrouter -a') self.telnet.expect(r'Adding a new MT Route(.+)\n' + INTERACTIVE_PROMPT) 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 print ikeys set_ikeys(self.telnet, ikeys) self.telnet.sendline('persist\n') self.telnet.expect(r'.*' + STANDARD_PROMPT) return {'mtrouter': self.get_router(order)}
def create(self, data): """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 """ try: ftype, fid = data['type'], data['fid'] except IndexError: raise MissingKeyError('Missing parameter: type or fid required') ftype = ftype.lower() self.telnet.sendline('filter -a') self.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 print ikeys set_ikeys(self.telnet, ikeys) self.telnet.sendline('persist\n') self.telnet.expect(r'.*' + STANDARD_PROMPT) return {'filter': self.get_filter(fid)}