def _build_chassis(self):
     chassis_dict = {}
     chassis_attributes = ApconChassisAttributes(self._chassis_table)
     for address, record in self._chassis_table.iteritems():
         model_name = 'Apcon Cli4 Chassis'
         serial_number = chassis_attributes.serial_number(address).value
         chassis = Chassis(address.index(), self._resource_address,
                           model_name, serial_number)
         chassis.attributes = chassis_attributes.get_attributes(address)
         chassis_dict[address] = chassis
     return chassis_dict
Exemplo n.º 2
0
    def autoload(self, address):
        """

        :return:
        """
        with self._cli_handler.enable_mode_service() as cli_service:
            autoload_actions = AutoloadActions(cli_service=cli_service, logger=self._logger)

            switch_details = autoload_actions.get_switch_details()
            switch_details = re.search(r"[Dd]evice\s+[Mm]odel\s+(?P<device_model>.*)\n"
                                       r"[Ss]erial\s+[Nn]umber\s+(?P<serial_number>.*)\n"
                                       r"[Ss][Ww]\s[Vv]ersion\s+(?P<sw_version>.*)\n",
                                       switch_details)

            chassis = Chassis(resource_id="", address=address, model_name="Cgs Chassis")
            chassis.set_model_name(switch_details.group("device_model"))
            chassis.set_serial_number(switch_details.group("serial_number"))
            chassis.set_os_version(switch_details.group("sw_version"))

            for port in autoload_actions.get_ports():
                port_resource = Port(resource_id=port.port_id.replace("/", "-"))
                port_resource.set_port_speed(port.speed)
                port_resource.set_parent_resource(chassis)

            return ResourceDescriptionResponseInfo([chassis])
    def _build_chassis(self):
        chassis_dict = {}

        serial_number = self._board_table.get('chassis-serial')
        model_name = self._board_table.get('model')
        sw_version = self._board_table.get('version')
        chassis = Chassis(self._chassis_id, self._resource_address, 'Pluribus Virtual Wire Chassis', serial_number)
        chassis.set_model_name(model_name)
        chassis.set_serial_number(serial_number)
        chassis.set_os_version(sw_version)
        chassis_dict[self._chassis_id] = chassis
        return chassis_dict
    def _build_chassis(self):
        chassis_dict = {}

        serial_number = self._board_table.get('serial_number')
        model_name = self._board_table.get('model_name')
        sw_version = self._board_table.get('sw_version')
        chassis = Chassis(self._chassis_id, self._resource_address,
                          'Fiberzone Afm Chassis', serial_number)
        chassis.set_model_name(model_name)
        chassis.set_serial_number(serial_number)
        chassis.set_os_version(sw_version)
        chassis_dict[self._chassis_id] = chassis
        return chassis_dict
Exemplo n.º 5
0
    def chassis(self):
        if self._chassis is not None:
            return self._chassis

        serial_number = self.board_table.get("serial_number")
        model_name = self.board_table.get("model_name")
        sw_version = self.board_table.get("sw_version")
        chassis = Chassis(self._chassis_id, self.resource_address,
                          "Rome Chassis", serial_number)
        chassis.set_model_name(model_name)
        chassis.set_serial_number(serial_number)
        chassis.set_os_version(sw_version)

        self._chassis = chassis
        return chassis
Exemplo n.º 6
0
    def chassis(self):
        if self._chassis is not None:
            return self._chassis

        serial_number = self.board_table.get('serial_number')
        model_name = self.board_table.get('model_name')
        sw_version = self.board_table.get('sw_version')
        chassis = Chassis(self._chassis_id, self.resource_address,
                          'Rome Chassis', serial_number)
        chassis.set_model_name(model_name)
        chassis.set_serial_number(serial_number)
        chassis.set_os_version(sw_version)

        self._chassis = chassis
        return chassis
 def _build_chassis(self):
     """
     Build chassis using data from chassis table
     :return:
     """
     chassis_dict = {}
     for address, record in self._chassis_table.iteritems():
         serial_number = record.get(
             'nbsCmmcChassisSerialNum') or record.get('SerialNum')
         chassis = Chassis(address.index(), self._resource_address,
                           'Generic MRV Chassis', serial_number)
         chassis.set_model_name(
             record.get('nbsCmmcChassisModel') or record.get('Model'))
         chassis.set_serial_number(serial_number)
         chassis.set_os_version(None)
         chassis_dict[address] = chassis
     return chassis_dict
