
    d                         d dl Z d dlmZ d dlmc mZ d dlmc mc mZ d dl	mc mc m
Z
 d dlmc mZ d dlmZ d dlmZ  G d de      Zy)    N)sleep)ResourceDiskError)ResourceDiskHandlerc                   *     e Zd Z fdZd Zd Z xZS )OpenWRTResourceDiskHandlerc                 v    t         t        |           | j                  dk(  s| j                  dk(  rd| _        y y )Nufsufs2ffs)superr   __init__fs)self	__class__s    M/usr/lib/python3/dist-packages/azurelinuxagent/daemon/resourcedisk/openwrt.pyr   z#OpenWRTResourceDiskHandler.__init__   s4    ($8:77etww&0DG  1    c                     t        j                  dj                  |      d      \  }}|dk7  rt        j                  d       y y )Nzhdparm -z {0}F)chk_errr   z#Failed refresh the partition table.)	shellutilrun_get_outputformatloggerwarn)r   deviceretoutputs       r   reread_partition_tablez1OpenWRTResourceDiskHandler.reread_partition_table%   s=    ../E/Ef/MW\]V!8KK=> r   c                    | j                   j                  d      }|t        d      t        j                  d|       dj                  |      }|dz   }t        j                  d|       t        j                  d      d   }| j                   j                  ||      }|rt        j                  d||       |S 	 t        j                  |d	
       d}| j                  dk(  rd}dj                  | j                  ||      }	| j                  ddj                  |            }
|
d   j                         }|dk(  r| j                  dk7  rtt        j                  d       | j                  ddj                  |             | j!                  |       t        j                  d|	       t        j"                  |	       nt        j                  d|       t%        j&                         }| j)                  |||      }d}t*        j,                  j/                  |      sQ|dkD  rLt        j                  d||       t1        d       |dz  }t*        j,                  j/                  |      s|dkD  rLt*        j,                  j/                  |      st        dj                  |            t*        j,                  j3                  |      rt        j4                  d|       nt        j                  d        | j!                  |       t        j                  d!|       t        j                  |      \  }
}|
rat        j4                  d"|       t        j"                  |	       t        j                  |      \  }
}|
rt        d#j                  ||
|            t        j                  d$||| j                         |S # t        $ r9}dj                  ||      }t        j                  |       t        ||      d }~ww xY w)%N   zunable to detect disk topologyzResource disk device {0} found.z/dev/{0}1z"Resource disk partition {0} found.mountz,Resource disk [{0}] is already mounted [{1}]i  )modez1Failed to create mount point directory [{0}]: {1})msginnerFxfsfzmkfs.{0} -{2} {1}Tz{0} 1 -n)suppress_message
option_str7ntfszCThe partition is formatted with ntfs, updating partition type to 83Fz{0} 1 83zFormat partition [{0}]zThe partition type is {0}   r   z3Waiting for partition [{0}], {1} attempts remainingzPartition was not created [{0}]zDisk is already mounted on {0}z)Mounting after re-reading partition info.zMount resource disk [{0}]zJFailed to mount resource disk. Attempting to format and retry mount. [{0}]z<Could not mount {0} after syncing partition table: [{1}] {2}z,Resource disk {0} is mounted at {1} with {2})osutildevice_for_ide_portr   r   infor   r   r   get_mount_pointfileutilmkdirOSErrorerrorr   change_partition_typestripr   runconfget_resourcedisk_mountoptionsget_mount_stringospathexistsr   ismountr   )r   mount_pointr   	partition
mount_listexistingoser#   force_optionmkfs_stringr   ptypemount_optionsmount_stringattemptsr   s                   r   mount_resource_diskz.OpenWRTResourceDiskHandler.mount_resource_disk*   sq   003>#$DEE5v> ""6*SL	8)D --g6q9
;;..z6BKKF! " O	8NN;U3 77eL)00)\R (($:K\K\]cKd(eAC<DGGv-KK / 0&&*J[J[\bJc&d''/KK0+>MM+&KK3U;::<,,]-6-8: ''..+1KKM! " !HMH ''..+1 ww~~i(#$E$L$LY$WXX77??;'KK8+F KKCD''/KK3\B#22<@KC J"$ k*'66|DV+ -88>y?B?E9GH H 	BGG	 O  	8))/S)A LL#377		8s   ;N8 8	O:4O55O:)__name__
__module____qualname__r   r   rJ   __classcell__)r   s   @r   r   r      s    ?
]r   r   )r;   timer   azurelinuxagent.common.loggercommonr   %azurelinuxagent.common.utils.fileutilutilsr1   &azurelinuxagent.common.utils.shellutilr   azurelinuxagent.common.confr8    azurelinuxagent.common.exceptionr   +azurelinuxagent.daemon.resourcedisk.defaultr   r    r   r   <module>rY      s:   ( 
  . . 8 8 : : * * > Ki!4 ir   