예제 #1
0
파일: epi_3_1.py 프로젝트: 18782967131/test
    def va_get_epi_interface(self, *args, **kwargs):
        """
        Method to get interface of epi
        param      : kwargs : dict
                     epi : object | uuid | hostname of epi
        return (List): a list like this
        [
            Intf(NAME='fabric-intf', IP='10.0.0.96', MAC='0:c:29:d9:5:eb', ID='0x600', STATE='Up/Up'), 
            Intf(NAME='south-intf', IP='0.0.0.0', MAC='0:c:29:d9:5:9', ID='0x603', STATE='Up/Up')
        ]
        example    : intf_info = va_get_epi_interface(epi='2-6')
                   : intf_info = va_get_epi_interface(epi=epi_1)
                     for intf in intf_info:
                        name = intf.NAME ##: -- Get detailed info, such as name, ip if you need
                        ip   = intf.IP
                        ...
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if 'epi' not in kwargs:
            raise ValueError(" epi is mandatory parameter!\n")
        epi = kwargs.get('epi')
        if isinstance(epi, Delegator):
            if epi._resource.get_nodetype() == 'epi':
                epi_obj = epi
                epi = self.va_get_epi_uuid(epi_obj=epi_obj)

        cmd = 'show chassis epi {} interface'.format(epi)
        output = self._access.va_cli(cmd)

        return (self._va_parse_epi_interface(output))
예제 #2
0
파일: epi_3_1.py 프로젝트: 18782967131/test
    def va_reconnect_epi(self, *args, **kwargs):
        """
        API to reconnect epi
        param   : kwargs : dict
        example : va_reconnect_epi(**kwargs)
            kwargs = {
                    'epi' : uuid|hostname,
                    'dev_id' : device id,
            }
        return: 
            :bool - True on success or False on failure:
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        cmd = 'request system reconnect'
        if 'epi' in kwargs:
            epi = kwargs.get('epi')
            cmd = '{} epi {}'.format(cmd, epi)
            if 'dev_id' in kwargs:
                dev_id = kwargs.get('dev_id')
                cmd = '{} device {}'.format(cmd, dev_id)
            else:
                cmd = '{} primary'.format(cmd)

        output = self._access.va_cli(cmd)
        return True
예제 #3
0
파일: epi_3_1.py 프로젝트: 18782967131/test
    def va_config_epi_operation_mode(self, *args, **kwargs):
        """
        method to config epi operation mode 
        param      : kwargs : dict
        example    : va_config_epi_operation_mode(**kwargs)
                   kwargs = {
                    'uuid': '564DB44A-B3F3-5D0B-0C33-77CD43987BFC'
                    'mode': 'inline'|'tap'|'pvlan'
                    'is_commit': True|False, True by default
                   }
        return: a tuple of True and cmd on success, False and err_msg on failure
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if not 'mode' in kwargs or \
            not 'uuid' in kwargs:
            raise ValueError(" 'mode' and 'uuid' are mandatory parameters!\n")

        is_commit = True
        uuid = kwargs.get('uuid')
        mode = kwargs.get('mode')
        if 'is_commit' in kwargs:
            is_commit = kwargs.get('is_commit')

        cmd = 'set chassis epi {} operation-mode {}'.format(uuid, mode)
        ret_val, err_msg = self._access.va_config(cmd, commit=is_commit)
        if ret_val is not None:
            return False, err_msg

        logger.info('Succeed to configure operation mode of EPI')
        return True, cmd
예제 #4
0
파일: epi_3_1.py 프로젝트: 18782967131/test
    def va_get_epi_mode(self, *args, **kwargs):
        """
        method to get epi mode 
        param      : kwargs : dict
        example    : va_get_epi_status(kwargs)
                   kwargs = {
                    'uuid': 'xxx'
                   }
        return: 'tap' or 'inline' or 'standy' or None (if epi not found)
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if not 'uuid' in kwargs:
            raise ValueError(" uuid is mandatory parameter!\n")

        uuid = kwargs['uuid']
        active_info = self.va_show_chassis_epi().get('Active EPI')

        for info in active_info:
            if info.uuid == uuid:
                logger.info('Mode of EPI: {}'.format(info.mode))
                return info.mode

        logger.error('Not found EPI {} in Activate EPI'.format(uuid))
        return None
