Exemple #1
0
def get_sis_vol_dict(na_server, vserver, volume=None):
    """Queries sis for volumes.

        If volume is present sis is queried for it.
        Records dedup and compression enabled.
    """

    sis_vols = {}
    query_attr = {"vserver": vserver}
    if volume:
        vol_path = "/vol/%s" % (volume)
        query_attr["path"] = vol_path
    query = {"sis-status-info": query_attr}
    try:
        result = netapp_api.invoke_api(na_server, api_name="sis-get-iter", api_family="cm", query=query, is_iter=True)
        for res in result:
            attr_list = res.get_child_by_name("attributes-list")
            if attr_list:
                sis_status = attr_list.get_children()
                for sis in sis_status:
                    path = sis.get_child_content("path")
                    if not path:
                        continue
                    (___, __, vol) = path.rpartition("/")
                    if not vol:
                        continue
                    v_sis = {}
                    v_sis["compression"] = na_utils.to_bool(sis.get_child_content("is-compression-enabled"))
                    v_sis["dedup"] = na_utils.to_bool(sis.get_child_content("state"))
                    sis_vols[vol] = v_sis
    except Exception as e:
        LOG.debug("Exception querying sis information. %s", e)
    return sis_vols
Exemple #2
0
def get_sis_vol_dict(na_server, vserver, volume=None):
    """Queries sis for volumes.

        If volume is present sis is queried for it.
        Records dedup and compression enabled.
    """

    sis_vols = {}
    query_attr = {'vserver': vserver}
    if volume:
        vol_path = '/vol/%s' % (volume)
        query_attr['path'] = vol_path
    query = {'sis-status-info': query_attr}
    try:
        result = netapp_api.invoke_api(na_server,
                                       api_name='sis-get-iter',
                                       api_family='cm',
                                       query=query,
                                       is_iter=True)
        for res in result:
            attr_list = res.get_child_by_name('attributes-list')
            if attr_list:
                sis_status = attr_list.get_children()
                for sis in sis_status:
                    path = sis.get_child_content('path')
                    if not path:
                        continue
                    (___, __, vol) = path.rpartition('/')
                    if not vol:
                        continue
                    v_sis = {}
                    v_sis['compression'] = na_utils.to_bool(
                        sis.get_child_content('is-compression-enabled'))
                    v_sis['dedup'] = na_utils.to_bool(
                        sis.get_child_content('state'))
                    sis_vols[vol] = v_sis
    except Exception as e:
        LOG.debug("Exception querying sis information. %s", e)
    return sis_vols
Exemple #3
0
def create_vol_list(vol_attrs):
    """Creates vol list with features from attr list."""
    vols = set()
    for v in vol_attrs:
        try:
            # name and vserver are mandatory
            # Absence will skip by giving KeyError.
            name = v["volume-id-attributes"]["name"]
            vserver = v["volume-id-attributes"]["owning-vserver-name"]
            vol = NetAppVolume(name, vserver)
            vol.id["type"] = v["volume-id-attributes"].get_child_content("type")
            if vol.id["type"] == "tmp":
                continue
            vol.id["junction_path"] = v["volume-id-attributes"].get_child_content("junction-path")
            # state attributes mandatory.
            vol.state["vserver_root"] = na_utils.to_bool(
                v["volume-state-attributes"].get_child_content("is-vserver-root")
            )
            if vol.state["vserver_root"]:
                continue
            vol.state["status"] = v["volume-state-attributes"].get_child_content("state")
            vol.state["inconsistent"] = na_utils.to_bool(
                v["volume-state-attributes"].get_child_content("is-inconsistent")
            )
            vol.state["invalid"] = na_utils.to_bool(v["volume-state-attributes"].get_child_content("is-invalid"))
            vol.state["junction_active"] = na_utils.to_bool(
                v["volume-state-attributes"].get_child_content("is-junction-active")
            )
            vol.state["cluster_volume"] = na_utils.to_bool(
                v["volume-state-attributes"].get_child_content("is-cluster-volume")
            )
            if vol.state["status"] != "online" or vol.state["inconsistent"] or vol.state["invalid"]:
                # offline, invalid and inconsistent volumes are not usable
                continue
            # aggr attributes mandatory.
            vol.aggr["name"] = v["volume-id-attributes"]["containing-aggregate-name"]
            # space attributes mandatory.
            vol.space["size_avl_bytes"] = v["volume-space-attributes"]["size-available"]
            vol.space["size_total_bytes"] = v["volume-space-attributes"]["size-total"]
            vol.space["space-guarantee-enabled"] = na_utils.to_bool(
                v["volume-space-attributes"].get_child_content("is-space-guarantee-enabled")
            )
            vol.space["space-guarantee"] = v["volume-space-attributes"].get_child_content("space-guarantee")
            # qos attributes optional.
            if v.get_child_by_name("volume-qos-attributes"):
                vol.qos["qos_policy_group"] = v["volume-qos-attributes"].get_child_content("policy-group-name")
            else:
                vol.qos["qos_policy_group"] = None
            vols.add(vol)
        except KeyError as e:
            LOG.debug("Unexpected error while creating" " ssc vol list. Message - %s" % six.text_type(e))
            continue
    return vols
