Your IP : 216.73.216.101


Current Path : /opt/sharedrads/__pycache__/
Upload File :
Current File : //opt/sharedrads/__pycache__/move_generator.cpython-313.pyc

�

iXMj-)���SrSSKJr SSKJr SSKrSSKrSSKrSSKJ	r	 SSK
JrJr SSK
r
SSKrSSKJr SSKr\	"S5rS	rS
rSrSrS
\4SjrS\\4SjrS\\\4S
S4SjrS$SjrS\S\S\S\S\\S
\\\ S-44Sjr!S\S\S\S\S\\S
\\\\\ 44Sjr"Sr#S\\\\\ 44Sjr$S\S \S!\ 4S"jr%\&S#:Xa\"5 gg)%zWDisk Move Generator - generates disk move tickets
according to arguments and exclusions�)�
itemgetter)�nodeN)�Path)�ThreadPoolExecutor�as_completed)�tabulatez/var/log/disk_exclude�c
�n�[R"[S9nUR5nUR	SS[
SS/SS9 UR	SS	[S
SS9 UR	S
S[SS9 UR	SS[SS9 UR	SS[
SS/SS9 UR	SSSSS9 UR	SSSSS9 UR	S S!SS"S9 UR5nURS#LaBURS#La3UR(d"[S$S%5 [R"S&5 U$)'zParse arguments)�descriptionz-az--add�add_user�+z3Add user to exclusion list. Entries survive 30 days)�type�dest�nargs�default�helpz-mz--min�z3Minimum size of account to migrate in GB, default 8)rrrz-xz--maxz(Maximum size of account to migrate in GB)rrz-tz--totalz<Lists several eligible accounts whose size totals up to X GBz-ez	--exclude�exc_userz1List of users to exclude alongside exclusion listz-nz--noexclude�
store_truezDo not use exclusion list)�actionrz-lz
--listaccountzPrint list of eligible accountsz-dz--ticketz/Email eligible accounts to the disk moves queueFz"--ticket (-d), --listaccount (-l),z or --add (-a) [user] is required�)�argparse�ArgumentParser�__doc__�add_mutually_exclusive_group�add_argument�str�int�
parse_args�ticket�listaccountr�print�sys�exit)�parser�group�argss   �!/opt/sharedrads/move_generator.py�get_argsr)s���
�
$�
$��
9�F��/�/�1�E�
�����
�
���
B��������
��
B�������g�C�&P��������
�
K�	��
�����
�
���
@���
������
(�	��������
.�	��������
>�	������D��{�{�e��� 0� 0�E� 9�$�-�-�
�0�.�	
�	������K�c��[SSS9n[R"U[R5nSSS5 Wc0$U$!,(df   N=f)zParse /etc/trueuserownersz/etc/trueuserownerszutf-8��encodingN)�open�yaml�load�rads�DumbYamlLoader)�handle�user_ownerss  r(�get_user_ownersr5XsD��	
�#�g�	6�&��i�i���(;�(;�<��
7����	���	
7�	6�s�&A�
Ac��[5n/n[5 UR(a�UR(dUR(a[S5 URHIn[R"U5(aM [US35 URRU5 MK [UR5 UR(dUR(aA[URURURURUR5nUR(a[!U5 UR(a[#U5 U$)Nz!Adding to exclusion list first...z is not a valid cpanel user)r)�refresh_exclusion_listrr!r r"r1�	is_cpuser�remove�add_excluded_users�collect_accounts�min�max�total�	noexcluder�
list_accounts�email_accounts)r'�accounts�users   r(�mainrDas����:�D��H����}�}����t�{�{��5�6��M�M�D��>�>�$�'�'����9�:�;��
�
�$�$�T�*�"�	�4�=�=�)����4�;�;�$��H�H�d�h�h��
�
�D�N�N�D�M�M�
������h���{�{��x� ��Kr*�returnc��0n[[SS9n[R"U[RS9nSSS5 [U[5(d[S5 0n[U5 U$!,(df   N==f![R[4aDn[[U5RUSS9 [S[5 [U5 SnAU$SnAff=f)	z4Read from the exclusion list and return it as a dict�asciir,)�LoaderNz#Error in exclusion list, rebuilding�: )�sep�
Recreating)
r.�EXCLUSION_LISTr/r0�
SafeLoader�
isinstance�dictr"�write_exclusion_list�	YAMLError�OSErrorr�__name__)�data�
exclusionlist�excs   r(�get_exclusion_listrW�s���
�D�
#�
�.�7�
3�}����=����I�D�4��$��%�%��7�8��D� ��&�
�K�4�
3��
�N�N�G�$�#�
�d�3�i� � �#�4�0�
�l�N�+��T�"�"��K��	#�s-�A>�$A-�5A>�-
A;�7A>�>C�9C�C�usersc��UHGn[5n[R"5RX!'[	U5 [US35 MI g)z<Format user information and timestamp for the exclusion listz added to exclusion listN)rW�arrow�now�
int_timestamprPr")rXrC�exclusion_lists   r(r:r:�s@����+�-��$�y�y�{�8�8����^�,�
���.�/�0�	r*r]c��[[SSS9n[R"XSS9 SSS5 g!,(df   g=f![a gf=f)zWrite to the exclusion list�wrGr,�)�indentN)r.rLr/�dump�	Exception)r]�outfiles  r(rPrP�s@��
�
�.�#��
8�G��I�I�n�a�8�9�
8�
8���
��
�s(�A�0�A�
>�A�A�
A�
Ac� �[5n0nUH`n[R"5RX-
[	[
R"[S9R55:dMZXX'Mb [U5 g![a gf=f)z)If a timeout has expired, remove the user)�daysN)rWrZr[r\r�datetime�	timedelta�TIMER�
total_secondsrPrc)�timeouts�new_dictrCs   r(r7r7�s~��
�%�'�����D��y�y�{�(�(�8�>�9�C��"�"��.�<�<�>�=��"*����	�
	�X�&���
��
�s�A$B�*B�
B
�B
rC�min_size�max_sizer?c�P�[R"U5(aUS4$[SU5R5(agU(d	X;aUS4$[R"5RU5S-nXQ:aUS4$U(a	XR:�aUS4$X4$![a US4s$f=f)zHRun the user through the first gamut to determine if
eligible for a moveNz/var/cpanel/suspendedi@)r1�cpuser_safer�is_file�QuotaCtl�getquota�KeyboardInterrupt)rCrmrnr?r]�size_gbs      r(�initial_disqualifyrv�s�������D�!�!���:���'��.�6�6�8�8���T�3���:������1�1�$�7�%�?������:����*���:���}������T�z���s.�B�B�B�/B�B�B�B%�$B%�total_gb�excludec	��Sn/n/n/n[[5R55n	X�-
n	UUUU	S.n/n[5n[SS9n
/nUR5H-unnURU
R"[U40UD65 M/ [U5H3nUR5unnUcMX�nURUUU45 M5 SSS5 U(dU$UR#[%S5S
S
9 U(a<SnUH2n['U5S:dXR:aURU5 UUS-
nM2 O UnUSSnU$![a1n
[	S[U
5RSU
35 /n	Sn
A
GNRSn
A
ff=f![a) [	S5 U
R!S	S
S9 /ssSSS5 $f=f!,(df   N�=f)zxGet a list of users, and then eliminate them based on suspension
status, size, and eligibility based on options providedrzSkipping exception file - rIN)rmrnr?r]r`)�max_workerszCaught KeyboardInterrupt.FT)�wait�cancel_futures�)�key�reverse��)�listrW�keysrcr"rrSr5r�items�append�submitrvr�resultrt�shutdown�sortr�len)rmrnrwr?rx�
size_totalrB�eligible_accounts�
final_listr]rV�kwargsr4�pool�jobsrC�owner�futureru�accounts                    r(r;r;�s����J��H����J���0�2�7�7�9�:����N����(�	�F��H�!�#�K�	��	*�d�	��D�*�0�0�2���e����D�K�K�(:�D�K�F�K�L� 3�&�t�,�� &�
�
��
��g��&�'�-�E��O�O�T�5�'�$:�;�	-�
+�����M�M�j��m�T�M�2���
��G��$�%��)�Z�-B�!�(�(��1��g�a�j�(�
�� �%���#�2��J����W��
�*�4��9�+=�+=�*>�b���F�G������0!�	��-�.��M�M�u�T�M�:��I�
+�	*�	��
+�	*�sH�!E�F;�
A%F�6F�
F�&E=�=F�'F8�,F;�7F8�8F;�;
G	c��U(d[S5 g[[[U5/SQSS95 [SU55=n(a[SUSS	35 gg)
z5Print the list of eligible accounts in a pretty tablezNo accounts match criteria.N)�User�Ownerz	Size (GB)z.1f)�headers�floatfmtc3�*# �UH	oSv� M g7f)r}N�)�.0�xs  r(�	<genexpr>� list_accounts.<locals>.<genexpr>$s���+�(�Q�a�D�(�s�z!Total size of matching accounts: z.2fz GB)r"r�reversed�sum)rBr>s  r(r@r@s`���
�+�,��	���X��2��	
���+�(�+�+�+�u�+�
�1�%���C�@�A�,r*rBc��[5RS5Sn/nUH#up4n[X1U5 URU5 M% [	U5 g)z'Send an email for each user in accounts�.rN)r�split�mail_disk_mover�r:)rB�serverrxrC�_rus      r(rArA(sK��
�V�\�\�#�
�q�
!�F��G�$�����t�W�-����t��%��w�r*�usernamer�ruc��SnSUSU3nSUSUSUSUSUS3n[R"X4US	9 [S
US35 g![Ra.n[U[R
S9 [S
S5 SnAgSnAff=f)z#Sends email to the disk moves queuezsadmin@imhadmin.netzDISK MOVE: z @ z,
    A new server disk move is required for z

    Move Username: z
    Account Size: a� GiB

    Please review the account to determine if they are eligible for a migration:
     * hasn't been moved recently (e.g. in the past year/no current move scheduled)
     * is not storing ToS content
     * is not large to the point of absurdity
     * other reasons left to the discretion of the administrator

    If the account is not eligible for a migration, please add them to the
    exception list to prevent further tickets being generated for their account:
    move_generator.py -a a4

    If the account is not eligible for reasons of ToS content, please respond
    to this ticket with the relevant information and leave it open to address
    further. For convenience, you may also update the subject line with the
    date on which this should be addressed again and/or notice count.
    )r�subject�bodyzDisk move ticket sent for r�)�filez@Sending of disk_move ticket failed. You can use the -l option tozview eligible accounts to moveN)r1�make_ticketr"�TicketErrorr#�stderr)r�r�ru�to_addrr�r�rVs       r(r�r�2s���#�G��H�:�S���1�G�,�,4�:�S���A��:���)�
�#��$��D�*	8����g�T�B�	�*�8�*�A�6�7�����
�
�c��
�
�#�
�N�,�	
�	
��
�s�A�B�$B�B�__main__)rEN)'r�operatorr�platformrrgrr#�pathlibr�concurrent.futuresrrrZr/rr1rLrir)r5rDrOrWr�rr:rrPr7�bool�tuple�floatrvr;r@rAr�rSr�r*r(�<module>r�s~��)�����
��?������-�.��
��A�H��B�D��"1�d�3�i�1�
��c�3�h��
�D�
�

� �

�����	�
����I�
��3�������D>��>��>��>��	>�
�#�Y�>�
�%��S�%��
 �!�
>�B
B�  �T�%��S�%��"8�9� �"8�S�"8�#�"8��"8�J�z���F�r*