Esempio n. 1
0
    def get_properties(self, req_props):
        properties = {}

        selector = dmutils.Selector(req_props)
        if req_props is not None and len(req_props) > 0:
            selected = selector.list_selector
        else:
            selected = selector.all_selector

        if selected(consts.NODE_NAME):
            properties[consts.NODE_NAME] = (
                self._assignment.get_node().get_name()
            )
        if selected(consts.RES_NAME):
            properties[consts.RES_NAME]  = (
                self._assignment.get_resource().get_name()
            )
        if selected(consts.SNAPS_NAME):
            properties[consts.SNAPS_NAME]  = self._snapshot.get_name()

        # target state flags
        if selected(consts.TSTATE_PREFIX + consts.FLAG_DEPLOY):
            properties[consts.TSTATE_PREFIX + consts.FLAG_DEPLOY] = (
                dmutils.bool_to_string(
                    dmutils.is_set(self._tstate, self.FLAG_DEPLOY)
                )
            )

        # current state flags
        if selected(consts.CSTATE_PREFIX + consts.FLAG_DEPLOY):
            properties[consts.CSTATE_PREFIX + consts.FLAG_DEPLOY] = (
                dmutils.bool_to_string(
                    dmutils.is_set(self._cstate, self.FLAG_DEPLOY)
                )
            )

        # Add PropsContainer properties
        for (key, val) in self.get_props().iteritems():
            if selected(key):
                if val is not None:
                    properties[key] = str(val)

        return properties
Esempio n. 2
0
    def get_properties(self, req_props):
        properties = {}

        selector = dmutils.Selector(req_props)
        if req_props is not None and len(req_props) > 0:
            selected = selector.list_selector
        else:
            selected = selector.all_selector

        if selected(consts.VOL_ID):
            properties[consts.VOL_ID] = str(self._vol_id)
        if selected(consts.VOL_BDEV):
            properties[consts.VOL_BDEV] = (
                "" if self._bd_path is None else str(self._bd_path)
            )

        # target state flags
        if selected(consts.TSTATE_PREFIX + consts.FLAG_DEPLOY):
            properties[consts.TSTATE_PREFIX + consts.FLAG_DEPLOY] = (
                dmutils.bool_to_string(
                    dmutils.is_set(self._tstate, self.FLAG_DEPLOY)
                )
            )

        # current state flags
        if selected(consts.CSTATE_PREFIX + consts.FLAG_DEPLOY):
            properties[consts.CSTATE_PREFIX + consts.FLAG_DEPLOY] = (
                dmutils.bool_to_string(
                    dmutils.is_set(self._cstate, self.FLAG_DEPLOY)
                )
            )

        # Add PropsContainer properties
        for (key, val) in self.get_props().iteritems():
            if selected(key):
                if val is not None:
                    properties[key] = str(val)

        return properties
Esempio n. 3
0
    def _get_assignments(self, res, vol_spec):

        diskful = []

        for a in res.iterate_assignments():
            tstate = a.get_tstate()

            if dm_utils.is_set(tstate, a.FLAG_DISKLESS):
                continue

            for vol_state in a.iterate_volume_states():
                vid = vol_state.get_id()

                # Only "interesting" volumes
                if isinstance(vol_spec, long):
                    if vid != vol_spec:
                        continue

                while (len(diskful) <= vid):
                    diskful.append([])

                diskful[vid].append(
                    dm_utils.is_set(vol_state.get_cstate(),
                                    vol_state.FLAG_DEPLOY)
                    and dm_utils.is_set(vol_state.get_tstate(),
                                        vol_state.FLAG_DEPLOY))

        # look for the most scarce volume, and return its statistics
        min_depl = 1000
        ret = []
        for v, deployed_l in enumerate(diskful):
            deployed = sum(deployed_l)
            assert (deployed >= 0 and deployed <= 63)

            if deployed < min_depl:
                ret = deployed_l
                min_depl = deployed

        return ret
Esempio n. 4
0
 def requires_undeploy(self):
     return (dmutils.is_unset(self._tstate, self.FLAG_DEPLOY) and
             dmutils.is_set(self._cstate, self.FLAG_DEPLOY))
Esempio n. 5
0
 def is_deployed(self):
     return dmutils.is_set(self._cstate, self.FLAG_DEPLOY)
Esempio n. 6
0
 def requires_undeploy(self):
     """
     Returns True if the assignment needs to be undeployed, False otherwise
     """
     return (dmutils.is_unset(self._tstate, self.FLAG_DEPLOY) and
             dmutils.is_set(self._cstate, self.FLAG_DEPLOY))