コード例 #1
0
def power_server_ucsm(sg, servers, action): 
    """
    perform power operations (hardreset, off, on..) for UCS Manager. 
    """
    # we expect servers to be a hash of like:
    # {blades: ["1/1", "1/2",..], rack: ["6", "7"]}
    try:
        handle = UCSUtil.ucs_login(sg)
    except KubamError as e:
        return jsonify({"error": str(e)}), Const.HTTP_UNAUTHORIZED
    try: 
        ucs_servers = servers_to_objects(handle, servers) 
    except KubamError as e:
        UCSUtil.ucs_logout(handle)
        return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST

    for i in ucs_servers:
        try: 
            UCSServer.power_server(handle, i, action)
        except KubamError as e:
            UCSUtil.ucs_logout(handle)
            return jsonify({"error": str(e)}), Const.HTTP_BAD_REQUEST
    UCSUtil.ucs_logout(handle)
    powerstat = UCSUtil.objects_to_servers(ucs_servers, ["oper_power"])
    return jsonify({"status": powerstat}), Const.HTTP_CREATED
コード例 #2
0
def powerstat_ucsm(sg, wanted_servers):
    """
    Get the power stat of the UCS Manager servers.
    """
    try:
        handle = UCSUtil.ucs_login(sg)
    except KubamError as e:
        return jsonify({"error": str(e)}), Const.HTTP_UNAUTHORIZED
    try: 
        powerstat = UCSServer.list_servers(handle)
        if not wanted_servers == "all":
            powerstat = UCSUtil.servers_to_objects(powerstat, wanted_servers)
        powerstat = UCSUtil.objects_to_servers(powerstat, ["oper_power"])
    except KubamError as e:
        UCSUtil.ucs_logout(handle)
        return jsonify({"error": str(e)}), Const.HTTP_UNAUTHORIZED
    UCSUtil.ucs_logout(handle)
    return powerstat