Ejemplo n.º 1
0
def comet_status(request):
    # noinspection PyUnusedLocal
    c = comet_logon(request)
    data = json.loads(Cluster.simple_list(format="json"))
    # pprint(data)
    # print (type(data))

    clusters = []
    for key in data:
        total = data[key]["nodes"]
        name = data[key]["name"]
        if name == "comet-fe1":
            name = "free"
        cluster = {
            "name": name,
            "total": total,
            "status": {
                'active': 0,
                'nostate': 0,
                'down': 0,
                'pending': 0,
                'unkown': total
            }
        }
        clusters.append(cluster)

    details = json.loads(Cluster.list(format="json"))

    counter = {}
    for node in details.values():
        clustername = node["cluster"]
        if clustername is not None:
            if clustername not in counter:
                counter[clustername] = {
                    'name': None,
                    'total': 0,
                    'status': {
                        'unkown': 0,
                        'active': 0,
                        'down': 0,
                        'pending': 0,
                        'nostate': 0,
                        'nostate-error': 0
                    }
                }

    # print (counter)
    for key, node in details.items():

        if node['kind'] == 'compute':

            name = node['cluster']
            state = node['state']

            if state in [None, 'None']:
                state = 'unkown'

            # print ("SSSSSSS", state, name, node['kind'])
            counter[name]['status'][state] += 1
            counter[name]['total'] += 1
            counter[name]['name'] = name
    pprint(counter)
    #
    # delete the free nodes for now
    #
    if 'comet-fe1' in counter:
        for count in counter:
            if count != "comet-fe1":
                counter['comet-fe1']['total'] = \
                    counter['comet-fe1']['total'] - counter[count]['total']

        counter['comet-fe1']['name'] = 'free'
    counter_list = []
    for key, cluster in counter.items():
        counter_list.append(cluster)

    # context["clusters"] = counter_list

    Chart.cluster_overview_pie(counter_list, filename='pie.svg')

    #
    # delete the overall count
    #
    if 'comet-fe1' in counter:
        del counter['comet-fe1']
    counter_list = []
    for key, cluster in counter.items():
        counter_list.append(cluster)

    Chart.cluster_overview_pie_vector(counter_list, filename='pie_vector.svg')
    Chart.cluster_overview_radar(counter_list, filename='radar.svg')

    context = {
        'pid': str(Comet.find_tunnel()),
        'tunnel': str(Comet.is_tunnel()),
        'title': "Comet Status"
    }

    return render(request, 'cloudmesh_portal/comet/status.jinja', context)
Ejemplo n.º 2
0
    def do_comet(self, args, arguments):
        """
        ::

            Usage:
               comet status
               comet tunnel start
               comet tunnel stop
               comet tunnel status
               comet logon
               comet logoff
               comet ll [CLUSTERID] [--format=FORMAT]
               comet docs
               comet info [--user=USER]
                            [--project=PROJECT]
                            [--format=FORMAT]
               comet cluster [CLUSTERID][--name=NAMES]
                            [--user=USER]
                            [--project=PROJECT]
                            [--hosts=HOSTS]
                            [--start=TIME_START]
                            [--end=TIME_END]
                            [--hosts=HOSTS]
                            [--format=FORMAT]
               comet computeset [COMPUTESETID]
               comet start ID
               comet stop ID
               comet power (on|off|reboot|reset|shutdown) CLUSTERID [NODESPARAM]
               comet console CLUSTERID [COMPUTENODEID]
               comet delete [all]
                              [--user=USER]
                              [--project=PROJECT]
                              [--name=NAMES]
                              [--hosts=HOSTS]
                              [--start=TIME_START]
                              [--end=TIME_END]
                              [--host=HOST]
               comet delete --file=FILE
               comet update [--name=NAMES]
                              [--hosts=HOSTS]
                              [--start=TIME_START]
                              [--end=TIME_END]
               comet add [--user=USER]
                           [--project=PROJECT]
                           [--host=HOST]
                           [--description=DESCRIPTION]
                           [--start=TIME_START]
                           [--end=TIME_END]
                           NAME
               comet add --file=FILENAME

            Options:
                --user=USER           user name
                --name=NAMES          Names of the vcluster
                --start=TIME_START    Start time of the vcluster, in
                                      YYYY/MM/DD HH:MM:SS format.
                                      [default: 1901-01-01]
                --end=TIME_END        End time of the vcluster, in YYYY/MM/DD
                                      HH:MM:SS format. In addition a duratio
                                      can be specified if the + sign is the
                                      first sig The duration will than be
                                      added to the start time.
                                      [default: 2100-12-31]
                --project=PROJECT     project id
                --host=HOST           host name
                --description=DESCRIPTION  description summary of the vcluster
                --file=FILE           Adding multiple vclusters from one file
                --format=FORMAT       Format is either table, json, yaml,
                                      csv, rest
                                      [default: table]

            Arguments:
                FILENAME  the file to open in the cwd if . is
                          specified. If file in in cwd
                          you must specify it with ./FILENAME

            Opens the given URL in a browser window.
        """

        if not arguments["tunnel"] and Comet.tunnelled and not Comet.is_tunnel():
            Console.error("Please establish a tunnel first with:")
            print
            print ("    comet tunnel start")
            print
            return ""

        try:

            if not arguments["tunnel"]:
                logon = Comet.logon()
                if logon is False:
                    Console.error("Could not logon")
                    return ""
        except:
            Console.error("Could not logon")
        # pprint (arguments)
        output_format = arguments["--format"] or "table"

        if arguments["status"]:

            Comet.state()

        elif arguments["tunnel"] and arguments["start"]:

            Comet.tunnel(True)

        elif arguments["tunnel"] and arguments["stop"]:

            Comet.tunnel(False)

        elif arguments["tunnel"] and arguments["status"]:

            Comet.state()

        elif arguments["logon"]:

            if self.context.comet_token is None:
                if Comet.logon():
                    Console.ok("logging on")
                    self.context.comet_token = Comet.token
                else:
                    Console.error("could not logon")
            else:
                Console.error("already logged on")

        elif arguments["logoff"]:

            if self.context.comet_token is None:
                Console.error("not logged in")
            else:
                if Comet.logoff():
                    Console.ok("Logging off")
                    self.context.comet_token = None
                else:
                    Console.error(
                        "some issue while logging off. Maybe comet not reachable")

        elif arguments["ll"]:

            cluster_id = arguments["CLUSTERID"] or None

            print(Cluster.simple_list(cluster_id, format=output_format))

        elif arguments["docs"]:

            Comet.docs()

        elif arguments["cluster"]:

            cluster_id = arguments["CLUSTERID"]
            print(Cluster.list(cluster_id, format=output_format))

        elif arguments["computeset"]:
            computeset_id = arguments["COMPUTESETID"]
            print (Cluster.computeset(computeset_id))

        elif arguments["info"]:

            Console.error("not yet implemented")

        elif arguments["add"]:

            print ("add the cluster")

        elif arguments["start"]:

            cluster_id = arguments["ID"]
            print("start", cluster_id)
            Cluster.start(cluster_id)

        elif arguments["stop"]:

            cluster_id = arguments["ID"]
            print("stop", cluster_id)
            Cluster.stop(cluster_id)

        elif arguments["power"]:

            clusterid = arguments["CLUSTERID"]
            fuzzyparam = None
            if 'NODESPARAM' in arguments:
                fuzzyparam = arguments["NODESPARAM"]
            param = fuzzyparam

            # no nodes param provided, action on front end
            if not fuzzyparam:
                subject = "FE"
                param = None
            # parse the nodes param
            else:
                try:
                    param = int(fuzzyparam)
                    subject = "COMPUTESET"
                    param = str(param)
                except ValueError:
                    if '[' in fuzzyparam and ']' in fuzzyparam:
                        subject = "HOSTS"
                    else:
                        subject = "HOST"

            if arguments["on"]:
                action = "on"
            elif arguments["off"]:
                action = "off"
            elif arguments["reboot"]:
                action = "reboot"
            elif arguments["reset"]:
                action = "reset"
            elif arguments["shutdown"]:
                action = "shutdown"
            else:
                action = None
            Cluster.power(clusterid, subject, param, action)
        elif arguments["console"]:
            clusterid = arguments["CLUSTERID"]
            nodeid = None
            if 'COMPUTENODEID' in arguments:
                nodeid = arguments["COMPUTENODEID"]
            Comet.console(clusterid, nodeid)
        return ""