예제 #5
0
    def va_unconfig_global_applog(self, application=None, port=None,
                               commit=None):
        '''
        API to configure global applog

        :param application:
        :param port:
        :param commit:
        :return:
        '''
        logger.info('We are in ::' + sys._getframe().f_code.co_name)
        if not application:
            return False, 'Application name is mandotory'
        if port:
            cmd = 'unset system app-log %s port %s' %(application, port)
        else:
            cmd = 'unset system app-log %s' %(application)
        if commit :
            cmd.append('commit')
        config_status, output = self._access.va_config(cmd)
        logger.debug('UnConfiguration of Global APPLOG : ' + str(config_status) + str(output))

        if config_status is False:
            logger.error('Global APPLOG Configuration/commit FAILED')
            return False, output
        else:
            logger.info('Global APPLOG Configuration/commit is successful')
            print('Configuration of GLOBAL APPLOG: ', config_status, output)
            return True, output
예제 #6
0
    def _va_parse_interface_mapping(self, output=None):
        """
        helper method to parse interface mapping

        [
         Config(varmour_intf='xe-1/0/0', 
         none='--->', 
         vm_intf='eth0', 
         mac='00:0c:29:5a:62:e9', 
         vm_index='6')
         ]
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        parsed = list()
        Config = namedtuple(
            'Config', ['varmour_intf', 'none', 'vm_intf', 'mac', 'vm_index'])

        for line in va_parse_as_lines(output):
            line = line.lstrip()
            if line.startswith('xe-'):
                values = line.split()
                try:
                    parsed.append(Config(*values))
                except TypeError:
                    pass

        return parsed
예제 #7
0
    def va_check_session_packets_increment(self, session_before, session_after, 
        *args, **kwargs):
        """
        API to check if packets counter of data session increase
        param     : 'session_before', should be single data session before increment
                    'session_after', should be single data session after increment
                }    
        example :
                    va_check_session_packets_increment(session_before, session_after)
        returns:
            :True|False (bool): True on success, False on failure
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        in_packets_before  = int(session_before.get('in_packets'))
        in_packets_after   = int(session_after.get('in_packets'))
        out_packets_before = int(session_before.get('out_packets'))
        out_packets_after  = int(session_after.get('out_packets'))
        if in_packets_before > in_packets_after or \
            out_packets_before > out_packets_after:
            logger.debug('In_packets:  {}, {}'.format(in_packets_before, in_packets_after))
            logger.debug('Out_packets: {}, {}'.format(out_packets_before, out_packets_after))
            logger.error('Packet counter of data session is not increasing!')
            return False

        logger.info('Packet counter of data session is increasing.')
        return True
예제 #8
0
    def va_delete_zone(self, *args, **kwargs):
        """
        API to delete zone
        param      : kwargs: 
                     'name' : name of zone
                     'is_negative' : negative test,  True|False, False by default
                     'is_commit'   : submit command, True|False, True by default
        example    : va_delete_zone(**kwargs)
                     kwargs = {
                         'name' : 'testzone',
                     }
        return: a tuple of True and cmd on success, False and err_msg on failure
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        if not 'name' in kwargs:
            raise ValueError(" name is mandatory parameter!\n")

        is_commit = True
        is_negative = False
        name = kwargs.get('name')
        if 'is_commit' in kwargs:
            is_commit = kwargs.get('is_commit')
        if 'is_negative' in kwargs:
            is_negative = kwargs.get('is_negative')

        cmd = 'unset zone {}'.format(name)
        ret_val, err_msg = self._access.va_config(cmd, commit=is_commit)
        if ret_val is not None:
            if not is_negative:
                logger.error('Failed to delete zone')
            return False, err_msg

        cmd = re.sub('^unset', 'set', cmd)
        logger.info('Succeed to delete zone')
        return True, cmd
예제 #9
0
파일: ha_3_1.py 프로젝트: 18782967131/test
    def va_do_ha_failover(self):

        """
        API to do HA failover
        return: 
            :bool - True on success or False on failure:
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)   

        if not self.va_check_ha_is_master():
            return False

        if not self.va_check_ha_ready():
            return False

        cmd = 'request system failover'
        failover_info = self._access.va_cli(cmd)

        pat = re.compile(r'FAILED HA FAILOVER')
        match_result = pat.search(failover_info)
        if match_result is not None:
            logger.error(failover_info)
            return False

        logger.info('Succeed to do HA failover')
        return True
