def __init__(self, stdin=sys.stdin, foreground=True): self.bridge = None # default bridge self.ipt = IPtables() self.nss = NameSpaces() self.dvr = DVR() if foreground: self.prompt = color_str(PROMPT_KW, 'g') self.stdin = stdin self.in_poller = poll() self.in_poller.register(stdin) Cmd.__init__(self) output("***\n Welcome to EasyOVS %s, " "type help to see available cmds.\n***\n" % VERSION) info('*** Starting CLI:\n') debug("==Loading credentials==\n") debug("auth_url = %s\n" % os.getenv('OS_AUTH_URL') or cfg.CONF.OS.auth_url) debug("username = %s\n" % os.getenv('OS_USERNAME') or cfg.CONF.OS.username) passwd = os.getenv('OS_PASSWORD') or cfg.CONF.OS.password passwd = passwd[:len(passwd) / 4] + "****" + passwd[-len(passwd) / 4:] debug("password = %s\n" % passwd) debug("tenant_name = %s\n" % os.getenv('OS_TENANT_NAME') or cfg.CONF.OS.tenant_name) while True: try: #if self.isatty(): #quietRun( 'stty sane' ) self.cmdloop() break except KeyboardInterrupt: info('\nInterrupt\n')
def __init__(self, node='compute'): """ :param node: on computer node or network node """ self.node = node self.br_int = Bridge('br-int') self.nss = NameSpaces()
def __init__(self, ns=None): self.valid_tables = ['raw', 'nat', 'filter', 'mangle', 'security'] self.tables = {} self.nss = NameSpaces() self.ns = ns for tb in self.valid_tables: self.tables[tb] = IPtable(tb, ns) self._load(ns=self.ns)
def do_ipt(self, arg): """ Show the iptables rules, e.g., ipt vm vm1,vm2 ipt show nat,raw,filter [INPUT] ipt check nat,raw,filter """ args = arg.split() if len(args) < 1 or len(args) > 3: # only 1-3 is valid warn("Not correct parameters, use as:\n") warn("ipt vm vm_ip\n") warn("ipt show|check [filter] [INPUT]\n") return cmd = args[0] if not hasattr(self.ipt, '%s' % cmd): error('Unsupported cmd=%s\n' % cmd) return if cmd == 'vm': if len(args) == 1: error('No vm ip is given\n') return else: for vm_ip in args[1:]: debug('run self.ipt.%s(%s)\n' % (cmd, vm_ip)) getattr(self.ipt, '%s' % cmd)(vm_ip) elif cmd in ['check', 'show']: ns = None if args[-1] in NameSpaces().get_ids(): ns = args.pop() if len(args) == 1: # show debug('run self.ipt.%s(ns=%s)\n' % (cmd, ns)) getattr(self.ipt, '%s' % cmd)(ns=ns) return elif len(args) == 2: # filter|INPUT if args[1] in self.ipt.get_valid_tables(): # filter debug('run self.ipt.%s(table=%s,ns=%s)\n' % (cmd, args[1], ns)) getattr(self.ipt, '%s' % cmd)(table=args[1], ns=ns) else: # INPUT debug('run self.ipt.%s(chain=%s, ns=%s)\n' % (cmd, args[1], ns)) getattr(self.ipt, '%s' % cmd)(chain=args[1], ns=ns) elif len(args) == 3: if args[1] in self.ipt.get_valid_tables(): # filter INPUT debug('run self.ipt.%s(table=%s, chain=%s, ns=%s\n)' % (cmd, args[1], args[2], ns)) getattr(self.ipt, '%s' % cmd)(table=args[1], chain=args[2], ns=ns) else: warn("Unknown table, table=%s\n" % args[1])