示例#1
0
    def test_get_network_range_from_cidr_ipv6(self):

        print(inspect.currentframe().f_code.co_name + '[IPv4]')

        cidr = '192.168.79.0/24'
        res = utils.Utils().get_network_range_from_cidr_ipv6(cidr)
        print(res)
        print(str(res['network']))
        print(str(res['broadcast']))

        network_bin = struct.unpack(
                '!i', socket.inet_aton(str(res['network'])))[0]
        broadcast_bin = struct.unpack(
                '!i', socket.inet_aton(str(res['broadcast'])))[0]

        print(network_bin)
        print(broadcast_bin)

        print(socket.inet_ntoa(struct.pack(r'!i', (network_bin))))
        print(socket.inet_ntoa(struct.pack(r'!i', (broadcast_bin))))

        # Assertion
        self.assertGreaterEqual(len(res), 1)

        print(inspect.currentframe().f_code.co_name + '[IPv6]')

        cidr = 'dead:beef::3/48'
        res = utils.Utils().get_network_range_from_cidr_ipv6(cidr)
        print(res)
        print(str(res['network']))
        print(str(res['broadcast']))

        # Assertion
        self.assertGreaterEqual(len(res), 1)
示例#2
0
    def test_get_subnet_mask_from_cidr_ipv6(self):

        print(inspect.currentframe().f_code.co_name + '[IPv4]')
        cidr = '192.168.79.0/24'
        res = utils.Utils().get_subnet_mask_from_cidr_ipv6(cidr)
        print(type(res))
        print(res)

        print(inspect.currentframe().f_code.co_name + '[IPv6]')
        cidr = 'dead:beef::3/48'
        res = utils.Utils().get_subnet_mask_from_cidr_ipv6(cidr)
        print(type(res))
        print(res)
示例#3
0
    def test_get_ipaddress_version(self):

        print(inspect.currentframe().f_code.co_name + '[IPv4]')
        res = utils.Utils().get_ipaddress_version('192.168.0.1')
        print(type(res))
        print(res)

        # Assertion
        self.assertEqual(res, utils.Utils().IP_VER_V4)

        print(inspect.currentframe().f_code.co_name + '[IPv6]')
        res = utils.Utils().get_ipaddress_version('dead:beef::2')
        print(type(res))
        print(res)

        # Assertion
        self.assertEqual(res, utils.Utils().IP_VER_V6)
示例#4
0
    def __init__(self, request_id='-'):
        self.job_config = config.JobConfig()
        self.logger = logger.LibLogger(self.job_config, request_id)
        self.utils = utils.Utils()
        self.log_deco_line = self.job_config.LOG_DECORATE_LINE

        self.nal_endpoint_config = self.get_config('nal_ep')
        self.nal_config = self.get_config('nal_conf')
        self.nal_endpoint_config.update(self.get_config('wim_ep'))
        self.nal_config.update(self.get_config('wim_conf'))
示例#5
0
    def test_get_ipmask_from_cidr_ip(self):

        cidr = '192.168.79.0/24'

        res = utils.Utils().get_ipmask_from_cidr_ip(cidr)
        print(inspect.currentframe().f_code.co_name)
        pprint(res)

        # Assertion
        self.assertGreaterEqual(len(res), 1)
示例#6
0
    def test_get_network_range_from_cidr(self):

        cidr = '192.168.79.0/24'

        res = utils.Utils().get_network_range_from_cidr(cidr)
        print(inspect.currentframe().f_code.co_name)
        pprint(res)
        print(socket.inet_ntoa(struct.pack(r'!i', (res['network']))))
        print(socket.inet_ntoa(struct.pack(r'!i', (res['broadcast']))))

        # Assertion
        self.assertGreaterEqual(len(res), 1)
示例#7
0
文件: base.py 项目: openmsa/NO
    def __init__(self,
                 api_config_instance,
                 endpoint_name,
                 nal_endpoint_config,
                 pod_id,
                 dc_id='system'):

        self.config = api_config_instance
        self.logger = logger.LibLogger(api_config_instance)
        self.utils = utils.Utils()

        user_name = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['user_id']
        user_pass = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['user_password']
        endpoint_url = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['endpoint']
        msa_class_name = \
            nal_endpoint_config[dc_id]['msa'][pod_id][endpoint_name]

        # Set ENDPOINT
        endpoint = endpoint_url.replace('%MSA_CLASS_NAME%', msa_class_name)

        # Set WSDL
        wsdl = endpoint + 'WSDL=' + msa_class_name

        # Output Log(SoapClient Input Parameters)
        log_params = {
            'wsdl': wsdl,
            'username': user_name,
            'password': self.config.LOG_PASSWORD_MASK
        }
        self.output_log_soap_params('in', __name__, '__init__', log_params)

        if self.config.ENV == self.config.ENV_DEV:

            # Create Instance(Stub(MSA))
            module = importlib.import_module(self.STUB_MSA_PACKAGE_PATH +
                                             msa_class_name)
            class_attr = getattr(module, msa_class_name)
            self.soap_client = class_attr(api_config_instance)

        else:

            # Create Instance(SoapClient(MSA))
            ssl._create_default_https_context = ssl._create_unverified_context
            module = importlib.import_module(self.SOAP_PACKAGE_PATH)
            class_attr = getattr(module, self.SOAP_CLASS_NAME)
            self.soap_client = class_attr(wsdl,
                                          username=user_name,
                                          password=user_pass).service
示例#8
0
文件: baserest.py 项目: openmsa/NO
    def __init__(self,
                 api_config_instance,
                 nal_endpoint_config,
                 pod_id,
                 dc_id='system'):

        self.config = api_config_instance
        self.utils = utils.Utils()
        self.rest = rest.MsaRest(api_config_instance)

        user_name = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['user_id']
        user_pass = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['user_password']
        endpoint_url = \
            nal_endpoint_config[dc_id]['msa'][pod_id]['rest_endpoint']

        # Set Auth Info
        self.auth_info = {'id': user_name, 'pass': user_pass}

        # Set ENDPOINT
        self.endpoint = endpoint_url
示例#9
0
    def test_get_ipaddress_compressed_paloalto_vm(self):

        print(inspect.currentframe().f_code.co_name + '[IPv4]')
        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                                    '192.168.0.1')
        print(res)
        self.assertEqual(res, '192.168.0.1')

        print(inspect.currentframe().f_code.co_name + '[IPv6]')
        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                                    'DEAD:BEEF::2')
        print(res)
        self.assertEqual(res, 'dead:beef::2')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                                    'DEAD:BEEF::0')
        print(res)
        self.assertEqual(res, 'dead:beef::')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:260:88:0:80:3eff:fe5a:8ac9')
        print(res)
        self.assertEqual(res, '2001:260:88::80:3eff:fe5a:8ac9')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:260:88:0:0:3eff:fe5a:8ac9')
        print(res)
        self.assertEqual(res, '2001:260:88::3eff:fe5a:8ac9')

        res = utils.Utils().get_ipaddress_compressed(
                                    '2001:260:88:0:0000:3eff:fe5a:8ac9')
        print(res)
        self.assertEqual(res, '2001:260:88::3eff:fe5a:8ac9')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:260:88:0:0:0:fe5a:8ac9')
        print(res)
        self.assertEqual(res, '2001:260:88::fe5a:8ac9')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:260:88:0:1:0:0:0')
        print(res)
        self.assertEqual(res, '2001:260:88::1::')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:260:88:0:0:1:0:0')
        print(res)
        self.assertEqual(res, '2001:260:88::1::')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:0:0:1:0:0:0:1')
        print(res)
        self.assertEqual(res, '2001:::1::1')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:0:0:1:0:0:0:0')
        print(res)
        self.assertEqual(res, '2001:::1::')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:0:0:0:1:0:0:8ac9')
        print(res)
        self.assertEqual(res, '2001::1:::8ac9')

        res = utils.Utils().get_ipaddress_compressed_paloalto_vm(
                                    '2001:0:0:0:1:0:0:0')
        print(res)
        self.assertEqual(res, '2001::1:::')
示例#10
0
文件: base.py 项目: openmsa/NO
 def __init__(self, api_config_instance):
     self.utils = utils.Utils()
     self.rest = rest.OscRest(api_config_instance)
     self.char_code = api_config_instance.CHAR_SET