ó 'KXc@sddlZddlmZddlmZddlmZddlZddlZddlZej e ƒZ i de fd6de fd6d e fd 6d e fd 6d e fd 6d e fd 6de fd6de fd6de fd6de fd6ZdZdegZidd6dd6ddd d d dgd6gd6e d6idd6d 6Ziiid!d"6e d#6e d$6d6d%6idd&6d'd(6dd)6gd*6Zd+Zd,Zd-ejfd.„ƒYZd/„Ze ddd0„Zd1„Zde d2d3„ZeejejffgZd4„ZdS(5iÿÿÿÿN(tlog(tsources(tutilthostnameslocal-hostnametroot_authorized_keyss public-keyss user-scripts user-dataslegacy-user-datascloud-init:user-datatiptables_disablet motd_sys_infossdc:datacenter_nametavailability_zonessdc:vendor-datas vendor-datassdc:operator-scriptsoperator-scripttSmartOSt datasources /dev/ttyS1t serial_devicei<t seed_timeouttno_base64_decodet base64_keyst base64_alls/dev/vdbt ephemeral0t disk_aliasestmbrt table_typetlayoutt overwritet disk_setuptlabeltext3t filesystemtdevicetfs_setupsU#cloud-boothook #!/bin/sh fname="%(per_boot_d)s/01_smartos_vendor_data.sh" mkdir -p "${fname%%/*}" cat > "$fname" <<"END_SCRIPT" #!/bin/sh ## # This file is written as part of the default vendor data for SmartOS. # The SmartOS datasource writes the listed file from the listed metadata key # sdc:operator-script -> %(operator_script)s # user-script -> %(user_script)s # # You can view content with 'mdata-get ' # for script in "%(operator_script)s" "%(user_script)s"; do [ -x "$script" ] || continue echo "executing '$script'" 1>&2 "$script" done END_SCRIPT chmod +x "$fname" s/var/dbtDataSourceSmartOScBsPeZd„Zd„Zd„Zd„Zd„Zd„Zeddd„Z RS(cCsïtjj||||ƒd|_tj|jtj|t iƒt gƒ|_i|_ t |_ |jjdƒ|_|jjdƒ|_|jjdƒ|_|jjdƒ|_|jjdƒ|_tjj|jjdƒƒ|_dS(NR tserial_timeoutR R Rtscripts(Rt DataSourcet__init__tNonet is_smartdcRt mergemanydicttds_cfgtget_cfg_by_patht DS_CFG_PATHtBUILTIN_DS_CONFIGtmetadatatBUILTIN_CLOUD_CONFIGtcfgtgettseedR tsmartos_no_base64tb64_keystb64_alltostpathtjointpathst get_cpatht script_base_d(tselftsys_cfgtdistroR2((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyR’s   cCs#tjj|ƒ}d||jfS(Ns %s [seed=%s](RRt__str__R+(R5troot((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyR8¥sc Cs>i}d}tjj|jƒs2tjdƒtStjƒd}|jdƒs]|dkrntjdƒtSt ƒ}|tkr”tjdƒtSt |ƒ\}}d|j ƒkrÌtjd |ƒtSt |_ ||d <|jd d t d tƒ}|dk r:gt|ƒjdƒD]}|jƒ^q|_n|jdd t d tƒ} | dk rvtj| ƒ|_nx?tjƒD]1\} } | \} } |j| d | ƒ|| R-Rtis_trueR.tSMARTOS_ATTRIB_MAPt iteritemsR1R2R3t LEGACY_USER_Dtwrite_boot_contentR*tBUILTIN_VENDOR_DATAR"R't userdata_rawtvendordata_raw(R5tmdtudt uname_archtdmi_infot system_uuidt system_typeR-tkR.tci_nount attributet smartos_nounR>tdata_dRGt u_script_lRHtu_datatu_data_f((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pytget_data©sn        4             cCs|jdj|ƒS(NR(R#R*(R5tname((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pytdevice_name_to_devicescCs|jS(N(R)(R5((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pytget_config_objscCs |jdS(Ns instance-id(R'(R5((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pytget_instance_idscCsy|dkrH||jkr$t}qH|js<||jkrHt}qHntd|d|d|jd|jd|d|ƒS(NtnounR>t seed_deviceR tdefaultR?( R R,RMR.R-RSt query_dataR+R (R5RrR>RtR?((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyRT s   N( t__name__t __module__RR8RmRoRpRqRMR RT(((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyR‘s   W   cCsM|stdƒ‚ntj|d|ƒ}|jƒsItd|ƒ‚n|S(s†This is replaced in unit testing, allowing us to replace serial.Serial with a mocked class. The timeout value of 60 seconds should never be hit. The value is taken from SmartOS own provisioning tools. Since we are reading each line individually up until the single ".", the transfer is usually very fast (i.e. microseconds) to get the response. sseed_device value is not setttimeoutsUnable to open %s(tAttributeErrortserialtSerialtisOpent SystemError(RsR tser((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyt get_serials  c Cs|s tSt||ƒ}|jd|jƒƒt|jƒƒjƒ}g}t} d|krn|jƒ|Sx>| s®|jƒ} | jƒdkržt} qq|j| ƒqqW|jƒ|d krt d|d|d|dtdtd tƒ}t j |ƒ}nd } |s|r/d j |ƒjƒ} nd j |ƒ} |r}ytj| ƒSWq}tk rytjd |ƒ| SXn| S( sãMakes a request to via the serial console via "GET " In the response, the first line is the status, while subsequent lines are is the value. A blank line with a "." is used to indicate end of response. If the response is expected to be base64 encoded, then set b64encoded to true. Unfortantely, there is no way to know if something is 100% encoded, so this method relies on being told if the data is base64 or not. sGET %s tSUCCESSt.sb64-%sRsR R?RtR>R:sFailed base64 decoding key '%s'N(RMRtwritetrstripRUtreadlinetcloseRStappendR RuRRWR1tbase64t b64decodet TypeErrorRKtwarn( RrRsR R>RtR?R~tstatustresponset eom_foundtmtresp((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyRu(s@          cCsýd\}}tjdƒ}|s%tS|ddg}y&tjdƒtj|ƒ\}}Wn&tk r‚}tjtd|ƒnX|ddg}y&tjdƒtj|ƒ\}}Wn&tk rà}tjtd|ƒnX|j ƒj ƒ|j ƒfS( Nt dmidecodes-ss system-uuidsGetting hostname from dmidecodesFailed to get system UUIDssystem-product-names1Determining hypervisor product name via dmidecode(NN( R RtwhichRMRKRLtsubpt ExceptiontlogexcRRR>(tsys_uuidtsys_typetdmidecode_patht sys_uuid_cmdt_errtet sys_type_cmd((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyRPbs"   ic Csè| r)tjj|ƒr)tj|ƒn|rQtjj|ƒrQtj|ƒn|s[dStj||d|ƒ|rH|jdƒ rHyŽddd|g}tj|ƒ\}}t j d||ƒ|j ƒdkrd j d |gƒ}tj||d|ƒt j d |ƒnWqHt k rD} tjt d || fƒqHXn|räyjtjj|ƒrstj|ƒn|r·tjj|ƒr·tjtjj|ƒƒtj||ƒnWqätk rà} tjt d | ƒqäXndS(s  Write the content to content_f. Under the following rules: 1. If no content, remove the file 2. Write the content 3. If executable and no file magic, add it 4. If there is a link, create it @param content: what to write @param content_f: the file name @param backup_d: the directory to save the backup at @param link: if defined, location to create a symlink to @param shebang: if no file magic, set shebang @param mode: file mode Becuase of the way that Cloud-init executes scripts (no shell), a script will fail to execute if does not have a magic bit (shebang) set for the file. If shebang=True, then the script will be checked for a magic bit and to the SmartOS default of assuming that bash. NRFs#!tfiles--briefs --mime-typesscript %s mime type is %ss text/plains s #!/bin/bashsadded shebang to file %ss%Failed to identify script type for %ss failed establishing content link(R/R0RJtunlinktislinkRt write_fileROR’RKRLR>R1R“R”t ensure_dirtdirnametsymlinktIOError( tcontentRCRDRERFtcmdtf_typeR™t new_contentRš((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyR[ys8 cCstj|tƒS(N(Rtlist_from_dependst datasources(tdepends((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pytget_datasource_list¸s( R‡t cloudinitRtloggingRRR/tos.pathRzt getLoggerRvRKRSRMRXtDS_NAMER%R&R(R\RZRRRR RuRPR[tDEP_FILESYSTEMt DEP_NETWORKR©R«(((sP/opt/freeware/lib/python2.7/site-packages/cloudinit/sources/DataSourceSmartOS.pyt sf                 („  9  9