示例#1
0
文件: ixia.py 项目: SrijaGupta/file
    def invoke(self, command, *args, **kwargs):
        """
        Pass-through for ixnetwork.py functions
        (ixnetwork.py? or something else?)
        """

        lib = 'ngpf'

        if re.search(r'^IxNet::', command):
            lib = 'ixnet'
            command = command.replace('IxNet::', '', 1)
            # Initialize IxNet if not set up already
            if not self._ixiaixnet:
                from IxNetwork import IxNet # pylint: disable=import-error
                self._ixiaixnet = IxNet()
                self._connect_ixnet()

        if 'port_handle' in kwargs.keys():
            port_handle = kwargs['port_handle']
            if isinstance(port_handle, six.string_types):
                port_handle = port_handle.split(' ')
            if port_handle[0] in self.intf_to_port_map.keys():
                new_port_handle = list()
                for intf in port_handle:
                    new_port_handle.append(self.port_to_handle_map[self.intf_to_port_map[intf]])
                kwargs['port_handle'] = ' '.join(new_port_handle)

        # User contributed module
        if command in self.user_functions:
            self.log(level="info", message="Invoking Juniper IXIA function " + command + " with parameters " + str(kwargs))
            result = self.user_functions[command](self, **kwargs)
            self.log(level="info", message="Invocation of Juniper IXIA function " + command + " completed with result: " + str(result))
            return result
        # ngpf method
        elif lib == 'ngpf':
            self.log(level="info", message="Invoking IXIA ngpf method " + command + " with parameters " + str(kwargs))
            ixia_method = getattr(self._ixiangpf, command)
            result = ixia_method(**kwargs)
            if result['status'] == '0':
                raise TobyIxiaException("Invocation of IXIA method " + command + " failed with result: " + str(result), host_obj=self)
            else:
                self.log(level="debug", message="Invocation of IXIA method " + command + " succeeded with result: " + str(result))
                return result
        # ixnet method
        elif lib == 'ixnet':
            ixnet_args = kwargs.get('ixnet_args', None)
            if not ixnet_args and len(args) > 0: # args came in via python *args instead of via kwargs(ixnet_args)
                ixnet_args = args
            self.log("INFO", message="Invoking IXIA ixnet API '" +command + "' with parameters " + str(ixnet_args))
            ixia_method = getattr(self._ixiaixnet, command)
            if ixnet_args:
                result = ixia_method(*ixnet_args)
            else:
                result = ixia_method()
            self.log("INFO", message="Invocation of IXIA API '" + command + "' completed with result: " + str(result))
            return result
示例#2
0
    def _ixnetwork_session_handler(self, context):
        try:
            self.ixnetwork_session.getVersion()
        except (AttributeError, Exception) as e:
            if e.__class__ != AttributeError:
                self.cs_session.WriteMessageToReservationOutput(self.reservation_id,
                                                                "[%s] _ixnetwork_session_handler %s:%s" %
                                                                (self.resource_name,
                                                                 e.__class__.__name__,
                                                                 e.message))

            utility_server_name, utility_server_resource = self.utility_server.popitem()
            api_address = utility_server_resource.FullAddress
            api_port = context.resource.attributes['API Port']
            api_version = context.resource.attributes['API Version']
            try:
                self.ixnetwork_session = IxNet()
                self.ixnetwork_session.connect(api_address, '-port', api_port, '-version', api_version)
                self.cs_session.WriteMessageToReservationOutput(self.reservation_id,
                                                                "[%s] Connected to API v%s at %s:%s" %
                                                                (self.resource_name,
                                                                 api_version,
                                                                 api_address,
                                                                 api_port))
            except Exception as e:
                self.cs_session.WriteMessageToReservationOutput(self.reservation_id,
                                                                "[%s] Failed to connect to API client v%s at %s:%s, %s:%s" %
                                                                (self.resource_name,
                                                                 api_version,
                                                                 api_address,
                                                                 api_port,
                                                                 e.__class__.__name__,
                                                                 e.message))
                raise

        return
示例#3
0
        pass

    class Py:
        pass

    py = Py()
    py.ports = [('10.205.15.62', 3, 5), ('10.205.15.62', 3, 6)]
    py.ixTclServer = '10.205.15.224'
    py.ixTclPort = 8009

################################################################################
# Import the IxNet library
################################################################################
from IxNetwork import IxNet
import time
ixNet = IxNet()

################################################################################
# Connect to IxNet client
################################################################################

ixNet.connect(py.ixTclServer, '-port', py.ixTclPort, '-version', '7.40')

################################################################################
# Cleaning up IxNetwork
################################################################################
print("Cleaning up IxNetwork...")
ixNet.execute('newConfig')

################################################################################
# Adding ports to configuration