diff options
author | zsdc <taras@vyos.io> | 2022-03-25 20:58:01 +0200 |
---|---|---|
committer | zsdc <taras@vyos.io> | 2022-03-25 21:42:00 +0200 |
commit | 31448cccedd8f841fb3ac7d0f2e3cdefe08a53ba (patch) | |
tree | 349631a02467dae0158f6f663cc8aa8537974a97 /cloudinit/cs_utils.py | |
parent | 5c4b3943343a85fbe517e5ec1fc670b3a8566b4b (diff) | |
parent | 8537237d80a48c8f0cbf8e66aa4826bbc882b022 (diff) | |
download | vyos-cloud-init-31448cccedd8f841fb3ac7d0f2e3cdefe08a53ba.tar.gz vyos-cloud-init-31448cccedd8f841fb3ac7d0f2e3cdefe08a53ba.zip |
T2117: Cloud-init updated to 22.1
Merged with 22.1 tag from the upstream Cloud-init repository.
Our modules were slightly modified for compatibility with the new
version.
Diffstat (limited to 'cloudinit/cs_utils.py')
-rw-r--r-- | cloudinit/cs_utils.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/cloudinit/cs_utils.py b/cloudinit/cs_utils.py index 8bac9c44..6db7e117 100644 --- a/cloudinit/cs_utils.py +++ b/cloudinit/cs_utils.py @@ -24,14 +24,13 @@ import platform from cloudinit import serial - # these high timeouts are necessary as read may read a lot of data. READ_TIMEOUT = 60 WRITE_TIMEOUT = 10 -SERIAL_PORT = '/dev/ttyS1' -if platform.system() == 'Windows': - SERIAL_PORT = 'COM2' +SERIAL_PORT = "/dev/ttyS1" +if platform.system() == "Windows": + SERIAL_PORT = "COM2" class Cepko(object): @@ -39,6 +38,7 @@ class Cepko(object): One instance of that object could be use for one or more queries to the serial port. """ + request_pattern = "<\n{}\n>" def get(self, key="", request_pattern=None): @@ -64,17 +64,18 @@ class CepkoResult(object): as the instance is initialized and stores the result in both raw and marshalled format. """ + def __init__(self, request): self.request = request self.raw_result = self._execute() self.result = self._marshal(self.raw_result) def _execute(self): - connection = serial.Serial(port=SERIAL_PORT, - timeout=READ_TIMEOUT, - writeTimeout=WRITE_TIMEOUT) - connection.write(self.request.encode('ascii')) - return connection.readline().strip(b'\x04\n').decode('ascii') + connection = serial.Serial( + port=SERIAL_PORT, timeout=READ_TIMEOUT, writeTimeout=WRITE_TIMEOUT + ) + connection.write(self.request.encode("ascii")) + return connection.readline().strip(b"\x04\n").decode("ascii") def _marshal(self, raw_result): try: @@ -94,4 +95,5 @@ class CepkoResult(object): def __iter__(self): return self.result.__iter__() + # vi: ts=4 expandtab |