'Define FC Connectivity.'

@proxy._trace_time
def _define_fc(self, host_bunch):

    fc_targets = []
    if (len(host_bunch.get('wwpns')) > 0):
        connected_wwpns = []
        for wwpn in host_bunch.get('wwpns'):
            component_ids = list(set([p.component_id for p in self._call_xiv_xcli('fc_connectivity_list', wwpn=wwpn.replace(':', ''))]))
            wwpn_fc_target_lists = []
            for component in component_ids:
                wwpn_fc_target_lists += [fc_p.wwpn for fc_p in self._call_xiv_xcli('fc_port_list', fcport=component)]
            LOG.debug('got    %(tgts)s    fc    targets    for    wwpn    %(wwpn)s', {'tgts': wwpn_fc_target_lists, 'wwpn': wwpn})
            if (len(wwpn_fc_target_lists) > 0):
                connected_wwpns += [wwpn]
                fc_targets += wwpn_fc_target_lists
            LOG.debug('adding    fc    port    %s', wwpn)
            self._call_xiv_xcli('host_add_port', host=host_bunch.get('name'), fcaddress=wwpn)
        if (len(connected_wwpns) == 0):
            LOG.error(CONNECTIVITY_FC_NO_TARGETS)
            raise self._get_exception()(CONNECTIVITY_FC_NO_TARGETS)
    else:
        msg = _("No    Fibre    Channel    HBA's    are    defined    on    the    host.")
        LOG.error(msg)
        raise self._get_exception()(msg)
    return fc_targets
