Ejemplo n.º 1
0
 def rename_node(clusterid, old_compute_name, new_compute_name):
     url = Comet.url("cluster/{}/compute/{}/rename".format(
         clusterid, old_compute_name))
     data = {"name": "%s" % new_compute_name}
     ret = ""
     r = Comet.post(url, data=data)
     # print (r)
     if r is not None:
         if '' != r.strip():
             ret = r
         else:
             ret = "Request Accepted."
     return ret
Ejemplo n.º 2
0
 def rename_node(clusterid, old_compute_name, new_compute_name):
     url = Comet.url("cluster/{}/compute/{}/rename"\
                     .format(clusterid, old_compute_name))
     data = {"name":"%s" % new_compute_name}
     ret = ""
     r = Comet.post(url, data=data)
     print (r)
     if r is not None:
         if '' != r.strip():
             ret = r
         else:
             ret = "Requeset Accepted."
     return ret
Ejemplo n.º 3
0
    def computeset_start(clusterid,
                         computenodeids=None,
                         numnodes=None,
                         allocation=None,
                         walltime=None):
        ret = ''
        # print ("clusterid: %s" % clusterid)
        # print ("computenodeids: %s" % computenodeids)
        # print ("numnodes: %s" % numnodes)
        # print ("allocation: %s" % allocation)
        # print ("walltime: %s" % walltime)
        data = None
        # validating and initiating allocation and walltime values
        if not allocation:
            cluster = Cluster.list(clusterid, format='rest')
            # use the first one if no provided
            allocation = cluster[0]['allocations'][0]
        if not walltime:
            walltime = Cluster.WALLTIME_MINS

        # preparing parameters for the post call
        # num of nodes to start
        #
        # Now it accepts
        # {"cluster":"vc3","computes":"compute[1-2]"},
        # {"cluster":"vc3","computes":["compute1","compute2"]} and
        # {"cluster":"vc3","count":2}
        #
        if numnodes:
            data = {
                "cluster": "%s" % clusterid,
                "count": "%s" % numnodes,
                "walltime_mins": "%s" % walltime,
                "allocation": "%s" % allocation
            }
        # computenodeids in hostlist format
        elif computenodeids:
            nodes_free = Cluster.check_nodes_computesets(
                clusterid, computenodeids)[0]
            if not nodes_free:
                Console.error("Some nodes are already in active computesets",
                              traceflag=False)
                return ret
            else:
                data = {
                    "computes": "%s" % computenodeids,
                    "cluster": "%s" % clusterid,
                    "walltime_mins": "%s" % walltime,
                    "allocation": "%s" % allocation
                }

        # print("Issuing request to poweron nodes...")
        posturl = Comet.url("computeset/")
        # print ("POST data: %s" % data)
        r = Comet.post(posturl, data=data)
        # print("RETURNED RESULTS:")
        # print (r)
        if 'cluster' in r:
            if 'state' in r and \
                            r['state'] in Cluster.PENDING_COMPUTESETS:
                computesetid = r['id']
                ret = 'Request accepted! Check status with:\n' \
                      'comet cluster {}\n'.format(clusterid) + \
                      'or:\n' \
                      'comet computeset {}\n'.format(computesetid)
            else:
                # in case of some internal problem
                ret = ''
        elif 'error' in r:
            ret = "An error occurred: {}".format(r['error'])
        else:
            ret = "An internal error occured. " \
                  "Please submit a ticket with the " \
                  "following info:\n {}\n" \
                .format(r)
        return ret