Exemplo n.º 8
0
    def get_resource_description(self, address):
        """
        Auto-load function to retrieve all information from the device
        :param address: resource address, '192.168.42.240'
        :type address: str
        :return: resource description
        :rtype: cloudshell.layer_one.core.response.response_info.ResourceDescriptionResponseInfo
        :raises cloudshell.layer_one.core.layer_one_driver_exception.LayerOneDriverException: Layer one exception.

        Example:

            from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
            from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
            from cloudshell.layer_one.core.response.resource_info.entities.port import Port

            chassis_resource_id = chassis_info.get_id()
            chassis_address = chassis_info.get_address()
            chassis_model_name = "Ixia Visionedge Chassis"
            chassis_serial_number = chassis_info.get_serial_number()
            chassis = Chassis(resource_id, address, model_name, serial_number)

            blade_resource_id = blade_info.get_id()
            blade_model_name = 'Generic L1 Module'
            blade_serial_number = blade_info.get_serial_number()
            blade.set_parent_resource(chassis)

            port_id = port_info.get_id()
            port_serial_number = port_info.get_serial_number()
            port = Port(port_id, 'Generic L1 Port', port_serial_number)
            port.set_parent_resource(blade)

            return ResourceDescriptionResponseInfo([chassis])
        """
        self._logger.info("GetResourceDescriptions")
        chassis_id = "1"
        chassis_model_name = "Ixia Visionedge Chassis"
        chassis = Chassis(chassis_id, address, chassis_model_name)

        blade_table = {}

        port_table = {}
        port_list = self._get_ports()
        # port_list = get_ports()
        if not port_list:
            raise Exception("Ports are not defined.")
        for port_info in port_list:
            port_uuid = port_info.get(self._KEYS.IDENTIFIER)
            port_name = port_info.get(self._KEYS.NAME)
            blade_id, port_id = self._parse_port_name(port_name)
            if not blade_id or not port_id:
                self._logger.debug(
                    "Extracting default port name for uuid: {}, name: {}".
                    format(port_uuid, port_name))
                blade_id, port_id = self._parse_port_name(
                    self._get_port_data(port_name).get('default_name'))

            if not blade_id or not port_id:
                self._logger.error(
                    "Cannot identify port id, uuid: {}, name: {}".format(
                        port_uuid, port_name))
                continue

            blade = blade_table.get(blade_id)
            if not blade:
                blade = Blade(blade_id)
                blade.set_parent_resource(chassis)
                blade_table[blade_id] = blade
            port = Port(port_id)
            port.set_parent_resource(blade)
            port_table[port_uuid] = port

        filters = self._get_filters()
        for f in filters:
            f_inf = self._get_filter(f.get(self._KEYS.IDENTIFIER))
            src_list = f_inf.get(self._KEYS.SRC_PORT_LIST)
            dst_list = f_inf.get(self._KEYS.DST_PORT_LIST)
            if src_list and dst_list:
                src_port = port_table.get(src_list[0])
                dst_port = port_table.get(dst_list[0])
                if src_port and dst_port:
                    dst_port.add_mapping(src_port)

        return ResourceDescriptionResponseInfo([chassis])
    def get_resource_description(self, address):
        """
        Auto-load function to retrieve all information from the device
        :param address: resource address, '192.168.42.240'
        :type address: str
        :return: resource description
        :rtype: cloudshell.layer_one.core.response.response_info.ResourceDescriptionResponseInfo
        :raises cloudshell.layer_one.core.layer_one_driver_exception.LayerOneDriverException: Layer one exception.

        Example:

            from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
            from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
            from cloudshell.layer_one.core.response.resource_info.entities.port import Port
            from cloudshell.layer_one.core.response.resource_info. import Res

            chassis_resource_id = chassis_info.get_id()
            chassis_address = chassis_info.get_address()
            chassis_model_name = "Visionedge Chassis"
            chassis_serial_number = chassis_info.get_serial_number()
            chassis = Chassis(resource_id, address, model_name, serial_number)

            blade_resource_id = blade_info.get_id()
            blade_model_name = 'Generic L1 Module'
            blade_serial_number = blade_info.get_serial_number()
            blade.set_parent_resource(chassis)

            port_id = port_info.get_id()
            port_serial_number = port_info.get_serial_number()
            port = Port(port_id, 'Generic L1 Port', port_serial_number)
            port.set_parent_resource(blade)

            return ResourceDescriptionResponseInfo([chassis])
        """
        #self._logger.warn('getting resources 1 ')

        from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
        from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
        from cloudshell.layer_one.core.response.resource_info.entities.port import Port
        from cloudshell.layer_one.core.response.response_info import ResourceDescriptionResponseInfo

        # chassis_resource_id = chassis_info.get_id()
        # chassis_address = chassis_info.get_address()
        chassis_model_name = "Visionedge Chassis"
        # chassis_serial_number = chassis_info.get_serial_number()
        chassis = Chassis("ChassisID", address, chassis_model_name, "C1")

        #self._logger.warn('getting resources 2 ')
        # blade_resource_id = blade_info.get_id()
        blade_model_name = 'Generic L1 Module'
        # blade_serial_number = blade_info.get_serial_number()
        blade = Blade("Bladeid", blade_model_name, "S1")
        blade.set_parent_resource(chassis)

        nto = self.nto_session

        # port_id = port_info.get_id()
        ports = nto.getAllCtePorts()
        for port_id in ports:
            # port_id = "P1-01"
            # port_serial_number = port_info.get_serial_number()
            self._logger.warn('getting resources port' + port_id['name'])
            port = Port(port_id['name'], 'Generic L1 Port',
                        "P" + str(port_id['uuid']))
            port.set_parent_resource(blade)

        self._logger.warn('getting resources 3')

        return ResourceDescriptionResponseInfo([chassis])
