コード例 #1
0
def _verify_and_update_lb_state(store,
                                lb_id,
                                set_state=True,
                                current_timestamp=None):
    """
    Based on the current state, the metadata on the lb and the time since the LB has
    been in that state, set the appropriate state in store.lbs
    Note: Reconsider if update metadata is implemented
    """
    current_timestring = datetime.utcfromtimestamp(current_timestamp).strftime(
        time_format)
    if store.lbs[lb_id]["status"] == "BUILD":
        store.meta[lb_id][
            "lb_building"] = store.meta[lb_id]["lb_building"] or 10
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"],
            store.meta[lb_id]["lb_building"],
            current_timestamp=current_timestamp) or "BUILD"

    elif store.lbs[lb_id]["status"] == "ACTIVE" and set_state:
        if "lb_pending_update" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "PENDING-UPDATE"
            log.msg("here")
            log.msg(store.lbs[lb_id]["status"])
        if "lb_pending_delete" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "PENDING-DELETE"
        if "lb_error_state" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "ERROR"
        store.lbs[lb_id]["updated"]["time"] = current_timestring

    elif store.lbs[lb_id]["status"] == "PENDING-UPDATE":
        if "lb_pending_update" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = set_resource_status(
                store.lbs[lb_id]["updated"]["time"],
                store.meta[lb_id]["lb_pending_update"],
                current_timestamp=current_timestamp) or "PENDING-UPDATE"

    elif store.lbs[lb_id]["status"] == "PENDING-DELETE":
        store.meta[lb_id][
            "lb_pending_delete"] = store.meta[lb_id]["lb_pending_delete"] or 10
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"],
            store.meta[lb_id]["lb_pending_delete"],
            "DELETED",
            current_timestamp=current_timestamp) or "PENDING-DELETE"
        store.lbs[lb_id]["updated"]["time"] = current_timestring

    elif store.lbs[lb_id]["status"] == "DELETED":
        # see del_load_balancer above for an explanation of this state change.
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"],
            3600,
            "DELETING-NOW",
            current_timestamp=current_timestamp) or "DELETED"
        if store.lbs[lb_id]["status"] == "DELETING-NOW":
            del store.lbs[lb_id]
コード例 #2
0
ファイル: loadbalancer.py プロジェクト: isaacm/mimic
def _verify_and_update_lb_state(store, lb_id, set_state=True,
                                current_timestamp=None):
    """
    Based on the current state, the metadata on the lb and the time since the LB has
    been in that state, set the appropriate state in store.lbs
    Note: Reconsider if update metadata is implemented
    """
    current_timestring = seconds_to_timestamp(current_timestamp)
    if store.lbs[lb_id]["status"] == "BUILD":
        store.meta[lb_id]["lb_building"] = store.meta[lb_id]["lb_building"] or 10
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"],
            store.meta[lb_id]["lb_building"],
            current_timestamp=current_timestamp
        ) or "BUILD"

    elif store.lbs[lb_id]["status"] == "ACTIVE" and set_state:
        if "lb_pending_update" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "PENDING-UPDATE"
            log.msg("here")
            log.msg(store.lbs[lb_id]["status"])
        if "lb_pending_delete" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "PENDING-DELETE"
        if "lb_error_state" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = "ERROR"
        store.lbs[lb_id]["updated"]["time"] = current_timestring

    elif store.lbs[lb_id]["status"] == "PENDING-UPDATE":
        if "lb_pending_update" in store.meta[lb_id]:
            store.lbs[lb_id]["status"] = set_resource_status(
                store.lbs[lb_id]["updated"]["time"],
                store.meta[lb_id]["lb_pending_update"],
                current_timestamp=current_timestamp
            ) or "PENDING-UPDATE"

    elif store.lbs[lb_id]["status"] == "PENDING-DELETE":
        store.meta[lb_id]["lb_pending_delete"] = store.meta[lb_id]["lb_pending_delete"] or 10
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"],
            store.meta[lb_id]["lb_pending_delete"], "DELETED",
            current_timestamp=current_timestamp
        ) or "PENDING-DELETE"
        store.lbs[lb_id]["updated"]["time"] = current_timestring

    elif store.lbs[lb_id]["status"] == "DELETED":
        # see del_load_balancer above for an explanation of this state change.
        store.lbs[lb_id]["status"] = set_resource_status(
            store.lbs[lb_id]["updated"]["time"], 3600, "DELETING-NOW",
            current_timestamp=current_timestamp
        ) or "DELETED"
        if store.lbs[lb_id]["status"] == "DELETING-NOW":
            del store.lbs[lb_id]
コード例 #3
0
ファイル: nova.py プロジェクト: venkateshsampath/mimic
def set_server_state(server_id):
    """
    If the server status is not active, sets the state of the server based on the
    server metadata
    """
    if s_cache[server_id]['status'] != "ACTIVE":
            if 'server_building' in s_cache[server_id]['metadata']:
                status = set_resource_status(
                    s_cache[server_id]['updated'],
                    int(s_cache[server_id]['metadata']['server_building']))
                s_cache[server_id]['status'] = status or s_cache[server_id]['status']
コード例 #4
0
ファイル: nova.py プロジェクト: jirwin/mimic
def set_server_state(server_id):
    """
    If the server status is not active, sets the state of the server based on the
    server metadata
    """
    if s_cache[server_id]['status'] != "ACTIVE":
        if 'server_building' in s_cache[server_id]['metadata']:
            status = set_resource_status(
                s_cache[server_id]['updated'],
                int(s_cache[server_id]['metadata']['server_building']))
            s_cache[server_id][
                'status'] = status or s_cache[server_id]['status']
コード例 #5
0
ファイル: nova.py プロジェクト: kivattik/mimic
def set_server_state(server_id):
    """
    If the server status is not active, sets the state of the server based on
    the server metadata.

    :param str server_id: the ID of a server, a key present in
        :pyobj:`s_cache`.
    """
    if s_cache[server_id]['status'] != "ACTIVE":
        if 'server_building' in s_cache[server_id]['metadata']:
            status = set_resource_status(
                s_cache[server_id]['updated'],
                int(s_cache[server_id]['metadata']['server_building']))
            s_cache[server_id]['status'] = (status or
                                            s_cache[server_id]['status'])
コード例 #6
0
ファイル: nova.py プロジェクト: maxlinc/mimic
def set_server_state(server_id, s_cache, current_timestamp):
    """
    If the server status is not active, sets the state of the server based on
    the server metadata.

    :param str server_id: the ID of a server, a key present in
        :pyobj:`s_cache`.
    """
    if s_cache[server_id]['status'] != "ACTIVE":
        if 'server_building' in s_cache[server_id]['metadata']:
            updated_timestring = s_cache[server_id]['updated']
            status = set_resource_status(
                updated_timestring,
                int(s_cache[server_id]['metadata']['server_building']),
                current_timestamp=current_timestamp)
            s_cache[server_id]['status'] = (status
                                            or s_cache[server_id]['status'])