3 \meO@sddlZddlZddlZddlZddlmZmZmZddlm Z ddl m Z m Z ddl mZddlmZddlmZdd lmZdd lmZdd lmZejeZd Zd ZdZdZdZ dZ!ddZ"dXddZ#ddZ$ddZ%ddZ&ddZ'ddZ(d d!Z)d"d#Z*d$d%Z+dYd(d)Z,dZd*d+Z-d,d-Z.d.d/Z/d0d1Z0d2d3Z1d[d6d7Z2d8d9Z3d:d;Z4dd?Z6d@dAZ7dBdCZ8dDdEZ9dFdGZ:dHdIZ;dJdKZdPdQZ?dRdSZ@dTdUZAdVdWZBdS)\N)safeyamlsubputil)Config)PostCustomScriptPreCustomScript) ConfigFile)NicConfigurator)PasswordConfigurator)GuestCustErrorEnum)GuestCustEventEnum)GuestCustStateEnumz/var/log/cloud-init.logZqueryNicsSupportedZ connected/var/run/vmware-imcZ deployPkgzenable-custom-scriptscCs|sdSd}d}y4tjd|tjd|gdgd\}}|rB|j}Wn6tk rz}ztjdtj|WYdd}~XnX||fS)NzError sending the RPC commandzSending RPC command: %szvmware-rpctoolr)rcszFailed to send RPC command)loggerdebugrrstrip Exception exception)rpcouterrer$/usr/lib/python3.6/guestcust_util.pysend_rpc(s   rcCs<d}|rtd|}nt}d|||f}t|\}}||fS)Nr@zdeployPkg.update.state %d %d %s)CLOUDINIT_LOG_FILEr)Z custstateZ custerrorZ errormessagemessagerrrrrrset_customization_status>s r!c Cs@|sdSd}tjj|sdSt|d}|j|}WdQRX|S)zReads the NICS from the specified file path and returns the content @param nicsfilepath: Absolute file path to the NICS.txt file. Nir)ospathexistsopenread)Z nicsfilepathZ NICS_SIZEfpnicsrrrget_nics_to_enableKs  r*cCs|stjddSd}d}d}xtd|D]}tjd|ttjtj|\}}|sbt j ||q*|t krxtjddSxLtd|D]>}ttjtj |\}}|r|t krtjd|dSt j |qWq*Wtjd|dS) Nz No Nics foundrrz(Trying to connect interfaces, attempt %dz-NICS connection status query is not supportedzNICS are connected on %d secondz2Can't connect network interfaces after %d attempts)rwarningrangerr!rGUESTCUST_STATE_RUNNINGr ZGUESTCUST_EVENT_ENABLE_NICStimesleepQUERY_NICS_SUPPORTEDZGUESTCUST_EVENT_QUERY_NICSNICS_STATUS_CONNECTEDinfo)r)ZenableNicsWaitRetriesZenableNicsWaitCountZenableNicsWaitSecondsZattemptrZ_errcountrrr enable_nics`s<       r5cCstjdstjd|Sddd||g}ytj|}Wn\tjk r}z>|jdkrhtjddj||ntjd||jtj||Sd }~XnX|}t j d |j }|r|j d j }tjd |||ntjd ||||S)a$Return the value of [section] key from VMTools configuration. @param section: String of section to read from VMTools config @returns: String value from key in [section] or defaultVal if [section] is not present or vmware-toolbox-cmd is not installed. zvmware-toolbox-cmdz9vmware-toolbox-cmd not installed, returning default valueconfiggetEzRvmware-toolbox-cmd returned 69 (unavailable) for cmd: %s. Return default value: %s zFailed running %s[%s]Nz ([^=]+)=(.*)zGet tools config: [%s] %s = %sz sh         *2(B