Beispiel #1
0
    def nat64(self, **kwargs):
        '''
            nat64 getter and setter
            format:
                {
                    "enable": True,
                    "ipv6": "64:ff9b::",
                    "ipv6_prefix": 96,
                    "ipv4": "0.0.0.0"
                }
        '''
        import libs.login
        if False == libs.login.cklogin():
            raise _.HTTPRedirect('/')

        import ml_w_nat64 as nat64
        import json
        import libs.tools
        if "nat64" in kwargs:
            # setter
            res = {"enable": "enable" in kwargs,
                   "ipv6": kwargs["ipv6"],
                   "ipv6_prefix": kwargs["ipv6_prefix"],
                   "ipv4": kwargs["ipv4"]}

            res = nat64.set(user = self.getUser(), cfg = res)
            if False == res[0]:
                return json.dumps([res[0], libs.tools.translateMessage(res[1])])
            else:
                return json.dumps(res)
        else:
            # getter
            return json.dumps(nat64.get())
	def test_nat64_g02(self):
		""" nat64_g02 """
		nat64 = {
			"enable": True,
			"ipv6": "64:ff9b::",
			"ipv6_prefix": 96,
			"ipv4": "0.0.0.0"
		}
		self.maxDiff = None
		e = ml_w_nat64.set(None, nat64)
		self.assertTrue(e[0], e[1])
		f = open(os.path.join("running", "nat64.txt"), "r")
		e = f.readlines()
		f.close()
		if "json" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['{"br": [{"STP": true, "name": "s0b1", "hello_time": 5, "interface": ["s0e2"], "max_message_age": 5, "forward_delay": 5}]}'])
		if "jcfg" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['nat64 {\n', '    enable True\n', '}\n'])
			def run(self):
				e = ml_w_nat64.set(None, nat64, threading.RLock())