~kiril-vladimiroff/cloud-init/cloudsigma-lack-of-ssh-key

« back to all changes in this revision

Viewing changes to cloudinit/cs_utils.py

  • Committer: Scott Moser
  • Author(s): Kiril Vladimiroff
  • Date: 2014-05-30 18:50:57 UTC
  • mfrom: (971.2.3 cloudsigma-smbios-data-check)
  • Revision ID: smoser@ubuntu.com-20140530185057-vw4fjfffjoi85iij
CloudSigma: only poll on serial device after dmidecode check.

On systems with a ttyS1 and nothing attached, the read attempts
that the cloud sigma datasource would do would block.

Also, Add timeouts for reading/writting from/to the serial console

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
import serial
37
37
 
 
38
# these high timeouts are necessary as read may read a lot of data.
 
39
READ_TIMEOUT = 60
 
40
WRITE_TIMEOUT = 10
 
41
 
38
42
SERIAL_PORT = '/dev/ttyS1'
39
43
if platform.system() == 'Windows':
40
44
    SERIAL_PORT = 'COM2'
76
80
        self.result = self._marshal(self.raw_result)
77
81
 
78
82
    def _execute(self):
79
 
        connection = serial.Serial(SERIAL_PORT)
 
83
        connection = serial.Serial(port=SERIAL_PORT,
 
84
                                   timeout=READ_TIMEOUT,
 
85
                                   writeTimeout=WRITE_TIMEOUT)
80
86
        connection.write(self.request)
81
87
        return connection.readline().strip('\x04\n')
82
88