o x[h @sPdZddlZddlZdZdZdZedkrdZGdd d ZGd d d ZdS) a cepko implements easy-to-use communication with CloudSigma's VMs through a virtual serial port without bothering with formatting the messages properly nor parsing the output with the specific and sometimes confusing shell tools for that purpose. Having the server definition accessible by the VM can ve useful in various ways. For example it is possible to easily determine from within the VM, which network interfaces are connected to public and which to private network. Another use is to pass some data to initial VM setup scripts, like setting the hostname to the VM name or passing SSH public keys through server meta. For more information take a look at the Server Context section of CloudSigma API Docs: http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html N< z /dev/ttyS1WindowsCOM2c@s0eZdZdZdZd ddZddZd d d ZdS) Cepkozb One instance of that object could be use for one or more queries to the serial port. z< {} >NcCs|dur|j}t||SN)request_pattern CepkoResultformatselfkeyr rF/usr/lib/python3/dist-packages/cloudinit/sources/helpers/cloudsigma.pyget*sz Cepko.getcCs|Sr)rr rrrall/sz Cepko.allcCs|jd}|||S)Nz/meta/{})r r rr rrrmeta2s  z Cepko.meta)rN)r)__name__ __module__ __qualname____doc__r rrrrrrrr"s  rc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)r z CepkoResult executes the request to the virtual serial port as soon as the instance is initialized and stores the result in both raw and marshalled format. cCs"||_||_||j|_dSr)request_execute raw_result_marshalresult)r rrrr__init__>s zCepkoResult.__init__c Csfzddl}Wnty}ztd|d}~ww|jtttd}||j d| d dS)Nrzserial support is not available)porttimeout writeTimeoutasciis ) serial ImportErrorNotImplementedErrorSerial SERIAL_PORT READ_TIMEOUT WRITE_TIMEOUTwriterencodereadlinestripdecode)r r#e connectionrrrrCs  zCepkoResult._executecCs$zt|WSty|YSwr)jsonloads ValueError)r rrrrrOs   zCepkoResult._marshalcC |jSr)r__len__rrrrr5U zCepkoResult.__len__cC |j|Sr)r __getitem__)r rrrrr8X zCepkoResult.__getitem__cCr7r)r __contains__)r itemrrrr:[r9zCepkoResult.__contains__cCr4r)r__iter__rrrrr<^r6zCepkoResult.__iter__N) rrrrrrrr5r8r:r<rrrrr 7s  r ) rr1platformr(r)r'systemrr rrrrs