Exemple #4
0
    def test_create_volume_with_extra_spec(self, spec, key, value):
        fake_volume = get_fake_volume()
        extra_specs = {spec: value}
        volume = copy.deepcopy(eseries_fake.VOLUME)

        self.library._client.create_volume = mock.Mock(
            return_value=volume)
        # Make this utility method return our extra spec
        mocked_spec_method = self.mock_object(na_utils,
                                              'get_volume_extra_specs')
        mocked_spec_method.return_value = extra_specs

        self.library.create_volume(fake_volume)

        self.assertEqual(1, self.library._client.create_volume.call_count)
        # Ensure create_volume is called with the correct argument
        args, kwargs = self.library._client.create_volume.call_args
        self.assertIn(key, kwargs)
        if(value is not None):
            expected = na_utils.to_bool(value)
        else:
            expected = value
        self.assertEqual(expected, kwargs[key])
Exemple #5
0
 def test_to_bool(self):
     self.assertTrue(na_utils.to_bool(True))
     self.assertTrue(na_utils.to_bool('true'))
     self.assertTrue(na_utils.to_bool('yes'))
     self.assertTrue(na_utils.to_bool('y'))
     self.assertTrue(na_utils.to_bool(1))
     self.assertTrue(na_utils.to_bool('1'))
     self.assertFalse(na_utils.to_bool(False))
     self.assertFalse(na_utils.to_bool('false'))
     self.assertFalse(na_utils.to_bool('asdf'))
     self.assertFalse(na_utils.to_bool('no'))
     self.assertFalse(na_utils.to_bool('n'))
     self.assertFalse(na_utils.to_bool(0))
     self.assertFalse(na_utils.to_bool('0'))
     self.assertFalse(na_utils.to_bool(2))
     self.assertFalse(na_utils.to_bool('2'))
Exemple #6
0
def get_volumes_for_specs(ssc_vols, specs):
    """Shortlists volumes for extra specs provided."""
    if specs is None or specs == {} or not isinstance(specs, dict):
        return ssc_vols['all']
    result = copy.deepcopy(ssc_vols['all'])
    raid_type = specs.get('netapp:raid_type')
    disk_type = specs.get('netapp:disk_type')
    bool_specs_list = ['netapp_mirrored', 'netapp_unmirrored',
                       'netapp_dedup', 'netapp_nodedup',
                       'netapp_compression', 'netapp_nocompression',
                       'netapp_thin_provisioned', 'netapp_thick_provisioned']
    b_specs = {}
    for spec in bool_specs_list:
        b_specs[spec] = na_utils.to_bool(specs.get(spec))\
            if specs.get(spec) else None

    def _spec_ineffect(b_specs, spec, opp_spec):
        """If the spec with opposite spec is ineffective."""
        if ((b_specs[spec] is None and b_specs[opp_spec] is None)
                or (b_specs[spec] == b_specs[opp_spec])):
            return True
        else:
            return False

    if _spec_ineffect(b_specs, 'netapp_mirrored', 'netapp_unmirrored'):
        pass
    else:
        if b_specs['netapp_mirrored'] or b_specs['netapp_unmirrored'] is False:
            result = result & ssc_vols['mirrored']
        else:
            result = result - ssc_vols['mirrored']
    if _spec_ineffect(b_specs, 'netapp_dedup', 'netapp_nodedup'):
        pass
    else:
        if b_specs['netapp_dedup'] or b_specs['netapp_nodedup'] is False:
            result = result & ssc_vols['dedup']
        else:
            result = result - ssc_vols['dedup']
    if _spec_ineffect(b_specs, 'netapp_compression', 'netapp_nocompression'):
        pass
    else:
        if (b_specs['netapp_compression'] or
                b_specs['netapp_nocompression'] is False):
            result = result & ssc_vols['compression']
        else:
            result = result - ssc_vols['compression']
    if _spec_ineffect(b_specs, 'netapp_thin_provisioned',
                      'netapp_thick_provisioned'):
        pass
    else:
        if (b_specs['netapp_thin_provisioned'] or
                b_specs['netapp_thick_provisioned'] is False):
            result = result & ssc_vols['thin']
        else:
            result = result - ssc_vols['thin']
    if raid_type or disk_type:
        tmp = copy.deepcopy(result)
        for vol in tmp:
            if raid_type:
                vol_raid = vol.aggr['raid_type']
                vol_raid = vol_raid.lower() if vol_raid else None
                if raid_type.lower() != vol_raid:
                    result.discard(vol)
            if disk_type:
                vol_dtype = vol.aggr['disk_type']
                vol_dtype = vol_dtype.lower() if vol_dtype else None
                if disk_type.lower() != vol_dtype:
                    result.discard(vol)
    return result