예제 #10
0
    def va_enable_profile_stateful_inspection(self, *args, **kwargs):
        """
        API to enable stateful inspection of profile
        param      : kwargs: 
                     'name'  : name of stateful inspection,
                     'is_negative' : negative test,  True|False, False by default
                     'is_commit'   : submit command, True|False, True by default
        example    : va_enable_profile_stateful_inspection(**kwargs)
                     kwargs = {
                         'name' : 'test_state',
                     }
        return: a tuple of True and cmd on success, False and err_msg on failure
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        if not 'name' in kwargs:
            raise ValueError(" name is mandatory parameter!\n")

        is_commit = True
        is_negative = False
        name = kwargs.get('name')
        if 'is_commit' in kwargs:
            is_commit = kwargs.get('is_commit')
        if 'is_negative' in kwargs:
            is_negative = kwargs.get('is_negative')

        cmd = 'unset profile stateful-inspection {} strict-tcp-check disable'.format(
            name)
        ret_val, err_msg = self._access.va_config(cmd, commit=is_commit)
        if ret_val is not None:
            if not is_negative:
                logger.error('Failed to enable stateful inspection of profile')
            return False, err_msg

        logger.info('Succeed to enable stateful inspection of profile')
        return True, cmd[2:]
예제 #11
0
    def va_clear_session(self):
        """
        API to clear session
        param      : None
        example    : va_clear_session()
        returns:
            :True|False (bool): True if success else False
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        times = 1
        sleeptime = 2
        self._access.va_cli('clear session')
        session = self.va_get_session('is_fail')
        pattern = re.compile(r'((\d+\.){3}\d+)')
        while pattern.search(session) is not None and times <= 6:
            time.sleep(sleeptime)
            logger.debug('Retry {} times to clear session'.format(times))
            self._access.va_cli('clear session')
            session = self.va_get_session('is_fail')
            times += 1

        if pattern.search(session) is not None:
            logger.error("Session can't be cleared")
            return False

        logger.info('Session are cleared')
        return True
예제 #12
0
    def va_check_user(self, *args, **kwargs):
        """
           check user is exist
           param      : kwargs : dict
                       kwargs = {
                                 'name'    : 'account user name'
                       }
           return: boolean
               True
               False

            Example    : va_check_user(**kwargs)
                       kwargs = {
                            'name'    : 'varmour_no_cli'
                       }
         """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if not 'name' in kwargs:
            raise ValueError("name is mandatory parameter!\n")

        name = kwargs.get('name')
        info = self.va_get_system_user_info()

        if name in info:
            logger.info("the user {} is exist".format(name))
            return True
        else:
            logger.error("the user {} is not exist".format(name))
            return False
예제 #13
0
    def _va_parse_app_profile(self, output=None):
        """
        Parse the Output of show policy and check the given app profile
        is associated with policy

        :param output:

        :return:
        """
        logger.info("We are in ::" + sys._getframe().f_code.co_name)
        if not output:
            logger.error(" The output is empty string and \
            nothing to verify")
            return False
        logger.debug(" The output :")
        parsed = list()

        for line in output.splitlines()[1:]:
            line = line.strip()
            if not line.startswith('index') and \
                    not line.startswith('=') and \
                    not line.startswith('Total'):
                parsed.append(line.split())
        logger.info(parsed)
        return parsed
