Changeset 191
- Timestamp:
- 07/30/12 23:48:21 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r190 r191 320 320 321 321 class EtherWebSocketHandler(DebugMixIn, BasicAuthMixIn, WebSocketHandler): 322 IFTYPE = 'server' 323 322 324 def __init__(self, app, req, switch, htpasswd=None, debug=False): 323 325 super(EtherWebSocketHandler, self).__init__(app, req) … … 326 328 self._debug = debug 327 329 328 @classmethod329 def get_type(cls):330 return 'server'331 332 330 def get_target(self): 333 331 return self.request.remote_ip … … 348 346 349 347 class TapHandler(DebugMixIn): 348 IFTYPE = 'tap' 350 349 READ_SIZE = 65535 351 350 … … 356 355 self._debug = debug 357 356 self._tap = None 358 359 @classmethod360 def get_type(cls):361 return 'tap'362 357 363 358 def get_target(self): … … 416 411 417 412 class EtherWebSocketClient(DebugMixIn): 413 IFTYPE = 'client' 414 418 415 def __init__(self, ioloop, switch, url, ssl_=None, cred=None, debug=False): 419 416 self._ioloop = ioloop … … 429 426 auth = ['Authorization: Basic %s' % token] 430 427 self._options['header'] = auth 431 432 @classmethod433 def get_type(cls):434 return 'client'435 428 436 429 def get_target(self): … … 495 488 class EtherWebSocketControlHandler(DebugMixIn, BasicAuthMixIn, RequestHandler): 496 489 NAMESPACE = 'etherws.control' 497 I NTERFACES = {498 TapHandler. get_type(): TapHandler,499 EtherWebSocketClient. get_type(): EtherWebSocketClient,490 IFTYPES = { 491 TapHandler.IFTYPE: TapHandler, 492 EtherWebSocketClient.IFTYPE: EtherWebSocketClient, 500 493 } 501 494 … … 540 533 target = p['target'] 541 534 options = getattr(self, '_optparse_' + type_)(p.get('options', {})) 542 klass = self.I NTERFACES[type_]535 klass = self.IFTYPES[type_] 543 536 interface = klass(self._ioloop, self._switch, target, **options) 544 537 portnum = interface.open() … … 577 570 return { 578 571 'port': port.number, 579 'type': port.interface. get_type(),572 'type': port.interface.IFTYPE, 580 573 'target': port.interface.get_target(), 581 574 'tx': port.tx, … … 735 728 736 729 def handle_ctl_addport(args): 737 raise NotImplementedError('addport') 730 params = [{ 731 'type': args.type, 732 'target': args.target, 733 'options': { 734 'instance': args.insecure, 735 'cacerts': args.cacerts, 736 'user': args.user, 737 'passwd': args.passwd, 738 } 739 }] 740 res = request(args, 'addPort', params) 741 print(yaml.safe_dump(res)) 738 742 739 743 def handle_ctl_shutport(args): … … 790 794 791 795 parser_c_ap = control_method.add_parser('addport') 796 parser_c_ap.add_argument( 797 'type', choices=EtherWebSocketControlHandler.IFTYPES.keys()) 792 798 parser_c_ap.add_argument('target') 793 799 parser_c_ap.add_argument('--insecure', action='store_true', default=False)
Note: See TracChangeset
for help on using the changeset viewer.