Exemple #7
0
def create_vol_list(vol_attrs):
    """Creates vol list with features from attr list."""
    vols = set()
    for v in vol_attrs:
        try:
            # name and vserver are mandatory
            # Absence will skip by giving KeyError.
            name = v['volume-id-attributes']['name']
            vserver = v['volume-id-attributes']['owning-vserver-name']
            vol = NetAppVolume(name, vserver)
            vol.id['type'] =\
                v['volume-id-attributes'].get_child_content('type')
            if vol.id['type'] == "tmp":
                continue
            vol.id['junction_path'] =\
                v['volume-id-attributes'].get_child_content('junction-path')
            # state attributes mandatory.
            vol.state['vserver_root'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-vserver-root'))
            if vol.state['vserver_root']:
                continue
            vol.state['status'] =\
                v['volume-state-attributes'].get_child_content('state')
            vol.state['inconsistent'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-inconsistent'))
            vol.state['invalid'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-invalid'))
            vol.state['junction_active'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-junction-active'))
            vol.state['cluster_volume'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-cluster-volume'))
            if (vol.state['status'] != 'online' or
                    vol.state['inconsistent'] or vol.state['invalid']):
                # offline, invalid and inconsistent volumes are not usable
                continue
            # aggr attributes mandatory.
            vol.aggr['name'] =\
                v['volume-id-attributes']['containing-aggregate-name']
            # space attributes mandatory.
            vol.space['size_avl_bytes'] =\
                v['volume-space-attributes']['size-available']
            vol.space['size_total_bytes'] =\
                v['volume-space-attributes']['size-total']
            vol.space['space-guarantee-enabled'] =\
                na_utils.to_bool(
                    v['volume-space-attributes'].get_child_content(
                        'is-space-guarantee-enabled'))
            vol.space['space-guarantee'] =\
                v['volume-space-attributes'].get_child_content(
                    'space-guarantee')
            # qos attributes optional.
            if v.get_child_by_name('volume-qos-attributes'):
                vol.qos['qos_policy_group'] =\
                    v['volume-qos-attributes'].get_child_content(
                        'policy-group-name')
            else:
                vol.qos['qos_policy_group'] = None
            vols.add(vol)
        except KeyError as e:
            LOG.debug('Unexpected error while creating'
                      ' ssc vol list. Message - %s', e)
            continue
    return vols
Exemple #8
0
def create_vol_list(vol_attrs):
    """Creates vol list with features from attr list."""
    vols = set()
    for v in vol_attrs:
        try:
            # name and vserver are mandatory
            # Absence will skip by giving KeyError.
            name = v['volume-id-attributes']['name']
            vserver = v['volume-id-attributes']['owning-vserver-name']
            vol = NetAppVolume(name, vserver)
            vol.id['type'] =\
                v['volume-id-attributes'].get_child_content('type')
            if vol.id['type'] == "tmp":
                continue
            vol.id['junction_path'] =\
                v['volume-id-attributes'].get_child_content('junction-path')
            # state attributes mandatory.
            vol.state['vserver_root'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-vserver-root'))
            if vol.state['vserver_root']:
                continue
            vol.state['status'] =\
                v['volume-state-attributes'].get_child_content('state')
            vol.state['inconsistent'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-inconsistent'))
            vol.state['invalid'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-invalid'))
            vol.state['junction_active'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-junction-active'))
            vol.state['cluster_volume'] =\
                na_utils.to_bool(
                    v['volume-state-attributes'].get_child_content(
                        'is-cluster-volume'))
            if (vol.state['status'] != 'online' or vol.state['inconsistent']
                    or vol.state['invalid']):
                # offline, invalid and inconsistent volumes are not usable
                continue
            # aggr attributes mandatory.
            vol.aggr['name'] =\
                v['volume-id-attributes']['containing-aggregate-name']
            # space attributes mandatory.
            vol.space['size_avl_bytes'] =\
                v['volume-space-attributes']['size-available']
            vol.space['size_total_bytes'] =\
                v['volume-space-attributes']['size-total']
            vol.space['space-guarantee-enabled'] =\
                na_utils.to_bool(
                    v['volume-space-attributes'].get_child_content(
                        'is-space-guarantee-enabled'))
            vol.space['space-guarantee'] =\
                v['volume-space-attributes'].get_child_content(
                    'space-guarantee')
            # qos attributes optional.
            if v.get_child_by_name('volume-qos-attributes'):
                vol.qos['qos_policy_group'] =\
                    v['volume-qos-attributes'].get_child_content(
                        'policy-group-name')
            else:
                vol.qos['qos_policy_group'] = None
            vols.add(vol)
        except KeyError as e:
            LOG.debug('Unexpected error while creating'
                      ' ssc vol list. Message - %s' % six.text_type(e))
            continue
    return vols
Exemple #9
0
def get_volumes_for_specs(ssc_vols, specs):
    """Shortlists volumes for extra specs provided."""
    if specs is None or specs == {} or not isinstance(specs, dict):
        return ssc_vols['all']
    result = copy.deepcopy(ssc_vols['all'])
    raid_type = specs.get('netapp:raid_type')
    disk_type = specs.get('netapp:disk_type')
    bool_specs_list = ['netapp_mirrored', 'netapp_unmirrored',
                       'netapp_dedup', 'netapp_nodedup',
                       'netapp_compression', 'netapp_nocompression',
                       'netapp_thin_provisioned', 'netapp_thick_provisioned']
    b_specs = {}
    for spec in bool_specs_list:
        b_specs[spec] = na_utils.to_bool(specs.get(spec))\
            if specs.get(spec) else None

    def _spec_ineffect(b_specs, spec, opp_spec):
        """If the spec with opposite spec is ineffective."""
        if ((b_specs[spec] is None and b_specs[opp_spec] is None)
                or (b_specs[spec] == b_specs[opp_spec])):
            return True
        else:
            return False

    if _spec_ineffect(b_specs, 'netapp_mirrored', 'netapp_unmirrored'):
        pass
    else:
        if b_specs['netapp_mirrored'] or b_specs['netapp_unmirrored'] is False:
            result = result & ssc_vols['mirrored']
        else:
            result = result - ssc_vols['mirrored']
    if _spec_ineffect(b_specs, 'netapp_dedup', 'netapp_nodedup'):
        pass
    else:
        if b_specs['netapp_dedup'] or b_specs['netapp_nodedup'] is False:
            result = result & ssc_vols['dedup']
        else:
            result = result - ssc_vols['dedup']
    if _spec_ineffect(b_specs, 'netapp_compression', 'netapp_nocompression'):
        pass
    else:
        if (b_specs['netapp_compression'] or
                b_specs['netapp_nocompression'] is False):
            result = result & ssc_vols['compression']
        else:
            result = result - ssc_vols['compression']
    if _spec_ineffect(b_specs, 'netapp_thin_provisioned',
                      'netapp_thick_provisioned'):
        pass
    else:
        if (b_specs['netapp_thin_provisioned'] or
                b_specs['netapp_thick_provisioned'] is False):
            result = result & ssc_vols['thin']
        else:
            result = result - ssc_vols['thin']
    if raid_type or disk_type:
        tmp = copy.deepcopy(result)
        for vol in tmp:
            if raid_type:
                vol_raid = vol.aggr['raid_type']
                vol_raid = vol_raid.lower() if vol_raid else None
                if raid_type.lower() != vol_raid:
                    result.discard(vol)
            if disk_type:
                vol_dtype = vol.aggr['disk_type']
                vol_dtype = vol_dtype.lower() if vol_dtype else None
                if disk_type.lower() != vol_dtype:
                    result.discard(vol)
    return result
Exemple #10
0
 def test_to_bool(self):
     self.assertTrue(na_utils.to_bool(True))
     self.assertTrue(na_utils.to_bool('true'))
     self.assertTrue(na_utils.to_bool('yes'))
     self.assertTrue(na_utils.to_bool('y'))
     self.assertTrue(na_utils.to_bool(1))
     self.assertTrue(na_utils.to_bool('1'))
     self.assertFalse(na_utils.to_bool(False))
     self.assertFalse(na_utils.to_bool('false'))
     self.assertFalse(na_utils.to_bool('asdf'))
     self.assertFalse(na_utils.to_bool('no'))
     self.assertFalse(na_utils.to_bool('n'))
     self.assertFalse(na_utils.to_bool(0))
     self.assertFalse(na_utils.to_bool('0'))
     self.assertFalse(na_utils.to_bool(2))
     self.assertFalse(na_utils.to_bool('2'))
Exemple #11
0
 def test_to_bool(self):
     self.assertTrue(na_utils.to_bool(True))
     self.assertTrue(na_utils.to_bool("true"))
     self.assertTrue(na_utils.to_bool("yes"))
     self.assertTrue(na_utils.to_bool("y"))
     self.assertTrue(na_utils.to_bool(1))
     self.assertTrue(na_utils.to_bool("1"))
     self.assertFalse(na_utils.to_bool(False))
     self.assertFalse(na_utils.to_bool("false"))
     self.assertFalse(na_utils.to_bool("asdf"))
     self.assertFalse(na_utils.to_bool("no"))
     self.assertFalse(na_utils.to_bool("n"))
     self.assertFalse(na_utils.to_bool(0))
     self.assertFalse(na_utils.to_bool("0"))
     self.assertFalse(na_utils.to_bool(2))
     self.assertFalse(na_utils.to_bool("2"))
Exemple #12
0
def get_volumes_for_specs(ssc_vols, specs):
    """Shortlists volumes for extra specs provided."""
    if specs is None or not isinstance(specs, dict):
        return ssc_vols["all"]
    result = copy.deepcopy(ssc_vols["all"])
    raid_type = specs.get("netapp:raid_type")
    disk_type = specs.get("netapp:disk_type")
    bool_specs_list = [
        "netapp_mirrored",
        "netapp_unmirrored",
        "netapp_dedup",
        "netapp_nodedup",
        "netapp_compression",
        "netapp_nocompression",
        "netapp_thin_provisioned",
        "netapp_thick_provisioned",
    ]
    b_specs = {}
    for spec in bool_specs_list:
        b_specs[spec] = na_utils.to_bool(specs.get(spec)) if specs.get(spec) else None

    def _spec_ineffect(b_specs, spec, opp_spec):
        """If the spec with opposite spec is ineffective."""
        if (b_specs[spec] is None and b_specs[opp_spec] is None) or (b_specs[spec] == b_specs[opp_spec]):
            return True
        else:
            return False

    if _spec_ineffect(b_specs, "netapp_mirrored", "netapp_unmirrored"):
        pass
    else:
        if b_specs["netapp_mirrored"] or b_specs["netapp_unmirrored"] is False:
            result = result & ssc_vols["mirrored"]
        else:
            result = result - ssc_vols["mirrored"]
    if _spec_ineffect(b_specs, "netapp_dedup", "netapp_nodedup"):
        pass
    else:
        if b_specs["netapp_dedup"] or b_specs["netapp_nodedup"] is False:
            result = result & ssc_vols["dedup"]
        else:
            result = result - ssc_vols["dedup"]
    if _spec_ineffect(b_specs, "netapp_compression", "netapp_nocompression"):
        pass
    else:
        if b_specs["netapp_compression"] or b_specs["netapp_nocompression"] is False:
            result = result & ssc_vols["compression"]
        else:
            result = result - ssc_vols["compression"]
    if _spec_ineffect(b_specs, "netapp_thin_provisioned", "netapp_thick_provisioned"):
        pass
    else:
        if b_specs["netapp_thin_provisioned"] or b_specs["netapp_thick_provisioned"] is False:
            result = result & ssc_vols["thin"]
        else:
            result = result - ssc_vols["thin"]
    if raid_type or disk_type:
        tmp = copy.deepcopy(result)
        for vol in tmp:
            if raid_type:
                vol_raid = vol.aggr["raid_type"]
                vol_raid = vol_raid.lower() if vol_raid else None
                if raid_type.lower() != vol_raid:
                    result.discard(vol)
            if disk_type:
                vol_dtype = vol.aggr["disk_type"]
                vol_dtype = vol_dtype.lower() if vol_dtype else None
                if disk_type.lower() != vol_dtype:
                    result.discard(vol)
    return result