Exemplo n.º 10
0
    def get_resource_description(self, address):
        """ Auto-load function to retrieve all information from the device
        :param address: resource address, "192.168.42.240"
        :type address: str
        :return: resource description
        :rtype: cloudshell.layer_one.core.response.response_info.ResourceDescriptionResponseInfo
        :raises cloudshell.layer_one.core.layer_one_driver_exception.LayerOneDriverException: Layer one exception.

        Example:

            from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
            from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
            from cloudshell.layer_one.core.response.resource_info.entities.port import Port

            chassis_resource_id = chassis_info.get_id()
            chassis_address = chassis_info.get_address()
            chassis_model_name = "Telebyte Chassis"
            chassis_serial_number = chassis_info.get_serial_number()
            chassis = Chassis(resource_id, address, model_name, serial_number)

            blade_resource_id = blade_info.get_id()
            blade_model_name = "Generic L1 Module"
            blade_serial_number = blade_info.get_serial_number()
            blade.set_parent_resource(chassis)

            port_id = port_info.get_id()
            port_serial_number = port_info.get_serial_number()
            port = Port(port_id, "Generic L1 Port", port_serial_number)
            port.set_parent_resource(blade)

            return ResourceDescriptionResponseInfo([chassis])
        """

        with self._cli_handler.default_mode_service() as session:
            autoload_actions = AutoloadActions(session, self._logger)

            dev_model, serial_number = autoload_actions.get_device_info()

            chassis = Chassis("", address, "Telebyte Chassis", serial_number)
            chassis.set_model_name(dev_model)
            chassis.set_os_version(autoload_actions.get_device_software())
            chassis.set_serial_number(serial_number)

            slot_id = 0
            while slot_id <= self._max_slot_count:
                try:
                    slot_id += 1
                    slot_info = autoload_actions.get_slot_info(slot_id=slot_id)
                    self._logger.debug("SLOT INFO: {}".format(slot_info))

                    if slot_info:
                        blade = Blade(slot_id, "Generic L1 Module", slot_info.get("Serial", ""))
                        blade.set_model_name(slot_info.get("Model", ""))
                        blade.set_parent_resource(chassis)

                        ports = {}
                        out_ports, in_ports = autoload_actions.get_in_out_ports(slot_info=slot_info)
                        self._logger.debug("OUT PORTS: {}, IN PORTS: {}".format(out_ports, in_ports))
                        if out_ports is None:
                            raise Exception("Can not determine out port count")

                        for i in range(1, out_ports + 1):
                            port_id = chr(i + self.PORT_ADD)
                            port_serial = "{dev_serial}.{port_id}".format(dev_serial=slot_info.get("Serial", ""),
                                                                          port_id=port_id)
                            self._logger.debug("Port ID : {}".format(port_id))

                            port = Port(port_id, "Generic L1 Port", port_serial)
                            port.set_parent_resource(blade)
                            ports[port_id] = port

                        for i in range(1, in_ports + 1):
                            port_id = i

                            port_serial = "{dev_serial}.{port_id}".format(dev_serial=slot_info.get("Serial", ""),
                                                                          port_id=port_id)
                            self._logger.debug("Port ID : {}".format(port_id))

                            port = Port(port_id, "Generic L1 Port", port_serial)
                            port.set_parent_resource(blade)
                            ports[port_id] = port

                        conn_info = autoload_actions.get_slot_connections(slot_id=slot_id)
                        self._logger.debug("SLOT CONNECTIONS: {}".format(conn_info))

                        for out_port_id, in_port_id in conn_info.items():
                            if in_port_id == 0: #  means no connection
                                continue

                            out_port = ports.get(out_port_id)
                            in_port = ports.get(in_port_id)
                            out_port.add_mapping(in_port)
                            in_port.add_mapping(out_port)


                except InvalidSlotNumberException:
                    # self._max_slot_count = min(slot_id, self._max_slot_count)
                    break

        return ResourceDescriptionResponseInfo([chassis])
 def _build_chassis(self):
     chassis = Chassis('1', self._address, 'Simpler Networks Chassis', self._chassis_sn)
     chassis.set_model_name(self._resource_descr)
     chassis.set_serial_number(self._chassis_sn)
     return chassis
Exemplo n.º 12
0
    def get_resource_description(self, address):
        """
        Auto-load function to retrieve all information from the device
        :param address: resource address, '192.168.42.240'
        :type address: str
        :return: resource description
        :rtype: cloudshell.layer_one.core.response.response_info.ResourceDescriptionResponseInfo
        :raises cloudshell.layer_one.core.layer_one_driver_exception.LayerOneDriverException: Layer one exception.

        Example:

        from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
        from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
        from cloudshell.layer_one.core.response.resource_info.entities.port import Port
        from cloudshell.layer_one.core.response.response_info import ResourceDescriptionResponseInfo

        chassis_resource_id = 1
        chassis_model_name = "Test Switch Chassis"
        chassis_serial_number = 'NA'
        chassis = Chassis(chassis_resource_id, address, chassis_model_name, chassis_serial_number)

        blade1 = Blade('1')
        blade1.set_parent_resource(chassis)
        blade2 = Blade('2')
        blade2.set_parent_resource(chassis)

        for port_id in range(1, 11):
            port = Port(port_id)
            port.set_parent_resource(blade1)

        for port_id in range(1, 11):
            port = Port(port_id)
            port.set_parent_resource(blade2)

        return ResourceDescriptionResponseInfo([chassis])
        """

        chassis_resource_id = 1
        chassis_model_name = "Test Switch Chassis"
        chassis_serial_number = 'NA'
        chassis = Chassis(chassis_resource_id, address, chassis_model_name,
                          chassis_serial_number)

        blade1 = Blade('1')
        blade1.set_parent_resource(chassis)
        blade2 = Blade('2')
        blade2.set_parent_resource(chassis)
        ports = {}

        for port_id in range(1, 11):
            port = Port(port_id)
            # port.set_protocol('69')
            # port.set_protocol_type('2')
            # port.set_speed('5')
            port.set_parent_resource(blade1)
            ports[port.address] = port

        for port_id in range(1, 11):
            port = Port(port_id)
            # port.set_protocol('30')
            # port.set_protocol_type('2')
            # port.set_speed('4')
            port.set_parent_resource(blade2)
            ports[port.address] = port

        with self.MappingTransManager(self._mapping_file) as mappings:
            for dst_addr, src_addr in mappings.items():
                src_port = ports.get(src_addr)
                dst_port = ports.get(dst_addr)
                if src_port and dst_port:
                    dst_port.add_mapping(src_port)
                # mapped_to = self.mappings.get(addr)
                # if mapped_to:
                #     port.add_mapping(mapped_to)

        return ResourceDescriptionResponseInfo([chassis])