Ejemplo n.º 3
0
def comet_status(request):
    # noinspection PyUnusedLocal
    c = comet_logon(request)
    data = json.loads(Cluster.simple_list(format="json"))
    # pprint(data)
    # print (type(data))

    clusters = []
    for key in data:
        total = data[key]["nodes"]
        name = data[key]["name"]
        if name == "comet-fe1":
            name = "free"
        cluster = {
            "name": name,
            "total": total,
            "status": {
                'active': 0,
                'nostate': 0,
                'down': 0,
                'pending': 0,
                'unkown': total
            }
        }
        clusters.append(cluster)

    details = json.loads(Cluster.list(format="json"))

    counter = {}
    for node in list(details.values()):
        clustername = node["cluster"]
        if clustername is not None:
            if clustername not in counter:
                counter[clustername] = {
                    'name': None,
                    'total': 0,
                    'status': {
                        'unkown': 0,
                        'active': 0,
                        'down': 0,
                        'pending': 0,
                        'nostate': 0,
                        'nostate-error': 0
                    }
                }

    # print (counter)
    for key, node in list(details.items()):

        if node['kind'] == 'compute':

            name = node['cluster']
            state = node['state']

            if state in [None, 'None']:
                state = 'unkown'

            # print ("SSSSSSS", state, name, node['kind'])
            counter[name]['status'][state] += 1
            counter[name]['total'] += 1
            counter[name]['name'] = name
    pprint(counter)
    #
    # delete the free nodes for now
    #
    if 'comet-fe1' in counter:
        for count in counter:
            if count != "comet-fe1":
                counter['comet-fe1']['total'] = \
                    counter['comet-fe1']['total'] - counter[count]['total']

        counter['comet-fe1']['name'] = 'free'
    counter_list = []
    for key, cluster in list(counter.items()):
        counter_list.append(cluster)

    # context["clusters"] = counter_list

    Chart.cluster_overview_pie(counter_list, filename='pie.svg')

    #
    # delete the overall count
    #
    if 'comet-fe1' in counter:
        del counter['comet-fe1']
    counter_list = []
    for key, cluster in list(counter.items()):
        counter_list.append(cluster)

    Chart.cluster_overview_pie_vector(counter_list, filename='pie_vector.svg')
    Chart.cluster_overview_radar(counter_list, filename='radar.svg')

    context = {
        'pid': str(Comet.find_tunnel()),
        'tunnel': str(Comet.is_tunnel()),
        'title': "Comet Status"
    }

    return render(request,
                  'cloudmesh_portal_comet/status.jinja',
                  context)