예제 #14
0
    def va_show_flow_address_group(self, name):
        """
        API for show address-group member list,and return the member list
        
        Param : name : address-group name

        Return : Tuple
            True,list
            False,err_msg

        Returns the result as follows:
            True,['saddr', 'daddr']
            False,'Fail to show address group member,address group test_group is not exist'

        Example : dir_1.va_show_flow_address_group()
                  dir_1.va_show_flow_address_group(name = 'test_group')
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        cmd = 'show address-group {}'.format(name)
        output = self._access.va_cli(cmd)
        if re.search('cannot find address group', output) != None:
            error = 'Fail to show address group member,address group {} is not exist'.format(
                name)
            logger.error(error)
            return False, error
        else:
            result = self._va_parse_address_group_member(output)
            if len(result) < 1:
                logger.info(
                    "address-group {} don't have any memeber".format(name))
                return True, result
            else:
                return True, result
예제 #15
0
    def va_log_command(self, command=None):
        """
        log the command and the vm that executes the command

        kwargs:
            :command (str): cli command executed
        """
        logger.info("{}".format(command))
예제 #16
0
    def va_add_user(self, *args, **kwargs):
        """
           Add user
           param      : kwargs : dict
                       kwargs = {
                                   'name'    : 'account user name',
                                   'password': '******',
                                   'role'    : 'account user role' [admin|operator|reader]
                                   'is_commit': True|False,  Optional parameters
                                  }
           return: Tuple
               True, cmd
               False, error log

            Example    : va_add_user(**kwargs)
                      kwargs = {
                       'name'    : 'varmour_no_cli',
                       'password': '******',
                       'role'    : 'admin'
                       'is_commit': True
                      }
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if not 'name' in kwargs:
            raise ValueError("name is mandatory parameter!\n")

        if not 'password' in kwargs:
            raise ValueError("password is mandatory parameter!\n")

        if not 'role' in kwargs:
            raise ValueError("role is mandatory parameter!\n")

        if not 'is_commit' in kwargs:
            is_commit = True
        else:
            is_commit = kwargs.get('is_commit')

        name = kwargs.get('name')
        password = kwargs.get('password')
        role = kwargs.get('role')
        cmd = 'set system user {} role {}'.format(name, role)
        cmd1 = 'set system user {} password'.format(name)
        err_cmd, err_msg = self._access.va_config(cmd,
                                                  commit=False,
                                                  exit=False)
        err_cmd1, err_msg1 = self._access.va_config(
            cmd1, **{'handle_password': password})

        if err_cmd is not None or err_msg is not None or\
            err_cmd1 is not None or err_msg1 is not None:
            logger.error('Failed to add user {}'.format(name))
            return False, err_msg

        logger.info('Succeed to add user {}'.format(name))
        return True, [cmd, cmd1]
