Beispiel #1
0
    def GetPower(self, unit, outlet):
        """
         @brief: This function returns the state of the specified outlet.

         @param outlet: The ID-number of the outlet for which the state will be returned.
      """

        if unit == "nasmyth": dest_host = pdu_config.DestHost_nasmyth
        elif unit == "container": dest_host = pdu_config.DestHost_container
        elif unit == "side_ports": dest_host = pdu_config.DestHost_side_ports
        elif unit == "nasmyth_2": dest_host = pdu_config.DestHost_nasmyth_2
        else: print "Error, wrong unit provided!"

        clock = song_timeclass.TimeClass()

        OID = ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.%i" % int(outlet)

        powerstatus = ""
        try:
            powerstatus = netsnmp.snmpget(OID,
                                          Version=1,
                                          DestHost=dest_host,
                                          Community=pdu_config.Community)
        except Exception, e:
            sys.exit("ERROR, connection to PDU could not be made!")
Beispiel #2
0
    def GetInfo(self, unit):
        """
         @brief: This function will return some info about the APC-PDU device. 

         @todo: This function could be filled with possibilities. 
      """

        if unit == "nasmyth":
            dest_host = pdu_config.DestHost_nasmyth
            pdu_names = pdu_config.names_nasmyth
        elif unit == "container":
            dest_host = pdu_config.DestHost_container
            pdu_names = pdu_config.names_container
        elif unit == "side_ports":
            dest_host = pdu_config.DestHost_side_ports
            pdu_names = pdu_config.names_side_ports
        elif unit == "nasmyth_2":
            dest_host = pdu_config.DestHost_nasmyth_2
            pdu_names = pdu_config.names_nasmyth_2
        else:
            print "Error, wrong unit provided!"

        clock = song_timeclass.TimeClass()
        OID = ".1.3.6.1.4.1.318.1.1.4.5.1.0"  # Returns the total number of outlets (24 with this PDU)

        powerstatus = ""
        try:
            powerstatus = netsnmp.snmpget(OID,
                                          Version=1,
                                          DestHost=dest_host,
                                          Community=pdu_config.Community)
        except Exception, e:
            sys.exit("ERROR, connection to PDU could not be made!")
    def wind_check_test(self):
        imp.reload(song_checker_config)
        return_value = []

        wind_speed = numpy.random.random() * 15
        wind_dir = numpy.random.random() * 360

        print ""
        print song_timeclass.TimeClass().whattime()
        print "Wind speed: %.1f" % wind_speed
        print "Wind direction: %.1f" % wind_dir

        if wind_speed > song_checker_config.max_windde_ports:
            if numpy.abs(
                    wind_dir - 358.0
            ) <= song_checker_config.side_ports_angle or wind_dir <= song_checker_config.side_ports_angle - 2.0:
                return_value.append(3)  # If wind direction is from "North".
            if numpy.abs(wind_dir -
                         101.0) <= song_checker_config.side_ports_angle:
                return_value.append(4)  # If wind direction is from "East".
            if numpy.abs(wind_dir -
                         177.0) <= song_checker_config.side_ports_angle - 30.0:
                return_value.append(1)  # If wind direction is from "South".
            if numpy.abs(wind_dir -
                         254.0) <= song_checker_config.side_ports_angle:
                return_value.append(2)  # If wind direction is from "West".

        return return_value
Beispiel #4
0
    def SetPower(self, unit, outlet, state):
        """
         @brief: This function changes the state of the specified outlet. 

         @param outlet: The ID-number of the outlet which will be switched on/off.
         @param state: The state to which to outlet will be switched.
      """

        if unit == "nasmyth": dest_host = pdu_config.DestHost_nasmyth
        elif unit == "container": dest_host = pdu_config.DestHost_container
        elif unit == "side_ports": dest_host = pdu_config.DestHost_side_ports
        elif unit == "nasmyth_2": dest_host = pdu_config.DestHost_nasmyth_2
        else: print "Error, wrong unit provided!"

        clock = song_timeclass.TimeClass()

        OID = ".1.3.6.1.4.1.318.1.1.4.4.2.1.3.%i" % int(
            outlet
        )  # .1.3.6.1.4.1.318 defines that the connection is to a APC device.
        # the .1.1.4.4.2.1.3 is defining that changes is made to the power outlet.
        # %i % int(outlet) is the outlet number which will be chanced.
        var = netsnmp.Varbind(".1.3.6.1.4.1.318.1.1.4.4.2.1.3.%i" %
                              int(outlet))
        res = netsnmp.snmpget(var,
                              Version=1,
                              DestHost=dest_host,
                              Community=pdu_config.Community)

        var.tag = OID
        var.val = int(
            state)  # The value of the outlet is set to the given state.

        setpower = ""
        try:
            setpower = netsnmp.snmpset(
                var,
                Version=1,
                DestHost=dest_host,
                Community=pdu_config.Community
            )  # Here the outlet, number int(outlet), is chanced to int(state
        except Exception, e:
            sys.exit("ERROR, connection to PDU could not be made!")
Beispiel #5
0
import datetime
import master_config as m_conf
import song_timeclass
import song_star_checker
import song_convert_coor
import check_ORs
import ephem
import central_song_checker
import song_checker_config
import numpy
import os
import socket
import gc
import psutil

clock = song_timeclass.TimeClass()
checker_handle = central_song_checker.Checker()


def twi_stop(time_stamp):

    song_site = ephem.Observer()
    song_site.lat = conf.lat_obs
    song_site.long = conf.long_obs
    song_site.elev = conf.elev_obs
    song_site.horizon = "%f:" % float(conf.obs_sun_alt)
    song_site.date = time_stamp

    sun = ephem.Sun()
    sun.compute(song_site)
    return song_site.next_rising(sun)
Beispiel #6
0
	"""
    error = 0
    try:
        #os.rename(current_log_file, old_log_file) 	# This
        tmp_file_1 = file(current_log_file, "r")
        file_info = tmp_file_1.readlines()
        tmp_file_1.close()
        tmp_file_2 = file(old_log_file, "w")
        for line in file_info:
            tmp_file_2.write(str(line))
        tmp_file_2.close()
    except Exception, e:
        print e
        print "Could not rename %s file to %s" % (current_log_file,
                                                  old_log_file)
        error = 1

    if error == 0:
        try:
            tmp_file = file(current_log_file, "w")
            text = "The content of %s was moved to %s at: %s\n\n" % (
                current_log_file, old_log_file,
                song_timeclass.TimeClass().obstimeUT())
            tmp_file.write(text)
            tmp_file.close()
        except Exception, e:
            print "Could not clear %s" % (current_log_file)
            error = 1

    return error