Ejemplo n.º 4
0
    def power(clusterid, subject, param=None, action=None,
              allocation=None, walltime=None, numnodes=None):

        # print("SUBJECT to perform action on: {}".format(subject))
        # print("\ton cluster: {}".format(clusterid))
        # print("\tAction: {}".format(action))
        # print("\tParameter: {}".format(param))
        # print("\tAllocation: {}".format(allocation))
        # print("\tWalltime: {}".format(walltime))

        # the API is now accepting hostlist format directly
        # computeIdsHostlist = hostlist.collect_hostlist(computeids)
        # print (computeIdsHostlist)
        ret = ''

        #
        # Now it accepts
        # {"cluster":"vc3","computes":"compute[1-2]"},
        # {"cluster":"vc3","computes":["compute1","compute2"]} and
        # {"cluster":"vc3","count":2}
        #
        if subject in ['HOSTS', 'HOST']:
            # power on N arbitrary nodes
            if numnodes:
                if "on" == action:
                    if not allocation:
                        cluster = Cluster.list(clusterid, format='rest')
                        # use the first one if no provided
                        allocation = cluster[0]['allocations'][0]
                    if not walltime:
                        walltime = Cluster.WALLTIME_MINS

                    posturl = Comet.url("computeset/")
                    data = {"cluster":"%s" % clusterid,
                            "count": "%s" % numnodes,
                            "walltime_mins": "%s" % walltime,
                            "allocation": "%s" % allocation}

                    r = Comet.post(posturl, data=data)
                    # print("RETURNED RESULTS:")
                    # print (r)
                    if 'cluster' in r:
                        if 'state' in r and \
                           ('queued' == r['state'] or \
                           'submitted' == r['state'] or \
                           'created' == r['state']):
                            computesetid = r['id']
                            ret = 'Request accepted! Check status with:\n' \
                                  'comet cluster {}\n'.format(clusterid) + \
                                  'or:\n' \
                                  'comet computeset {}\n'.format(computesetid)
                        else:
                            # in case of some internal problem
                            ret = ''
                    elif 'error' in r:
                        ret = "An error occurred: {}".format(r['error'])
                    else:
                        ret = "An internal error occured. "\
                              "Please submit a ticket with the "\
                              "following info:\n {}\n"\
                              .format(r)
                # cannot power off or reboot N arbitrary nodes
                else:
                    ret = "Action NOT SUPPORTED! Try with explicit "\
                          "node name(s) or computeset id"
            # parse based on NODEPARAM parameter
            # could be computeset id; front end; or hostlist named compute nodes
            else:
                hosts_param = hostlist.expand_hostlist(param)
                hosts_param_set = set(hosts_param)
                nodes_free = True
                nodes_allocated = False
                nodes_checked = False
                # computesetid = -1
                computesets = Comet.get_computeset()
                for computeset in computesets:
                    if computeset["cluster"] == clusterid \
                            and (computeset["state"] == "started" or
                                 computeset["state"] == "running"):
                        computesetid = computeset["id"]
                        # print (computesetid)
                        hosts = set()
                        for compute in computeset["computes"]:
                            hosts.add(compute["name"])
                        # print (hosts)
                        if hosts_param_set <= hosts:
                            nodes_allocated = True
                            nodes_free = False
                            nodes_checked = True
                        # at least one specified host not in any Active computeset
                        else:
                            for host in hosts_param:
                                # some specified nodes are in Active computeset
                                if host in hosts:
                                    nodes_free = False
                                    nodes_checked = True
                                    break
                    # a cluster could have multiple 'started' set
                    if nodes_checked:
                        break
                # print ("nodes_checked: %s" % nodes_checked)
                # print ("nodes_allocated: %s" % nodes_allocated)
                # print ("nodes_free: %s" % nodes_free)
                if not (nodes_free or nodes_allocated):
                    ret = "Error: Some nodes are already in active computesets"
                else:
                    if "on" == action:
                        if not allocation:
                            cluster = Cluster.list(clusterid, format='rest')
                            # use the first one if no provided
                            allocation = cluster[0]['allocations'][0]
                        if not walltime:
                            walltime = Cluster.WALLTIME_MINS

                        data = {"computes": "%s" % param,
                                "cluster": "%s" % clusterid,
                                "walltime_mins": "%s" % walltime,
                                "allocation": "%s" % allocation}

                        if nodes_free:
                            # print("Issuing request to poweron nodes...")
                            url = Comet.url("computeset/")
                            posturl = url
                            # print (data)

                            r = Comet.post(posturl, data=data)
                            # print("RETURNED RESULTS:")
                            # print (r)
                            if 'cluster' in r:
                                if 'state' in r and \
                                   ('queued' == r['state'] or 'submitted' == r['state']):
                                    computesetid = r['id']
                                    ret = 'Request accepted! Check status with:\n' \
                                          'comet cluster {}\n'.format(clusterid) + \
                                          'or:\n' \
                                          'comet computeset {}\n'.format(computesetid)
                                else:
                                    # in case of some internal problem
                                    ret = ''
                            elif 'error' in r:
                                ret = "An error occurred: {}".format(r['error'])
                            else:
                                ret = "An internal error occured. "\
                                      "Please submit a ticket with the "\
                                      "following info:\n {}\n"\
                                      .format(r)
                        elif nodes_allocated:
                            ret = ""
                            for host in hosts_param:
                                url = Comet.url("cluster/{}/compute/{}/"
                                                .format(clusterid, host))
                                action = "poweron"
                                puturl = "{}{}".format(url, action)
                                # print (puturl)
                                r = Comet.put(puturl)
                                if r is not None:
                                    if '' != r.strip():
                                        ret += r
                                    else:
                                        ret += "Requeset Accepted. "\
                                               "In the process of power on node {}\n"\
                                               .format(host)
                                else:
                                    ret += "Problem executing the request. "\
                                        "Check if the node {} belongs to the cluster"\
                                        .format(host)
                        # print(ret)
                    elif action in ["off", "reboot", "reset", "shutdown"]:
                        if action in ["off"]:
                            action = "power{}".format(action)
                        if nodes_allocated:
                            ret = ""
                            for host in hosts_param:
                                url = Comet.url("cluster/{}/compute/{}/"
                                                .format(clusterid, host))
                                puturl = "{}{}".format(url, action)
                                # print (puturl)
                                r = Comet.put(puturl)
                                if r is not None:
                                    if '' != r.strip():
                                        ret = r
                                    else:
                                        ret += "Requeset Accepted. "\
                                            "In the process of {} node {}\n"\
                                            .format(action, host)
                                else:
                                    ret += "Problem executing the request. "\
                                        "Check if the node {} belongs to the cluster"\
                                        .format(host)
                        elif nodes_free:
                            ret = "Error: The specified nodes are "\
                                  "not in active computesets"
                    else:
                        ret = "Action not supported! Try these: "\
                              "on/off/reboot/reset/shutdown"
        elif 'FE' == subject:
            url = Comet.url("cluster/{}/frontend/".format(clusterid))
            if action in ["on", "off", "reboot", "reset", "shutdown"]:
                if action in ["on", "off"]:
                    action = "power{}".format(action)
                puturl = "{}{}".format(url, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the front-end node".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the cluster exists"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        elif 'COMPUTESET' == subject:
            url = Comet.url("computeset/")
            if 'on' == action:
                ret = "NOT SUPPORTED! Use hostslist to specify the hosts to power on!"
            elif action in ["off", "reboot", "reset", "shutdown"]:
                if action in ["off"]:
                    action = "power{}".format(action)
                puturl = "{:}{:}/{}".format(url, param, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the nodes".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the computeset exists"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        '''
        elif 'HOST' == subject:
            computesets = Comet.get_computeset()
            pprint (computesets)
            for computeset in computesets:
                if computeset["cluster"] == clusterid \
                        and (computeset["state"] == "started" \
                             or computeset["state"] == "running"):
                    computesetid = computeset["id"]
                    # print (computesetid)
                    hosts = set()
                    for compute in computeset["computes"]:
                        hosts.add(compute["name"])
                    # print (hosts)
                    is_valid_set = True
                    hostsparam = Parameter.expand(param)
                    for host in hostsparam:
                        if host not in hosts:
                            is_valid_set = False
                            break 
            url = Comet.url("cluster/{}/compute/{}/".format(clusterid, param))
            if action in ["on", "off", "reboot", "reset", "shutdown"]:
                if action in ["on", "off"]:
                    action = "power{}".format(action)
                puturl = "{}{}".format(url, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the nodes".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the node belongs to the cluster"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        '''
        # """
        return ret
Ejemplo n.º 5
0
    def computeset_start(clusterid,
                         computenodeids=None,
                         numnodes=None,
                         allocation=None,
                         walltime=None):
        ret = ''
        # print ("clusterid: %s" % clusterid)
        # print ("computenodeids: %s" % computenodeids)
        # print ("numnodes: %s" % numnodes)
        # print ("allocation: %s" % allocation)
        # print ("walltime: %s" % walltime)
        data = None
        # validating and initiating allocation and walltime values
        if not allocation:
            cluster = Cluster.list(clusterid, format='rest')
            # use the first one if no provided
            allocation = cluster[0]['allocations'][0]
        if not walltime:
            walltime = Cluster.WALLTIME_MINS

        # preparing parameters for the post call
        # num of nodes to start
        #
        # Now it accepts
        # {"cluster":"vc3","computes":"compute[1-2]"},
        # {"cluster":"vc3","computes":["compute1","compute2"]} and
        # {"cluster":"vc3","count":2}
        #
        if numnodes:
            data = {"cluster": "%s" % clusterid,
                    "count": "%s" % numnodes,
                    "walltime_mins": "%s" % walltime,
                    "allocation": "%s" % allocation}
        # computenodeids in hostlist format
        elif computenodeids:
            nodes_free = Cluster.check_nodes_computesets(clusterid, computenodeids)[0]
            if not nodes_free:
                Console.error("Some nodes are already in active computesets",
                              traceflag=False)
                return ret
            else:
                data = {"computes": "%s" % computenodeids,
                        "cluster": "%s" % clusterid,
                        "walltime_mins": "%s" % walltime,
                        "allocation": "%s" % allocation}

        # print("Issuing request to poweron nodes...")
        posturl = Comet.url("computeset/")
        # print ("POST data: %s" % data)
        r = Comet.post(posturl, data=data)
        # print("RETURNED RESULTS:")
        # print (r)
        if 'cluster' in r:
            if 'state' in r and \
                            r['state'] in Cluster.PENDING_COMPUTESETS:
                computesetid = r['id']
                ret = 'Request accepted! Check status with:\n' \
                      'comet cluster {}\n'.format(clusterid) + \
                      'or:\n' \
                      'comet computeset {}\n'.format(computesetid)
            else:
                # in case of some internal problem
                ret = ''
        elif 'error' in r:
            ret = "An error occurred: {}".format(r['error'])
        else:
            ret = "An internal error occured. " \
                  "Please submit a ticket with the " \
                  "following info:\n {}\n" \
                .format(r)
        return ret
Ejemplo n.º 6
0
    def power(clusterid, subject, param=None, action=None):

        # print("SUBJECT to perform action on: {}".format(subject))
        # print("\ton cluster: {}".format(clusterid))
        # print("\tAction: {}".format(action))
        # print("\tParameter: {}".format(param))

        # the API is now accepting hostlist format directly
        # computeIdsHostlist = hostlist.collect_hostlist(computeids)
        # print (computeIdsHostlist)
        ret = ''
        if 'HOSTS' == subject:
            url = Comet.url("computeset/")

            # data = {
            #    "computes": [{"name": vm, "host": "comet-{:}".format(vm)} for vm in
            #                 computeids], "cluster": "%s" % id}
            data = {"computes": "%s" % param,
                    "cluster": "%s" % clusterid,
                    "walltime_mins": "%s" % Cluster.WALLTIME_MINS}

            # print (data)
            if "on" == action:
                # print("Issuing request to poweron nodes...")
                posturl = url
                # print (data)

                r = Comet.post(posturl, data=data)
                # print("RETURNED RESULTS:")
                # print (r)
                if 'cluster' in r:
                    if 'state' in r and \
                       ('queued' == r['state'] or 'submitted' == r['state']):
                        computesetid = r['id']
                        ret = 'Request accepted! Check status with:\n' \
                              'comet cluster {}\n'.format(clusterid) + \
                              'or:\n' \
                              'comet computeset {}\n'.format(computesetid)
                    else:
                        # in case of some internal problem
                        ret = ''
                elif 'error' in r:
                    ret = "An error occurred: {}".format(r['error'])
                else:
                    ret = "An internal error occured. " \
                          "Please submit a ticket with following info:\n {}\n" \
                        .format(r)
                # print(ret)
            elif action in ["off", "reboot", "reset", "shutdown"]:
                if action in ["off"]:
                    action = "power{}".format(action)
                # print("finding the computesetid of the specified nodes...")
                computesets = Comet.get_computeset()
                # print ("computesets")
                # pprint (computesets)

                is_valid_set = False
                # computesetid = -1
                for computeset in computesets:
                    if computeset["cluster"] == clusterid \
                            and (computeset["state"] == "started" \
                                 or computeset["state"] == "running"):
                        computesetid = computeset["id"]
                        # print (computesetid)
                        hosts = set()
                        for compute in computeset["computes"]:
                            hosts.add(compute["name"])
                        # print (hosts)
                        is_valid_set = True
                        hostsparam = Parameter.expand(param)
                        for host in hostsparam:
                            if host not in hosts:
                                is_valid_set = False
                                break
                    # a cluster could have multiple 'started' set
                    if is_valid_set:
                        break
                if is_valid_set:
                    # print("Issuing request to poweroff nodes...")
                    # print("computesetid: {}".format(computesetid))
                    puturl = "{:}{:}/{}".format(url, computesetid, action)
                    # print (puturl)
                    r = Comet.put(puturl)
                    # print("RETURNED RESULTS:")
                    # print(r)
                    if r is not None:
                        if '' != r.strip():
                            ret = r
                            # print(r)
                        else:
                            ret = "Requeset Accepted. "\
                                  "In the process of {} the nodes".format(action)
                    else:
                        ret = "Unknown error: POWER, HOSTS"
                else:
                    ret = "All the nodes are not in the specified cluster, "\
                          "or they are not running"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        elif 'FE' == subject:
            url = Comet.url("cluster/{}/frontend/".format(clusterid))
            if action in ["on", "off", "reboot", "reset", "shutdown"]:
                if action in ["on", "off"]:
                    action = "power{}".format(action)
                puturl = "{}{}".format(url, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the nodes".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the cluster exists"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        elif 'COMPUTESET' == subject:
            url = Comet.url("computeset/")
            if 'on' == action:
                ret = "NOT SUPPORTED! Use hostslist to specify the hosts to power on!"
            elif action in ["off", "reboot", "reset", "shutdown"]:
                if action in ["off"]:
                    action = "power{}".format(action)
                puturl = "{:}{:}/{}".format(url, param, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the nodes".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the computeset exists"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        elif 'HOST' == subject:
            url = Comet.url("cluster/{}/compute/{}/".format(clusterid, param))
            if action in ["on", "off", "reboot", "reset", "shutdown"]:
                if action in ["on", "off"]:
                    action = "power{}".format(action)
                puturl = "{}{}".format(url, action)
                # print (puturl)
                r = Comet.put(puturl)
                if r is not None:
                    if '' != r.strip():
                        ret = r
                    else:
                        ret = "Requeset Accepted. "\
                              "In the process of {} the nodes".format(action)
                else:
                    ret = "Problem executing the request. "\
                          "Check if the node belongs to the cluster"
            else:
                ret = "Action not supported! Try these: on/off/reboot/reset/shutdown"
        return ret