
    d#                         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)ResourceDiskError)ResourceDiskHandlerc                   0     e Zd Z fdZd Zd Zd Z xZS )OpenBSDResourceDiskHandlerc                 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/openbsd.pyr   z#OpenBSDResourceDiskHandler.__init__   s4    ($8:77etww&0DG  1    c                      y )N )r   mount_pointsize_mbs      r   create_swap_spacez,OpenBSDResourceDiskHandler.create_swap_space"   s    r   c                    t        j                         }|rst        j                  d       | j                  j                  d      }t        j                  dj                  |      d      \  }}|rt        j                  d|       y y y )NzEnable swap   zswapctl -a /dev/{0}bFchk_errz Failed to enable swap, error {0})
confget_resourcedisk_swap_size_mbloggerinfoosutildevice_for_ide_port	shellutilrun_get_outputformaterror)r   r   r   deviceerroutputs         r   enable_swapz&OpenBSDResourceDiskHandler.enable_swap%   sw    446KK&[[44Q7F#22 4::@&.;@BKC ?H  r   c                     | j                   }|dk7  rt        dj                  |            | j                  j	                  d      }|st        d      t        j                  d|       dj                  |      }t        j                  d      d   }| j                  j                  ||      }|rt        j                  d|       |S t        j                  |d	
       dj                  | j                   ||      }t        j                  |d      }|rOt        j                  dj                  ||             dj                  |      }	t        j                  |	d      \  }}
|rt        dj                  ||
            t        j                         }|rQ|dkD  rd}dj                  |||      }t        j                  |d      \  }}
|rt        dj                  ||
            t        j                  dj                  |            \  }}
|rt        dj                  ||
            t        j                  |d      \  }}
|rt        dj                  ||
            t        j                  d|||       |S )Nr
   z<Unsupported filesystem type: {0}, only ufs/ffs is supported.r   z&Unable to detect resource disk device.zResource disk device {0} found.z	/dev/{0}amountz$Resource disk {0} is already mountedi  )modezmount -t {0} {1} {2}Fr   zCreating {0} filesystem on {1}z/sbin/fdisk -yi {0}z+Failed to create new MBR on {0}, error: {1}i   zJecho -e '{0} 1G-* 50%
swap 1-{1}M 50%' | disklabel -w -A -T /dev/stdin {2}z0Failed to create new disklabel on {0}, error {1}znewfs -O2 {0}az;Failed to create new filesystem on partition {0}, error {1}z(Failed to mount partition {0}, error {1}z=Resource disk partition {0} is mounted at {1} with fstype {2})r   r   r#   r   r    r   r   r!   r"   get_mount_pointfileutilmkdirrunr   r   )r   r   r   r%   	partition
mount_listexisting	mount_cmdr&   	fdisk_cmdr'   r   disklabel_cmdrets                 r   mount_resource_diskz.OpenBSDResourceDiskHandler.mount_resource_disk0   sr   WW;# %<<BF2JH H 003#$LMM5v>  &&v.	 --g6q9
;;..z9EKK>	JO{/*11$''2;[J	mmIu5KK8??FKL-44V<I#229eLKC' )55;VFF5KM M 88:GZ'(G"'(.{GV(L  (66!52V+ -228&2HJ J $22 466<fVnFKC' )..4fY.GI I $229eLKC' )44:F9f4MO O 	 $k2	7r   )__name__
__module____qualname__r   r   r(   r7   __classcell__)r   s   @r   r   r      s    	IAr   r   )azurelinuxagent.common.loggercommonr   %azurelinuxagent.common.utils.fileutilutilsr-   &azurelinuxagent.common.utils.shellutilr!   azurelinuxagent.common.confr    azurelinuxagent.common.exceptionr   +azurelinuxagent.daemon.resourcedisk.defaultr   r   r   r   r   <module>rD      s4   ( / . 8 8 : : * * > KV!4 Vr   