def _get_hg_state_hdlr(methods, params):
    '''Helper Method to get Hybrid Group State'''
    obj = cps_object.CPSObject(obj=params['filter'])
    resp = params['list']

    if obj.get_key() == hg_utils.hg_state_key:
        hg_name = nas_if.get_cps_attr(obj, hg_utils.hg_state_attr('id'))
        return _service_get_hg_state(hg_name, resp)

    nas_if.log_err("Key Error: Hybrid Group State Key issue")
    return False
def create_hg_state_cps_obj(hg_obj):
    '''Helper Method to generate Hybrid Group State'''
    if hg_obj is None:
        nas_if.log_err("Hybrid Group is None")
        return None

    obj = cps_object.CPSObject(
        module='base-pg/dell-pg/port-groups-state/hybrid-group-state',
        qual='observed',
        data={
            hg_utils.hg_state_attr('id'):
            hg_obj.name,
            hg_utils.hg_state_attr('default-profile'):
            hg_obj.get_hybrid_group_default_profile_mode(),
            hg_utils.base_hg_state_attr('front-panel-port'):
            hg_obj.get_fp_ports(),
            hg_utils.base_hg_state_attr('hwport-list'):
            hg_obj.get_hw_ports()
        })

    # Add description field for each Hybrid Group.
    for profile_mode_idx, profile_mode in enumerate(
            hg_obj.get_supported_hybrid_group_profile_modes()):

        profile_description = str(profile_mode)
        for fpp_idx, fpp_num in enumerate(hg_obj.get_fp_ports()):

            port = fp.find_front_panel_port(fpp_num)
            hybrid_profile = port.get_hybrid_profile()
            port_profile_name = str(
                hybrid_profile.get_port_profile(profile_mode))
            port_profile = fp.get_port_profile(port_profile_name)
            desc = (("; Port %d - %s ") % (fpp_num, port_profile.description))
            profile_description += desc

        obj.add_embed_attr([
            hg_utils.hg_state_attr('supported-profiles'),
            str(profile_mode_idx), 'profile-name'
        ], str(profile_mode), 6)
        obj.add_embed_attr([
            hg_utils.hg_state_attr('supported-profiles'),
            str(profile_mode_idx), 'profile-description'
        ], str(profile_description), 6)

    for fpp_idx, fpp_num in enumerate(hg_obj.get_fp_ports()):

        port = fp.find_front_panel_port(fpp_num)
        prev_port_profile_name = port.get_profile_type()
        hybrid_profile = port.get_hybrid_profile()

        for profile_mode_idx, profile_mode in enumerate(
                hybrid_profile.profile_modes):

            cur_port_profile_name = str(
                hybrid_profile.get_port_profile(profile_mode))
            port.apply_port_profile(fp.get_port_profile(cur_port_profile_name))

            obj.add_embed_attr(
                [hg_utils.hg_state_attr('port'),
                 str(fpp_idx), 'port-id'], str(fpp_num), 6)
            obj.add_embed_attr([
                hg_utils.hg_state_attr('port'),
                str(fpp_idx), 'profile',
                str(profile_mode_idx), 'name'
            ], str(profile_mode), 8)
            obj.add_embed_attr([
                hg_utils.hg_state_attr('port'),
                str(fpp_idx), 'profile',
                str(profile_mode_idx), 'default-phy-mode'
            ], str(port.get_def_phy_mode()), 8)
            obj.add_embed_attr([
                hg_utils.hg_state_attr('port'),
                str(fpp_idx), 'profile',
                str(profile_mode_idx), 'default-breakout-mode'
            ], str(port.get_def_breakout()), 8)
            obj.add_embed_attr([
                hg_utils.hg_state_attr('port'),
                str(fpp_idx), 'profile',
                str(profile_mode_idx), 'default-port-speed'
            ], str(port.get_default_phy_port_speed()), 8)

            cap_idx = 0
            for mode in port.get_breakout_caps():
                for hw_speed in port.get_hwport_speed_caps():

                    phy_npu_speed = fp.get_phy_npu_port_speed(
                        mode, (hw_speed * len(hg_obj.get_hw_ports())) /
                        len(hg_obj.get_fp_ports()))
                    if False is fp.verify_npu_supported_speed(phy_npu_speed):
                        continue

                    obj.add_embed_attr([
                        hg_utils.hg_state_attr('port'),
                        str(fpp_idx), 'profile',
                        str(profile_mode_idx), 'br-cap',
                        str(cap_idx), 'phy-mode'
                    ], str(nas_comm.yang.get_value('ether', 'yang-phy-mode')),
                                       10)
                    obj.add_embed_attr([
                        hg_utils.hg_state_attr('port'),
                        str(fpp_idx), 'profile',
                        str(profile_mode_idx), 'br-cap',
                        str(cap_idx), 'breakout-mode'
                    ], str(mode), 10)
                    obj.add_embed_attr([
                        hg_utils.hg_state_attr('port'),
                        str(fpp_idx), 'profile',
                        str(profile_mode_idx), 'br-cap',
                        str(cap_idx), 'port-speed'
                    ], str(phy_npu_speed), 10)
                    obj.add_embed_attr([
                        hg_utils.hg_state_attr('port'),
                        str(fpp_idx), 'profile',
                        str(profile_mode_idx), 'br-cap',
                        str(cap_idx), 'skip-ports'
                    ], str(
                        nas_comm.yang.get_tbl('breakout-to-skip-port')[mode]),
                                       10)
                    cap_idx += 1

        port.apply_port_profile(fp.get_port_profile(prev_port_profile_name))
    return obj