예제 #17
0
    def va_add_service_group(self, *args, **kwargs):
        """
           Add service group
            
           Param   : kwargs : dict
                       kwargs = {
                                   'name'(str) : 'Define custom service name'
                                   'member'(str|list)             : 'member service(s) to service group'
                                   'is_commit'(boolean)          : 'Whether commit command' (default true)

           Return : Tuple
               True, cmd
               False, error log

           Example     : va_add_service_group(**kwargs)
                         kwargs = {
                                    'name'                  : 'test1'
                                    'member'                : 'TCP-ANY'
                                    'is_commit'             :  True|False
                                }
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        if 'name' not in kwargs:
            raise ValueError("name is mandatory parameter!\n")

        name = kwargs['name']
        cmds = []

        if 'member' not in kwargs:
            cmds.append("set service-group {}".format(name))
        else:
            member = kwargs['member']
            if type(member) != str and type(member) != list:
                raise ValueError("param member must be a list or string\n")
            if type(member) == str:
                member = member.split()
            if type(member) == list:
                for member_list in member:
                    cmds.append("set service-group {} member {}" \
                    .format(name,member_list))

        if 'is_commit' not in kwargs:
            is_commit = True
        else:
            is_commit = kwargs['is_commit']

        err_cmd, err_msg = self._access.va_config(cmds, commit=is_commit)

        if err_cmd is not None or err_msg is not None:
            logger.error("Failed to add service-group {}".format(name))
            return False, err_msg
        else:
            logger.info("Succeed to add service-group {}".format(name))
            return True, cmds
예제 #18
0
    def va_unset_chassis_debug(self,*args, **kwargs):

        """
            API unset chassi debug service/control/io/agent/routing-engine/konfd/chassis-d/orchestration/telemetry
            Param      : kwargs : 
                         debug_name(list) : Enabled debug name (default: all of debug process list)
                         enable_device    : Device ID or all devices (default: all)
                         orchestration_debug(list) : Orchestration debug flag (default: all)
                         is_commit        : commit True|False(default:True)
            Return     : Tuple
                         True,cmd
                         False,err log

            Example    : 
                       va_unset_chassis_debug(orchestration_debug=['orch-event','orch-deploy',\
                                                                  'vcenter-plugin-event'])
                       va_unset_chassis_debug(debug_name='orchestration'),
                       va_unset_chassis_debug()
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        debug_name = ['service','io','agent','control','routing-engine','konfd','chassis-d',\
                      'telemetry','orchestration']

        cmds = []
        pre_cmd = 'unset chassis process '
        is_commit = kwargs.get('is_commit',True)

        debug_name = kwargs.get('debug_name',['service','io','agent','control','routing-engine',\
                                              'konfd','chassis-d','telemetry','orchestration'])
        if isinstance(debug_name,str):
            debug_name = debug_name.split(',')
        
        for enable_debug_name in debug_name:
            if enable_debug_name in ['service','io','agent']:
                enable_dev = kwargs.get('enable_device','all')
                cmds.append(pre_cmd + '{} {} debug all'.format(enable_debug_name,enable_dev))
            elif enable_debug_name == 'orchestration':
                orch_debugs = kwargs.get('orchestration_debug','all')
                if isinstance(orch_debugs,str):
                    orch_debugs = orch_debugs.split(',')
                for flag in orch_debugs:
                    cmds.append(pre_cmd + 'orchestration debug {}'.format(flag))
            else:
                cmds.append(pre_cmd + '{} debug all'.format(enable_debug_name))

        ret_val, err_msg = self._access.va_config(cmds, commit=is_commit)
        if ret_val is not None:
            logger.error('Fail to unset chassis debug')
            return False, err_msg
        cmd_str = ','.join(cmds)
        cmd_list = (cmd_str.replace('unset','set')).split(',')
        logger.info('Succeed to unset chassis debug')
        return True, cmds 
예제 #19
0
    def va_config_address_group(self, dataDict, *args, **kwargs):
        """
            Config adddress group
            param     : data: dict
                data = {
                    name     : address group name 
                    member     : [], Any | address name
                    is_commit : commit, ON/OFF
                }
     
            example  :
                data = {
                    'name'       : 'addr-group',
                    'member'   : [],
                    'is_commit': 'ON',
                }
                va_config_address_group(data)
            return: True/False
       """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        data = copy.deepcopy(dataDict)

        cmds = []
        cmdprefix = 'set address-group'
        retcmds = []

        if not 'name' in data:
            raise ValueError(" Please input parameter 'name'\n")

        name = data['name'].strip()

        if 'member' in data:
            member = data['member']
            if not isinstance(member, list):
                member_list = [member]
            else:
                member_list = member
            for member in member_list:
                cmds.append('%s %s member %s' % (cmdprefix, name, member))
        else:
            cmds.append('%s %s' % (cmdprefix, name))
        retcmds = copy.deepcopy(cmds)

        if not 'is_commit' in data:
            is_commit = 'ON'
        else:
            is_commit = data['is_commit']

        self._access.va_config(cmds)

        if is_commit.upper() == "ON":
            if self._access.va_commit() is False:
                return False
        return True
