3 \me# @sUddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZdd lmZd Zd Zd Zd d deegeggdZe eeZejeZee e eddddZdS)N)parse_qs) url_helper)util)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) PER_INSTANCEZcc_rightscale_userdataZCLOUD_INIT_REMOTE_HOOKaIThis module adds support for RightScale configuration hooks to cloud-init. RightScale adds an entry in the format ``CLOUD_INIT_REMOTE_HOOK=http://...`` to ec2 user-data. This module checks for this line in the raw userdata and retrieves any scripts linked by the RightScale user data and places them in the user scripts configuration directory, to be run later by ``cc_scripts_user``. .. note:: the ``CLOUD_INIT_REMOTE_HOOK`` config variable is present in the raw ec2 user data only, not in any cloud-config parts **Raw user data schema**:: CLOUD_INIT_REMOTE_HOOK= zRightScale Userdataz&Support rightscale configuration hooks)idnametitle descriptionZdistrosZ frequencyZexamplesZactivate_by_schema_keys)r cfgcloudargsreturncCst|dd}| st| r,tjd|dS|}y,t|}| sJt|kr\tjd|tdSWn$tk rtjtd|YnXg}g}|j d} |t} xt | D]\} } t j j | d| } y6tj| }|jr|jrtj| |dd|j| Wqtk r8}z"|j|tjtd t| | WYdd}~XqXqW|rTtjd t|t|t| krt| t|}tjd ||rtjd t||ddS)Nget_userdata_rawz'Failed to get raw userdata in module %sz:Skipping module %s, did not find %s in parsed raw userdataz1Failed to parse query string %s into a dictionaryscriptszrightscale-%02ii)modez!%s failed to read %s and write %sz)Wrote out rightscale userdata to %s filesz%s urls were skipped or failedz2%s failed with exceptions, re-raising the last one)getattrcallableLOGdebugr MY_HOOKNAME ExceptionrZlogexcZ get_ipath_cur enumerateospathjoinuhelpZreadurlokcontentsZ write_fileappendMY_NAMElenZwarning)r rrrrZudZmdictZ wrote_fnsZcaptured_excpsZ scripts_dZurlsiZurlZfnameZrespeZskippedr*,/usr/lib/python3.6/cc_rightscale_userdata.pyhandleJsT      $  r,)ZloggingrZ urllib.parserZ cloudinitrr"rZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.distrosr Zcloudinit.settingsr r&rZMODULE_DESCRIPTIONmeta__doc__Z getLogger__name__rstrlistr,r*r*r*r+ s0