MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyo
�
d�bc@s*ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	yKddl
jjZddl
jjjZddlmZddlmZWnRek
rddljZddljjZddlmZddlmZnXdefd��YZdS(i����N(tarray_to_bytes(tOSUtilError(t
DefaultOSUtiltBigIpOSUtilcBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zddd�Zdd
d�Zd�Zdd�Zd�Zed�Zd�Zd�Zd�Zd�ZRS(cCstt|�j�dS(N(tsuperRt__init__(tself((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyR/scCs�xctdd�D]R}tjd�tjddt�}|dkrUtjd�Pntjd�qW|dkrvtSt	d	��d
S(sWWait for mcpd to become available

        All configuration happens in mcpd so we need to wait that this is
        available before we go provisioning the system. I call this method
        at the first opportunity I have (during the DVD mounting call).
        This ensures that the rest of the provisioning does not need to wait
        for mcpd to be available unless it absolutely wants to.

        :return bool: Returns True upon success
        :raises OSUtilError: Raises exception if mcpd does not come up within
                             roughly 50 minutes (100 * 30 seconds)
        iidsChecking to see if mcpd is upsU/usr/bin/tmsh -a show sys mcp-state field-fmt 2>/dev/null | grep phase | grep runningtchk_errismcpd is up!is5mcpd hasn't completed initialization! Cannot proceed!N(
trangetloggertinfot	shellutiltruntFalsettimetsleeptTrueR(Rtretriestrc((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyt_wait_until_mcpd_is_initialized2s


cCs5d}tj|�}|dkr1tjd�n|S(Ns/usr/bin/tmsh save sys configis,WARNING: Cannot save sys config on 1st boot.(RRR	terror(RtcmdR((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyt_save_sys_configOs
cCstjddt�S(Ns/usr/bin/bigstart restart sshdR(RRR
(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytrestart_ssh_serviceVscCstjdj|j�dt�S(Ns/sbin/service {0} stopR(RRtformattservice_nameR
(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytstop_agent_serviceYscCstjdj|j�dt�S(Ns/sbin/service {0} startR(RRRRR
(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytstart_agent_service\scCstjdj|j�dt�S(Ns/sbin/chkconfig --add {0}R(RRRRR
(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytregister_agent_service_scCstjdj|j�dt�S(Ns/sbin/chkconfig --del {0}R(RRRRR
(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytunregister_agent_servicebscCs|jddg�S(Ns/sbin/pidoftdhclient(t
_get_dhcp_pid(R((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytget_dhcp_pidescCsdS(s>Set the static hostname of the device

        Normally, tmsh is used to set the hostname for the system. For our
        purposes at this time though, I would hesitate to trust this function.

        Azure(Stack) uses the name that you provide in the Web UI or ARM (for
        example) as the value of the hostname argument to this method. The
        problem is that there is nowhere in the UI that specifies the
        restrictions and checks that tmsh has for the hostname.

        For example, if you set the name "bigip1" in the Web UI, Azure(Stack)
        considers that a perfectly valid name. When WAAgent gets around to
        running though, tmsh will reject that value because it is not a fully
        qualified domain name. The proper value should have been bigip.xxx.yyy

        WAAgent will not fail if this command fails, but the hostname will not
        be what the user set either. Currently we do not set the hostname when
        WAAgent starts up, so I am passing on setting it here too.

        :param hostname: The hostname to set on the device
        N(tNone(Rthostname((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytset_hostnamehscCsdS(s�Sets the DHCP hostname

        See `set_hostname` for an explanation of why I pass here

        :param hostname: The hostname to set on the device
        N(R!(RR"((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytset_dhcp_hostname�scCs�|j|�r#tjd|�dSdddd|dddd	dd
dddd
dg}|j|ddj|��|j�dS(s?Create user account using tmsh

        Our policy is to create two accounts when booting a BIG-IP instance.
        The first account is the one that the user specified when they did
        the instance creation. The second one is the admin account that is,
        or should be, built in to the system.

        :param username: The username that you want to add to the system
        :param expiration: The expiration date to use. We do not use this
                           value.
        :param comment: description of the account.  We do not use this value.
        s%User {0} already exists, skip useradds
/usr/bin/tmshtcreatetauthtuserspartition-accesstaddt{sall-partitionstroletadmint}tshelltbashterr_msgs!Failed to create user account:{0}iN(t
get_userentryR	R
R!t _run_command_raising_OSUtilErrorRR(Rtusernamet
expirationtcommentR((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytuseradd�s

ii
cCs�|jdddd|d|gddj|��|jd�}|dkr[td	��n|jdddddd|gdd
�|j�dS(
sChange a user's password with tmsh

        Since we are creating the user specified account and additionally
        changing the password of the built-in 'admin' account, both must
        be modified in this method.

        Note that the default method also checks for a "system level" of the
        user; based on the value of UID_MIN in /etc/login.defs. In our env,
        all user accounts have the UID 0. So we can't rely on this value.

        :param username: The username whose password to change
        :param password: The unencrypted password to set for the user
        :param crypt_id: If encrypting the password, the crypt_id that was used
        :param salt_len: If encrypting the password, the length of the salt
                         value used to do it.
        s
/usr/bin/tmshtmodifyR&R'tpasswordR/sFailed to set password for {0}R+s'The 'admin' user account was not found!s Failed to set password for adminiN(R1RR0R!RR(RR2R7tcrypt_idtsalt_lent	userentry((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytchpasswd�s
cCs3|jddg�|jdddd|g�dS(swDeletes a user account.

        Note that the default method also checks for a "system level" of the
        user; based on the value of UID_MIN in /etc/login.defs. In our env,
        all user accounts have the UID 0. So we can't rely on this value.

        We also don't use sudo, so we remove that method call as well.

        :param username:
        :return:
        ttouchs
/var/run/utmps
/usr/bin/tmshtdeleteR&R'N(t_run_command_without_raising(RR2((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytdel_account�ss/devcCsqd}xXgtj|�D]}tj||�^qD](}|dk	r5dj|jd��Sq5Wtd��dS(s.Find BIG-IP's CD/DVD device

        This device is almost certainly /dev/cdrom so I added the ? to this pattern.
        Note that this method will return upon the first device found, but in my
        tests with 12.1.1 it will also find /dev/sr0 on occasion. This is NOT the
        correct CD/DVD device though.

        :todo: Consider just always returning "/dev/cdrom" here if that device device
               exists on all platforms that are supported on Azure(Stack)
        :param dev_dir: The root directory from which to look for devices
        s(sr[0-9]|hd[c-z]|cdrom[0-9]?)s/dev/{0}isFailed to get dvd deviceN(tostlistdirtretmatchR!RtgroupR(Rtdev_dirtpattentdevtdvd((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytget_dvd_device�s
5cKs |j�tt|�j|�S(sMount the DVD containing the provisioningiso.iso file

        This is the _first_ hook that WAAgent provides for us, so this is the
        point where we should wait for mcpd to load. I am just overloading
        this method to add the mcpd wait. Then I proceed with the stock code.

        :param max_retry: Maximum number of retries waagent will make when
                          mounting the provisioningiso.iso DVD
        :param chk_err: Whether to check for errors or not in the mounting
                        commands
        (RRRt	mount_dvd(Rtkwargs((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyRJ�s
cCstjd�dS(s_Runs the eject command to eject the provisioning DVD

        BIG-IP does not include an eject command. It is sufficient to just
        umount the DVD disk. But I will log that we do not support this for
        future reference.

        :param chk_err: Whether or not to check for errors raised by the eject
                        command
        s'Eject is not supported on this platformN(R	twarn(RR((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyt	eject_dvd�s
cCscd}d}tj�d}|dkr1d}nd}tjtjtjtj�}tjdd||�}tjd	|||j	�d�}t
j|j�d
|�}tj
d	|�d}	|	||kr�tjd|�nt|�}xCtd|||�D]+}
|j||
�}d|kr3q	q	Pq	W|jd
�tj||
d|
d!�fS(s�Return the interface name, and ip addr of the management interface.

        We need to add a struct_size check here because, curiously, our 64bit
        platform is identified by python in Azure(Stack) as 32 bit and without
        adjusting the struct_size, we can't get the information we need.

        I believe this may be caused by only python i686 being shipped with
        BIG-IP instead of python x86_64??
        tiit64biti(i tBttiLi�s9SIOCGIFCONF returned more than {0} up network interfaces.tloslatin-1ii(tplatformtarchitecturetsockettAF_INETt
SOCK_DGRAMtIPPROTO_UDPtarraytstructtpacktbuffer_infotfcntltioctltfilenotunpackR	RLRRt_format_single_interface_nametdecodet	inet_ntoa(Rtifacetexpectedt
python_arctstruct_sizetsocktbufftparamtrettretsizeti((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pytget_first_ifs2
			
cCs|||d!jdd�dS(NiRQii(tsplit(RRitoffset((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyRb0scCs(dj|||�}tj|dt�S(s{Add specified route using tmsh.

        :param net:
        :param mask:
        :param gateway:
        :return:
        s-/usr/bin/tmsh create net route {0}/{1} gw {2}R(RRRR
(RtnettmasktgatewayR((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyt	route_add3scCsSx:tdd�D])}tjjd�r,Pqtjd�qWtt|�j|�S(s�Return device name attached to ide port 'n'.

        Include a wait in here because BIG-IP may not have yet initialized
        this list of devices.

        :param port_id:
        :return:
        iids/sys/bus/vmbus/devices/i
(	RR@tpathtexistsRRRRtdevice_for_ide_port(Rtport_idR((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyRx?s
	N(t__name__t
__module__RRRRRRRRR R#R$R!R5R;R?RIRJRRMRoRbRuRx(((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyR-s*												#			*		(RZR^R@RTRBRVR[Rtazurelinuxagent.common.futureRtazurelinuxagent.common.loggertcommonR	t&azurelinuxagent.common.utils.shellutiltutilsRt azurelinuxagent.common.exceptionRt%azurelinuxagent.common.osutil.defaultRtImportErrortazurelinuxagent.loggertazurelinuxagent.utils.shellutiltazurelinuxagent.exceptiont%azurelinuxagent.distro.default.osutilR(((sG/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/bigip.pyt<module>s&