Example #1
0
    def is_member_active(elem_t, member_id):
        if 'member-states' not in elem_t:
            return True

        for ms, elem_ms in six.iteritems(elem_t['member-states']):
            if Member.normalize(ms) == Member.normalize(member_id):
                state = elem_ms.get('state', CPState.ACTIVE)
                return CPState.is_active(state)

        return True
Example #2
0
    def get_active_member_count(elem_t):
        mc = elem_t.get('member-count', 1)

        if 'member-states' not in elem_t:
            return mc

        for ms, elem_ms in six.iteritems(elem_t['member-states']):
            state = elem_ms.get('state', CPState.ACTIVE)
            if not CPState.is_active(state):
                mc -= 1

        return mc
    def is_active(cloud_model, elem_s):
        if isinstance(elem_s, dict):
            if 'state' in elem_s:
                state = elem_s.get('state', CPState.ACTIVE)
                return CPState.is_active(state)

            if Server.is_allocated(elem_s):
                name = Server.hostname(elem_s)
                if ResourceNode.is_resource_node(name):
                    return Server.is_resource_node_active(cloud_model, name)

        elif ResourceNode.is_resource_node(elem_s):
            return Server.is_resource_node_active(cloud_model, elem_s)

        return True
Example #4
0
    def is_active(cloud_model, elem_s):
        if isinstance(elem_s, dict):
            if 'state' in elem_s:
                state = elem_s.get('state', CPState.ACTIVE)
                return CPState.is_active(state)

            if Server.is_allocated(elem_s):
                name = Server.hostname(elem_s)
                if ResourceNode.is_resource_node(name):
                    return Server.is_resource_node_active(cloud_model, name)

        elif ResourceNode.is_resource_node(elem_s):
            return Server.is_resource_node_active(cloud_model, elem_s)

        return True
    def get_active_count(elem_cp, node_type):
        resource_nodes = elem_cp.get('resource-nodes', dict())
        for rn, elem_rn in six.iteritems(resource_nodes):
            if rn.lower() != node_type.lower():
                continue

            count = elem_rn.get('count', 0)
            states = elem_rn.get('states', dict())
            for s, elem_s in six.iteritems(states):
                state = elem_s.get('state', 'active')
                if not CPState.is_active(state):
                    count -= 1

            return count

        return 0
Example #6
0
    def is_deleted(models, controllers, elem_s):
        state_persistor = StatePersistor(
            models, controllers, persistence_file='server_allocations.yml')

        info = state_persistor.recall_info()
        for k, v in six.iteritems(info):
            if (v['pxe-mac-addr'] != elem_s['pxe-mac-addr']
                    or v['pxe-ip-addr'] != elem_s['pxe-ip-addr']):
                continue

            if 'state' not in v:
                return False

            if not CPState.is_active(v['state']):
                return True

            return False

        return False
    def is_active(elem_cp, node_type, rn):
        if isinstance(rn, int):
            rn_id = int(rn)
        else:
            rn_id = ResourceNode.id_from_hostname(rn)

        resource_nodes = elem_cp.get('resource-nodes', dict())
        for rn, elem_rn in six.iteritems(resource_nodes):
            if rn.lower() != node_type.lower():
                continue

            states = elem_rn.get('states', dict())
            for s, elem_s in six.iteritems(states):
                if int(s) != rn_id:
                    continue

                state = elem_s.get('state', 'active')
                return CPState.is_active(state)

        return True
    def is_deleted(models, controllers, elem_s):
        state_persistor = StatePersistor(
            models, controllers,
            persistence_file='server_allocations.yml')

        info = state_persistor.recall_info()
        for k, v in six.iteritems(info):
            if (v['pxe-mac-addr'] != elem_s['pxe-mac-addr'] or
                    v['pxe-ip-addr'] != elem_s['pxe-ip-addr']):
                continue

            if 'state' not in v:
                return False

            if not CPState.is_active(v['state']):
                return True

            return False

        return False
Example #9
0
 def is_active(elem_cp):
     state = elem_cp.get('state', CPState.ACTIVE)
     return CPState.is_active(state)
Example #10
0
    def is_active_or_empty(elem_t):
        state = elem_t.get('state', None)
        if state:
            return CPState.is_active(state)

        return True
Example #11
0
    def is_active(elem_t):
        state = elem_t.get('state', None)
        if state:
            return CPState.is_active(state)

        return len(elem_t['services']) > 0