本文整理汇总了Python中telnetlib.Telnet.send方法的典型用法代码示例。如果您正苦于以下问题:Python Telnet.send方法的具体用法?Python Telnet.send怎么用?Python Telnet.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telnetlib.Telnet
的用法示例。
在下文中一共展示了Telnet.send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CMonitor
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import send [as 别名]
class CMonitor(CElement):
def __init__(self, monitor_info):
super(CMonitor, self).__init__()
self.__monitor = monitor_info
self.__chardev = None
self.__mode = "readline"
self.__workspace = ""
self.__monitor_handle = None
def get_workspace(self):
return self.__workspace
def set_workspace(self, ws):
self.__workspace = ws
def precheck(self):
if self.__mode not in ["readline", "control"]:
raise ArgsNotCorrect("[Monitor] Invalid monitor mode: {}".format(self.__mode))
self.__chardev.precheck()
# Monitor specific chardev attribution
if self.__monitor["chardev"]["backend"] != "socket":
raise ArgsNotCorrect("[Monitor] Invalid monitor chardev backend: {}".
format(self.__monitor["chardev"]["backend"]))
if self.__monitor["chardev"]["server"] is not True:
raise ArgsNotCorrect("[Monitor] Invalid monitor chardev server: {}".
format(self.__monitor["chardev"]["server"]))
if self.__monitor["chardev"]["wait"] is not False:
raise ArgsNotCorrect("[Monitor] Invalid monitor chardev wait: {}".
format(self.__monitor["chardev"]["wait"]))
def init(self):
self.__mode = self.__monitor.get("mode", "readline")
chardev_info = {}
if self.__mode == "readline":
chardev_info = self.__monitor.get("chardev", {})
if "backend" not in chardev_info:
chardev_info["backend"] = "socket"
if "server" not in chardev_info:
chardev_info["server"] = True
if "wait" not in chardev_info:
chardev_info["wait"] = False
if "host" not in chardev_info:
chardev_info["host"] = "127.0.0.1"
if "port" not in chardev_info:
chardev_info["port"] = 2345
elif self.__mode == "control":
chardev_info = self.__monitor.get("chardev", {})
if "backend" not in chardev_info:
chardev_info["backend"] = "socket"
if "server" not in chardev_info:
chardev_info["server"] = True
if "wait" not in chardev_info:
chardev_info["wait"] = False
if "path" not in chardev_info:
if self.get_workspace():
chardev_path = os.path.join(self.get_workspace(), ".monitor")
else:
chardev_path = os.path.join(config.infrasim_etc, ".monitor")
chardev_info["path"] = chardev_path
else:
pass
self.__monitor["chardev"] = chardev_info
self.__chardev = CCharDev(chardev_info)
self.__chardev.logger = self.logger
self.__chardev.set_id("monitorchardev")
self.__chardev.init()
def handle_parms(self):
self.__chardev.handle_parms()
self.add_option(self.__chardev.get_option())
self.add_option("-mon chardev={},mode={}".format(self.__chardev.get_id(), self.__mode))
def get_mode(self):
return self.__mode
def open(self):
if self.__mode == "readline":
self.__monitor_handle = Telnet(self.__chardev.host, self.__chardev.port)
elif self.__mode == "control":
self.__monitor_handle = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.__monitor_handle.connect(self.__chardev.get_path())
# enable qmp capabilities
qmp_payload = {
"execute": "qmp_capabilities"
}
self.send(qmp_payload)
else:
raise ArgsNotCorrect("[Monitor] Monitor mode {} is unknown.".format(self.__mode))
self.logger.info("[Monitor] monitor opened({}).".format(self.__monitor_handle))
def send(self, command):
if self.__monitor_handle:
self.logger.info("[Monitor] send command {}".format(command))
if self.__mode == "readline":
self.__monitor_handle.write(command)
#.........这里部分代码省略.........