示例#1
0
def printUsers(site):
    global br
    r = br.get(site + actions['users'] + '?json=yes', headers=mkHeader(site))
    findError(r.json(), site)
    h = "{:<12} | {:<15} | {:<15} \t".format("user", "Bandwidth", "Disk Usage")
    print(h)
    print('=' * 60)
    for mess in range(int(r.json()["info"]["rows"])):
        if r.json()[str(mess)]["username"]["is_user"] == "yes":
            quota = float(r.json()[str(
                mess)]["quota"]["usage"]) if "unlimited" in r.json()[str(
                    mess)]["quota"]["limit"] else 100 * float(
                        r.json()[str(mess)]["quota"]["usage"]) / float(
                            r.json()[str(mess)]["quota"]["limit"])
            banwidth = float(r.json()[str(mess)]["bandwidth"]["usage"]) if "unlimited" in \
                                                                           r.json()[str(mess)]["bandwidth"][
                                                                               "limit"] else 100 * float(
                r.json()[str(mess)]["bandwidth"]["usage"]) / float(r.json()[str(mess)]["bandwidth"]["limit"])
            row = "{:<12} | {:<22}    | {:<22}    \t".format(
                r.json()[str(mess)]["username"]["value"],
                paint("{:.4f}/Unli".format(banwidth), 'f_green') if
                banwidth > 100 else warn(banwidth, "{:.4f}%".format(banwidth)),
                paint("{:.4f}/Unli".format(quota), 'f_green')
                if quota > 100 else warn(quota, "{:.4f}%".format(quota)))
            print(row)
    print('-' * 60)
示例#2
0
    def get_partition_from_job(self, job):
        if job.uuid in self.partition_cache:
            return self.partition_cache[job.uuid]

        try:
            client = zerorpc.Client()
            client.connect(job.address)
            obj_str = client.take(job.uuid)
            if obj_str is None:
                raise Exception("get_partition_from_job: Can't be None.")
        except zerorpc.RemoteError as e:
            if e.name == JobTaken.__name__:
                print warn('Remote job is taken. Skip.')
            elif e.name == JobFinished.__name__:
                print warn('Remote job is finished. Skip.')
            else:
                print error('Remote error at getting partition. Skip.')
            return None
        except zerorpc.LostRemote:
            print error('Lost remote at getting partition. Skip.')
            return None
        else:
            logger.info('take job:' + job.address)
            partition = load(obj_str)
            self.partition_cache[job.uuid] = partition
            return partition
示例#3
0
def printService(site):
    global br
    r = br.get(site + actions['services'] + '?json=yes',
               headers=mkHeader(site))
    head = "{:15} | {:7} | {:6} | {}  \t".format("Name", "Memory", "Status",
                                                 "Pids")
    print(head)
    findError(r.json(), site)
    for service in list(r.json()["memory"].keys()):
        pids = ''
        percentage = "{:17}".format(paint('0.00', 'f_blue'))
        if not r.json()["memory"][service] == "":
            percentage = warn(
                float(r.json()["memory"][service]) / 15.01,
                r.json()["memory"][service])
        if service in r.json()["pids"].keys():
            pids = ", ".join(r.json()["pids"][service])
        row = "{:15} | {:8} | {:6} | {}  \t".format(
            service, percentage,
            r.json()["status"][service], pids)
        print(row)