예제 #20
0
    def va_config_app_group(self, dataDict, *args, **kwargs):
        """
            API to config app group
    
            param    : 
                dataDict = {
                            name         :  Define custom app group name
                            application  : application name or application list
                            is_commit    : Whether commit command
                            }
            return   : True/False
            example  : app_group_data({
                                'name'        : 'test',
                                'application' : [],
                                'is_commit'   : 'ON'
                               })
                        va_config_app_group(app_group_data)
        """
        logger.info("We are in ::" + sys._getframe().f_code.co_name)

        set_cmds = []
        data = copy.deepcopy(dataDict)

        # handle default value
        if 'name' in data:
            name = data['name']
        else:
            name = 'app_group_test'

        if 'application' in data:
            application = data['application']
            if not isinstance(application, list):
                app_list = [application]
            else:
                app_list = application
            for app in app_list:
                set_cmds.append('set profile app-group %s add application %s' %
                                (name, app))

        set_cmds.append('set profile app-group %s' % name)
        retcmds = copy.deepcopy(set_cmds)
        if not 'is_commit' in data:
            is_commit = 'ON'
        else:
            is_commit = data['is_commit']
        if is_commit.upper() == 'ON':
            set_cmds.append('commit')

        self._access.va_config(set_cmds)
        if is_commit.upper() == "ON":
            if self._access.va_commit() is False:
                return False
        return True
예제 #21
0
    def va_show_interface_mapping(self, dev_id='all', *args, **kwargs):
        """
        API to show interface mapping
        return: 
            :list - refer to output of _va_parse_interface_mapping
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        parser = self._va_parse_interface_mapping
        cmd = "show interface device {} mapping".format(dev_id)
        mapping_info = self._access.va_cli(cmd)

        return parser(mapping_info)
예제 #22
0
    def va_set_admin_auth(self, *args, **kwargs):
        """
            Set the admin-auth policy and admin-auth remote mode
            Param    : kwargs : dict
                       kwargs = {
                                    'mode'(str)         : 'admin-auth remote mode' (radius|ladp|ad)
                                    'policy'(str|list)  : 'Admin user authentication policy' (fallback-to-next|fallback-if-down)
                                    'is_commit'(boolean): True|False (default:True)
                                }
            Return    : Tuple
                True,cmd
                False,error log
             
             Example    : 
                       kwargs   = {
                                    'mode'      : 'ladp'
                                    'policy'    : fallback-to-next
                                    'is_commit' : True
                        }                         
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        cmds = []

        if not 'mode' in kwargs:
            raise ValueError("mode is mandatory parameter!\n")

        if not 'is_commit' in kwargs:
            is_commit = True
        else:
            is_commit = kwargs['is_commit']

        cmds.append("set system admin-auth remote {}".format(kwargs['mode']))

        if 'policy' in kwargs:
            policy = kwargs['policy']
            if type(policy) == str:
                policy = policy.split()
            if type(policy) == list:
                for policy_list in policy:
                    cmds.append("set system admin-auth policy {}" \
                    .format(policy_list))

        err_cmd, err_msg = self._access.va_config(cmds, commit=is_commit)

        if err_cmd != None or err_msg != None:
            logger.error("Fail to set admin-auth")
            return False, err_msg
        else:
            logger.info("Succeed to set admin-auth")
            return True, cmds
예제 #23
0
    def va_get_chassis_fabric_vxlan_info(self):
        """
            get chassis fabric vxlan info 
            param   : None
 
            return (list) : look at the following output
            varmour@vArmour#ROOT> show chassis fabric
            Global VXLAN Tunnel ID: 10
            DEV-ID   | HOSTNAME             | STATE      | MGT-IP               | FABRIC-IP            | FABRIC-GW            | MODE 
            -------------------------------------------------------------------------------------------------------------------------
            1        | vArmour              | Active     | 10.11.120.41/24      | 10.0.0.41/24         | --                   | DIR   
            2        | vArmour              | In-Active  | --                   | 10.0.0.43/24         | --                   |       
            3        | vArmour              | Active     | 10.11.120.46/24      | 10.0.0.46/24         | --                   | CP    
            4        | vArmour              | Active     | 10.11.120.43/24      | 10.0.0.43/24         | --                   | CP   

            return (list) :                                                                                                                                                  
       
            [  
                'Global VXLAN Tunnel ID: 10', 
                fabric(DEVID='1', HOSTNAME='vArmour', STATE='Active', MGT_IP=' 10.11.120.41/24', FABRIC_IP=' 10.0.0.41/24', FABRIC_GW='--', MODE='DIR'), 
                fabric(DEVID='2', HOSTNAME=' vArmour', STATE=' In-Active', MGT_IP='--', FABRIC_IP=' 10.0.0.43/24', FABRIC_GW='--', MODE='   '), 
                fabric(DEVID='3', HOSTNAME=' vArmour', STATE=' Active', MGT_IP=' 10.11.120.46/24', FABRIC_IP=' 10.0.0.46/24', FABRIC_GW='--', MODE='CP'), 
                fabric(DEVID='4', HOSTNAME=' vArmour', STATE=' Active', MGT_IP=' 10.11.120.43/24', FABRIC_IP=' 10.0.0.43/24 ', FABRIC_GW='--', MODE=' CP')
            ]
            
            example     : dir_1.va_get_chassis_fabric_vxlan_info()
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)
        
        parsed = list()
        Usert = namedtuple('fabric',['DEVID','HOSTNAME','STATE','MGT_IP','FABRIC_IP','FABRIC_GW','MODE'])
        rt = self._access.va_cli("show chassis fabric")

        for line in va_parse_as_lines(rt):
            line = line.replace(' ','')
            if line.startswith('Global VXLAN Tunnel ID') and not line.startswith('DEV-ID') \
            and 'show chassis fabric' not in line and not line.startswith('-'):
                parsed.append(line)                
            elif not line.startswith('Global VXLAN Tunnel ID') and not line.startswith('DEV-ID') \
            and not line.startswith('-') and 'show chassis fabric' not in line:
                values = line.split("|")
                if '-' in values:
                    values = "_"
                try:
                    parsed.append(Usert(*values))
                except TypeError:
                    pass
        
        logger.info(parsed)
        return parsed
예제 #24
0
    def va_install_image(self, image, **kwargs ):
        """
        Install image

        Arguments:
            :image (str): Software image name
            :kwargs (dict) :
                'install_os'    :  primary/secondary
                'install_delay' : time of install image
        returns:
            :False: Failed to install image.
            :True: Succeed to install image.

        Examples:
            va_install_image('image-file.tar')
            va_install_image('image-file.tar',\
                {'install_os':'primary','install_delay':200})
        """
        if not 'install_os' in kwargs:
            install_os = 'primary'
        else :
            install_os = kwargs['install_os']

        if not 'install_delay' in kwargs:
            install_delay = 300
        else :
            install_delay = kwargs['install_delay']

        if not 'reboot_delay' in kwargs:
            reboot_delay = 120
        else:
            reboot_delay = kwargs['reboot_delay']

        logger.info('install delay is {}'.format(install_delay))
        self._access.va_cli("request install software {} {}"\
                            .format(image, install_os),install_delay)

        #check the status of install firmeare
        if not self.va_check_install_status_for_ep_or_cp():
            return False

        if not self.va_check_install_status_for_epi() :
            return False

        logger.debug("Change boot-sector to %s" % install_os)
        self._access.va_cli("request system boot-sector {}" .format(install_os))
        time.sleep(30)

        logger.info("**************Completed install image to all devices************")
        return True
예제 #25
0
    def va_verify_session(self, *args, **kwargs):
        """
        API to check flow session 
    
        param     : kwargs : dict
            kwargs = {
                    'session' : session_val,
                    'proto'   : 'icmp' | 'ftp',
                    'policy'  : 'test_pol',
                    more parameters refer to va_check_session,
                }    
        example :
                    va_check_session(**kwargs)

        return: True/False
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)   
        check_data = copy.copy(kwargs)

        if not 'session' in kwargs:
            session = self.va_get_session()
        else:
            session = kwargs.pop('session')
        check_data['session'] = session

        if not 'policy' in kwargs:
            check_data['policy'] = "test_pol"

        if 'proto' in kwargs:
            proto = kwargs.pop('proto')
            check_data['proto'] = proto_map.get(proto)

            if proto.upper() != 'ICMP':
                if proto.upper() == 'FTP-DATA':
                    check_data['in_src_port'] = port_map.get(proto)
                    check_data['out_dst_port'] = port_map.get(proto)
                else :
                    check_data['in_dst_port']  = port_map.get(proto)
                    check_data['out_src_port'] = port_map.get(proto)

        if 'is_fail' in args:
            if 'data_session' in args:
                return self.va_check_session(check_data,'is_fail','data_session')
            else:
                return self.va_check_session(check_data,'is_fail')
        if 'data_session' in args:
            return self.va_check_session(check_data,'data_session')
        else:
            return self.va_check_session(check_data)
