def __init__(self, pathname=None, cmddict=None, id=None, version=0, **kwargs): """Creates a new AIT Command Sequence Creates an empty sequence which will be encoded and decoded based on the given command dictionary (default: cmd.DefaultCmdDict). If the optional pathname is given, the command sequence (text or binary) will be read from it. """ self.pathname = pathname self.cmddict = cmddict or cmd.getDefaultCmdDict() self.crc32 = None self.seqid = id self.lines = [] self.header = {} self.version = version self.log = SeqMsgLog() self.magic = kwargs.get("magic", 0x0C03) self.cmd_size = kwargs.get("cmd_size", 106) if self.pathname is not None: self.read()
def __init__(self, destination, cmddict=None, verbose=False): if type(destination) is int: destination = ('127.0.0.1', destination) if cmddict is None: cmddict = cmd.getDefaultCmdDict() self._host = destination[0] self._port = destination[1] self._cmddict = cmddict self._verbose = verbose self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) _def_cmd_hist = os.path.join(ait.config._ROOT_DIR, 'ait-cmdhist.pcap') self.CMD_HIST_FILE = ait.config.get('command.history.filename', _def_cmd_hist) if not os.path.isfile(self.CMD_HIST_FILE): if not os.path.isdir(os.path.dirname(self.CMD_HIST_FILE)): self.CMD_HIST_FILE = _def_cmd_hist msg = ('command.history.filename directory does not exist. ' 'Reverting to default {}').format(_def_cmd_hist) ait.core.log.warn(msg)
def cmddict(self, value): if value is None: value = cmd.getDefaultCmdDict() self._cmddict = value
def __init__(self, udp_dest=None, cmddict=None, verbose=False, cmdtopic=None): if cmddict is None: cmddict = cmd.getDefaultCmdDict() self._cmddict = cmddict self._verbose = verbose # Set up the destination of our commands and arguments based on destination # information. if udp_dest: # Convert partial info to full tuple if type(udp_dest) is int: udp_dest = (ait.DEFAULT_CMD_HOST, udp_dest) elif type(udp_dest) is str: udp_dest = (udp_dest, ait.DEFAULT_CMD_PORT) # Sanify check that we have a tuple if type(udp_dest) is not tuple: errmsg = "Illegal type of 'udp_dest' argument: " + type(udp_dest) errmsg += ". Legal types: {int,str,tuple}" raise TypeError(errmsg) # Our UDP socket self._udp_socket = None # Our ZMQ publisher socket self._pub_socket = None if udp_dest: self._host = udp_dest[0] self._port = udp_dest[1] self._udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) else: self._cntxt = zmq.Context() self._pub_url = ait.config.get("server.xsub", ait.SERVER_DEFAULT_XSUB_URL) self._pub_url = self._pub_url.replace("*", "localhost") self._pub_socket = self._cntxt.socket(zmq.PUB) self._pub_socket.connect(self._pub_url) # Allow for the ZMQ connection to complete by sleeping self._pub_conn_sleep = int( ait.config.get("command.zmq_conn_sleep", ait.DEFAULT_CMD_ZMQ_SLEEP) ) sleep_msg = ( "Sleeping {} seconds to allow ZeroQM connection to complete " ).format(str(self._pub_conn_sleep)) ait.core.log.debug(sleep_msg) time.sleep(self._pub_conn_sleep) # Retrieve the command topic to be used self._pub_topic = ( ait.config.get("command.topic", ait.DEFAULT_CMD_TOPIC) if cmdtopic is None else cmdtopic ) _def_cmd_hist = os.path.join(ait.config._ROOT_DIR, "ait-cmdhist.pcap") self.CMD_HIST_FILE = ait.config.get("command.history.filename", _def_cmd_hist) if not os.path.isfile(self.CMD_HIST_FILE): if not os.path.isdir(os.path.dirname(self.CMD_HIST_FILE)): self.CMD_HIST_FILE = _def_cmd_hist msg = ( "command.history.filename directory does not exist. " "Reverting to default {}" ).format(_def_cmd_hist) ait.core.log.warn(msg)