Exemplo n.º 13
0
    def get_resource_description(self, address):
        """
        Auto-load function to retrieve all information from the device
        :param address: resource address, '192.168.42.240'
        :type address: str
        :return: resource description
        :rtype: cloudshell.layer_one.core.response.response_info.ResourceDescriptionResponseInfo
        :raises cloudshell.layer_one.core.layer_one_driver_exception.LayerOneDriverException: Layer one exception.

        Example:

            from cloudshell.layer_one.core.response.resource_info.entities.chassis import Chassis
            from cloudshell.layer_one.core.response.resource_info.entities.blade import Blade
            from cloudshell.layer_one.core.response.resource_info.entities.port import Port

            chassis_resource_id = chassis_info.get_id()
            chassis_address = chassis_info.get_address()
            chassis_model_name = "Coldfusion Chassis"
            chassis_serial_number = chassis_info.get_serial_number()
            chassis = Chassis(resource_id, address, model_name, serial_number)

            blade_resource_id = blade_info.get_id()
            blade_model_name = 'Generic L1 Module'
            blade_serial_number = blade_info.get_serial_number()
            blade.set_parent_resource(chassis)

            port_id = port_info.get_id()
            port_serial_number = port_info.get_serial_number()
            port = Port(port_id, 'Generic L1 Port', port_serial_number)
            port.set_parent_resource(blade)

            return ResourceDescriptionResponseInfo([chassis])
        """
        self._logger.info("@get_resource_description")

        chassis_json = self.chassis_get("")

        chassis_resource_id = address
        chassis_address = address
        chassis_model_name = "Coldfusion Chassis"
        chassis_serial_number = chassis_json["Serial"]
        chassis = Chassis(chassis_resource_id, chassis_address,
                          chassis_model_name, chassis_serial_number)

        # Discover and configure the topology
        _blades = {}
        linecards_json = chassis_json["Linecards"]
        for lc in range(len(linecards_json)):
            self._logger.info("Resource LC-{0}".format(lc + 1))
            if linecards_json[lc] != None:
                blade_resource_id = str(lc + 1)
                blade_model_name = 'Generic L1 Module'
                blade_serial_number = "L".format(lc + 1)
                blade = Blade(blade_resource_id, blade_model_name,
                              blade_serial_number)
                blade.set_parent_resource(chassis)
                _blades[lc + 1] = {}

                ports_json = self.chassis_get("linecards/{0}/ports".format(lc))
                for port in range(0, len(ports_json)):
                    ptype = ports_json[port]["Type"]
                    breakout = ports_json[port]["Breakout"]
                    if breakout and ptype == "OPort_CF1":
                        for lane in range(4):
                            port_id = self._qport(port + 1, lane + 1)
                            port_serial_number = "{0:02}.{1:01}.{2}".format(
                                lc + 1, port + 1, lane + 1)
                            port_obj = Port(port_id, 'Generic L1 Port',
                                            port_serial_number)
                            port_obj.set_parent_resource(blade)
                            _blades[lc + 1][port_id] = port_obj
                    else:
                        port_id = self._qport(port + 1)
                        port_serial_number = "{0:02}.{1:01}.1".format(
                            lc + 1, port + 1)
                        port_obj = Port(port_id, 'Generic L1 Port',
                                        port_serial_number)
                        port_obj.set_parent_resource(blade)
                        _blades[lc + 1][port_id] = port_obj

        # Configure the mappings
        for lc, blade in _blades.items():
            ports_json = self.chassis_get("linecards/{0}/ports".format(lc - 1))
            num_ports = len(ports_json)
            ports = [
                "{0}.{1}".format(lc, port) for port in range(1, num_ports + 1)
            ]
            body = dict(Ports=ports)
            flows = self.chassis_post("show-flow", body)
            #            self._logger.info("@flows for LC-{0}={1}".format(lc,str(flows)))
            for port in range(0, num_ports):
                egress = flows['Ports'][port]['Egress']
                ptype = ports_json[port]["Type"]
                breakout = ports_json[port]["Breakout"]
                if breakout and ptype == "OPort_CF1":
                    for lane in range(4):
                        port_id = self._qport(port + 1, lane + 1)
                        port_obj = blade[port_id]
                        for egress_port in egress:
                            index = min(lane, len(egress_port) - 1)
                            if egress_port[index] != None and len(
                                    egress_port[index]) > 0:
                                # self._logger.info("$$$ {0} -> {1}".format(port_obj.address, egress_port[index]))
                                eport_lc, eport_port, eport_lane = self._parse_lport(
                                    egress_port[index])
                                if len(egress_port) == 1:
                                    eport_lane = lane + 1
                                if _blades.has_key(
                                        eport_lc) and eport_lane == lane + 1:
                                    port_id = self._qport(
                                        eport_port, eport_lane)
                                    mapped_to = _blades[eport_lc][port_id]
                                    mapped_to.add_mapping(port_obj)
                                    self._logger.info(
                                        "$$$ {0} mapped to {1}".format(
                                            port_obj.address,
                                            mapped_to.address))
                else:
                    port_id = self._qport(port + 1)
                    port_obj = blade[port_id]
                    for egress_port in egress:
                        eport = self._parse_lport(egress_port[0])
                        if _blades.has_key(eport[0]):
                            port_id = self._qport(eport[1])
                            mapped_to = _blades[eport[0]][port_id]
                            mapped_to.add_mapping(port_obj)
                            self._logger.info("$$$ {0} mapped to {1}".format(
                                port_obj.address, mapped_to.address))

        return ResourceDescriptionResponseInfo([chassis])