예제 #26
0
    def va_set_chassis_fabric(self, *args, **kwargs):

        """
            method set fabric tunnel/secret/heartbeat-interval 
            param      : kwargs : dict
                       kwargs = {
                                 'vxlan'    : 'vxlan identifier'
                                 'secret'   : 'fabric secret key'
                                 'heartbeat_interval'   : ' Heartbeat interval in seconds'
                                 'is_commit': 'commit' True|False
                       }
            return     : Tuple
                True,cmd
                False,err log

            Example    : va_set_chassis_fabric(**kwargs)
                        kwargs = {
                         'vxlan'    : 10,
                         'secret'   : 'varmour',
                         'heartbeat_interval'    : 3,
                         'is_commit'    : True
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        cmds = []

        if 'vxlan' in kwargs:
            cmds.append('set chassis fabric tunnel vxlan %s' % (kwargs['vxlan']))

        if 'heartbeat_interval' in kwargs:
            cmds.append('set chassis fabric heartbeat_interval %s' % (kwargs['heartbeat_interval']))

        if 'secret' in kwargs:
            cmds.append('set chassis fabric secret %s' % (kwargs['secret']))

        if not 'is_commit' in kwargs :
            is_commit = True
        else :
            is_commit = kwargs['is_commit']
    
        err_cmd,err_msg = self._access.va_config(cmds,commit=is_commit)

        if err_cmd is None or err_msg is None:
            logger.info("Succeed to set chassis fabric")
            return True,cmds
        else:
            error = "Failed to set chassis fabric"
            logger.error(error)
            return False,err_msg
예제 #27
0
파일: ha_3_1.py 프로젝트: 18782967131/test
    def va_check_ha_is_ineligible(self):
        """
        API to check if HA is ineligible state
        return:
            :bool - True on success or False on failure:
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)

        ha_role = self.va_get_ha_role()
        if ha_role != 'ineligible':
            logger.error('The role of director is {}'.format(ha_role))
            return False

        logger.info('The role of director is INELIGIBLE')
        return True
예제 #28
0
    def _va_parse_show_session(self, output=None):
        """
        Parse the Output of show policy and check the given
        app profile is associated with policy

        :param output:

        :return:
        """
        logger.info("We are in ::" + sys._getframe().f_code.co_name)
        if not output:
            logger.error(" The output is empty string and \
            nothing to verify")
            return False
        logger.debug(" The \"show session\" output :")
예제 #29
0
    def _va_verify_ip(self, interface=None, config=None):
        """
        Helper function to compare ip address that is being
        configured and its actual set value.
        """
        output = self.va_show_interface(interface)
        if not output:
            return False

        if config.with_prefixlen == output['Local address']:
            logger.info("set/unset ip succeeded")
            return True
        else:
            logger.error("set/unset ip failed")
            return False
예제 #30
0
파일: ha_3_1.py 프로젝트: 18782967131/test
    def va_check_ha_is_master(self):
        """
        API to check if HA is master
        return: 
            :bool - True on success or False on failure:
        """
        logger.info("\nIn subroutine: " + sys._getframe().f_code.co_name)   

        ha_role = self.va_get_ha_role()
        if ha_role != 'master':
            logger.error('The role of director is {}'.format(ha_role))
            return False

        logger.info('The role of director is MASTER')
        return True