Esempio n. 1
0
 def _build_blade(self, blade_name):
     """
     :type blade_name: str
     """
     blade_model = 'Matrix ' + blade_name
     serial_number = 'NA'
     resource_model = 'Rome Matrix {}'.format(blade_name)
     blade = Blade(blade_name.upper(), resource_model, serial_number)
     blade.set_model_name(blade_model)
     blade.set_serial_number(serial_number)
     blade.set_parent_resource(self.chassis)
     return blade
 def _build_blade(self, blade_name):
     blade_model = 'Panel'
     serial_number = 'NA'
     blade = Blade(blade_name, 'Generic L1 Module', serial_number)
     blade.set_model_name(blade_model)
     blade.set_serial_number(serial_number)
     return blade
    def _build_blades(self, chassis_dict):
        blades_dict = {}
        slots_attributes = ApconSlotAttributes(self._slot_table)
        for address, record in self._slot_table.iteritems():
            model_name = 'Generic L1 Module'
            blade_model = slots_attributes.model_name(address).value
            serial_number = slots_attributes.serial_number(address).value
            blade_address = Address(0, address)

            chassis_address = blade_address.get_chassis_address()
            try:
                chassis = chassis_dict[chassis_address]
            except KeyError:
                raise Exception(
                    'Fail to get information for the Chassis {}'.format(
                        chassis_address))

            blade = Blade(blade_address.index(), model_name, serial_number)
            blade.attributes = slots_attributes.get_attributes(address)
            blades_dict[blade_address] = blade
            blade.set_parent_resource(chassis)
        return blades_dict
 def _build_cards(self, chassis):
     self._logger.debug('Build Cards')
     cards = {}
     for card_data in self._card_table.values():
         card_type = card_data.get('sniEntityCardType')
         if card_type and card_type.strip("'") == 'funnelcard':
             card_index = card_data.get('sniEntityCardIndex')
             card_model = card_data.get('sniEntityCardAid')
             card_serial_num = card_data.get('sniEntityCardSerialNum')
             card = Blade(card_index, 'Generic L1 Module', card_serial_num)
             card.set_model_name(card_model)
             card.set_serial_number(card_serial_num)
             card.set_parent_resource(chassis)
             cards[card_index] = card
     return cards
Esempio n. 5
0
    def _build_blades(self, blade_name):
        """Build blades.

        :type blade_name: str
        :rtype: list[Blade]
        """
        for name in tuple(blade_name):  # ('A',) or ('Q',) or ('X', 'Y')
            blade_model = "Matrix " + name
            serial_number = "NA"
            resource_model = "Rome Matrix {}".format(name)
            blade = Blade(name.upper(), resource_model, serial_number)
            blade.set_model_name(blade_model)
            blade.set_serial_number(serial_number)
            blade.set_parent_resource(self.chassis)
            yield blade
 def _build_blades(self, chassis_dict):
     """
     Build blades using data from slot table
     :param chassis_dict:
     :return:
     """
     blades_dict = {}
     for address, record in self._slot_table.iteritems():
         blade_model = record.get('nbsCmmcSlotModel') or record.get('Model')
         serial_number = record.get('nbsCmmcSlotSerialNum') or record.get(
             'SerialNum')
         chassis = chassis_dict.get(address.get_chassis_address())
         if chassis and blade_model and blade_model.lower(
         ) != 'n/a' and blade_model not in self.IGNORE_BLADES:
             blade = Blade(address.index(), 'Generic L1 Module',
                           serial_number)
             blade.set_model_name(blade_model)
             blade.set_serial_number(serial_number)
             blades_dict[address] = blade
             blade.set_parent_resource(chassis)
     return blades_dict
Esempio n. 7
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])
Esempio n. 9
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_blade(self, chassis_dict):
     blade_model = 'Virtal Wire Module'
     blade = Blade(self._blade_id)
     blade.set_model_name(blade_model)
     blade.set_parent_resource(chassis_dict.get(self._chassis_id))
     return {self._blade_id: blade}
Esempio n. 11
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])
Esempio 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

            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])