示例#4
0
def printStats(site):
    r = br.get(site + actions['stats'] + '?json=yes', headers=mkHeader(site))
    head = "{:25} | {:14}  | {:12}   | {:5} | {}  \t".format(
        "Filesystem", "Used", "Available", "Capacity", "Mounted on")
    print(head)
    findError(r.json(), site)
    for mess in range(int(r.json()["disk"]["info"]["rows"])):
        if "root" in r.json()["disk"][str(
                mess)]["Filesystem"] or "/dev" in r.json()["disk"][str(
                    mess)]["Filesystem"]:
            a = paint("Unlimited", 'f_green') if r.json()["disk"][str(
                mess)]["Available"] == "unlimited" else float(
                    r.json()["disk"][str(mess)]["Available"]) / 1048576
            row = "{:25} | {:10.4f} GB   | {:10.4f} GB  | {:18} | {}  \t".format(
                r.json()["disk"][str(mess)]["Filesystem"],
                float(r.json()["disk"][str(mess)]["Used"]) / 1048576, a,
                warn(r.json()["disk"][str(mess)]["Capacity"]),
                r.json()["disk"][str(mess)]["Mounted on"])
            if int(r.json()["disk"][str(mess)]["Capacity"].replace('%',
                                                                   '')) > 80:
                row += "\t Limit Warning"
            print(row)
示例#5
0
def getInfo(temp, hum, wind):
    global warn_temp, warn_humid, warn_wind
    global time_warntemp, time_warnhumid, time_warnwind

    if time.time() - time_warntemp > 300:  # 5 minutos
        warn_temp = False
    if time.time() - time_warnhumid > 300:
        warn_humid = False
    if time.time() - time_warnwind > 300:
        warn_humid = False

    if warn_temp is False:

        warn_temp = True
        time_warntemp = time.time()

        if temp > 35:
            print(
                colors.fail(
                    "Temperatura extremamente alta. Por favor, leve roupa fresca, hidrate-se e abrigue-se do sol."
                ))
        elif temp > 27:
            print(
                colors.warn(
                    "Temperatura elevada. Recomanda-se uma t-shirt e colocar protetor solar."
                ))
        elif temp > 22:
            print(
                colors.okblue(
                    "Temperatura algo elevada. Leve roupa mais fresca."))
        elif temp > 16:
            print(
                colors.okgreen(
                    "Temperatura amena! Leve roupa de acordo com a sua sensação da temperatura."
                ))
        elif temp > 2:
            print(
                colors.warning(
                    "Temperatura baixa. Por favor, leve roupa mais quente."))
        else:
            print(
                colors.fail(
                    "Temperatura extremamente baixa. Use gorro e bastantes peças de roupa."
                ))
    if warn_humid is False:
        if hum >= 80:
            warn_humid = True
            time_warnhumid = time.time()

            print(
                colors.warning(
                    "Probabilidade elevada de aguaceiros (humidade). Não se esqueça do guarda-chuva."
                ))

    if warn_wind is False:

        warn_wind = True
        time_warnwind = time.time()

        if wind >= 70:
            print(
                colors.fail(
                    "Vento muito forte. Considere abrigar-se das rajadas. Se sair, leve casasco."
                ))
        elif wind >= 25:
            print(
                colors.warning(
                    "Vento forte. Considere vestir um casaco antes de sair de casa."
                ))
        elif wind >= 10:
            print(
                "Brisa aveirense. Leve uma camisola ou um casaco, apenas se não estiver calor."
            )
        else:
            print(colors.okgreen("Vento dentro do normal!"))
示例#6
0
    while True:
        print info('Fetching job...')

        # 1. connect to job's source, lock it up to prevent other workers to take it
        next_job = job_discover.take_next_job()  # block here
        print info('Got job.')

        # 2. get the dumped_partition, unload it
        partition = job_discover.get_partition_from_job(next_job)
        if partition is None:
            continue
        logger.debug('got partition')

        # 3. check partition in partition_server
        if partition_server.exists(partition.uuid):
            print warn('Finished job. Skip')
            continue

        # 3. setup all partitions result, if they exists in partition_discover
        def set_partition_result(target_partition):
            partition_result = partition_discover.get_partition(target_partition.uuid)
            if partition_result is not None:
                target_partition.get = lambda: partition_result
                target_partition.evaluated = True
            for parent in target_partition.parent_list:
                set_partition_result(parent)
        set_partition_result(partition)
        logger.debug('set partitions results')

        # 3. run the target_partition
        try: