from pyhpecfm import fabric
from lib.actions import HpecfmBaseAction

class fabricIpLookup(HpecfmBaseAction):
    def run(self):
        cfm_fabrics = fabric.get_fabric_ip_networks(self.client)
        if isinstance(cfm_fabrics, list):
            fabric_data = []
            # Loop through cfm_fabrics and process IPZ
            for fabip in cfm_fabrics:
                desc = fabip['description']
                if desc == '':
                    desc = 'HPE Composable Fabric'
                out ={
                        'u_desc':desc,
                        'u_fabu_uid':fabip['fabric_uuid'],
                        'u_name':fabip['name'],
                        'u_mode':fabip['mode'],
                        'u_sub_address':fabip['subnet']['address'],
                        'u_mask_prefix':fabip['subnet']['prefix_length']
                      }
                fabric_data.append(out)

            return (True, fabric_data)
        return (False, switches)
