ó
½-'Nc           @   s$  d  d l  Z  d  d l m Z d  d l m Z d  d l m Z e ƒ  Z d d d d d	 e d
 „ Z e j	 d ƒ d „  ƒ Z
 e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z e j	 d ƒ d „  ƒ Z d S(   iÿÿÿÿN(   t   UpgradeManager(   t   Persist(   t   PackageStores   data.bpickles   broker.bpickles   monitor.bpickles   hash.dbs   hash.sqlitec      
   C   s‰  t  j j |  | ƒ } t  j j |  | ƒ } t  j j |  | ƒ } t  j j |  | ƒ } t  j j |  | ƒ } t d | ƒ } t  j j | ƒ rš | j | ƒ n | j | ƒ | j ƒ  t d | ƒ } | j d | j	 d ƒ ƒ | j d | j	 d ƒ ƒ | j d | j	 d ƒ ƒ | j ƒ  t d | ƒ }	 xW d d d d d	 d
 d d d d g
 D]1 }
 | j
 |
 ƒ rI|	 j |
 | j	 |
 ƒ ƒ qIqIW|	 j ƒ  t  j j | ƒ r…d d l } | j | d ƒ } t | ƒ } i  } | j ƒ  } xQ | d k	 r)y | | } t | ƒ | | <Wn t k
 rn X| j | ƒ } qÙW| j | ƒ | j | j	 d d ƒ ƒ | j | j	 d d ƒ ƒ | j | j	 d d ƒ ƒ n  d S(   s  
    This function is triggered by the post-inst script when landscape
    is upgraded. It applies all the upgraders to the old monolithic
    persist data file and then splits the file up into multiple
    persist files for each new per-process service.
    t   filenames   message-stores   message-exchanget   registrations   client-uptimes   computer-uptimes   computer-infos   load-averages   memory-infos
   mount-infos   processor-infot   temperatures   hardware-inventoryt   usersiÿÿÿÿNt   rs   package.installeds   package.availables   package.available_upgrades(    (    (    (   t   ost   patht   joinR   t   existst   applyt
   initializet   savet   sett   gett   hast   gdbmt   openR   t   firstkeyt   Nonet   intt
   ValueErrort   nextkeyt   set_hash_idst   add_installedt   add_availablet   add_available_upgrades(   t   data_dirR   t   broker_filenamet   monitor_filenamet   hashdb_filenamet   sqlite_filenamet   managert   persistt   broker_persistt   monitor_persistt   pluginR   t   hashdbt   storet   hash_idst   keyt   hash(    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   migrate_data_file   sR    

		 

i   c         C   s4  |  j  d ƒ } i  } i  } | j  d ƒ ra x4 | j  d ƒ j ƒ  D] \ } } | | | d <q@ Wn  | j  d ƒ rxŸ | j  d ƒ j ƒ  D]… \ } } | d } g  }	 xH | D]@ }
 | j  d ƒ j  |
 i  ƒ j  d ƒ } | r© |	 j | ƒ q© q© Wt |	 ƒ | d <| | | d <q† Wn  |  j d i | d 6| d 6ƒ d S(   sQ   
    Upgrade from persisted stores indexed on uid/gid to username/groupname.
    R   t   usernamet   groupst   memberst   nameN(   R   t	   iteritemst   appendt   sortedR   (   R#   t   old_user_datat   new_user_datat   new_group_datat   useridt	   user_datat   groupidt
   group_datat   old_group_memberst   new_group_memberst   user_idR-   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   index_users_on_names_addedO   s$    ""
i   c         C   s$   |  j  d d ƒ |  j  d d ƒ d S(   s:   Move registration-related information to a sensible place.s   message-store.secure_ids   registration.secure-ids   http-ping.insecure-ids   registration.insecure-idN(   t   move(   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   move_registration_datam   s    i   c         C   s   |  j  d d ƒ d S(   s8   Rename "message-queue" to "message-store", if necessary.s   message-queues   message-storeN(   R?   (   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   rename_message_queuet   s    i   c         C   s   |  j  d ƒ |  j  d ƒ d S(   sß   
    The user and group plugin has been refactored to include detecting
    and reporting changes made externally to Landscape.  Old data
    needs to be wiped out so that the plugin sends fresh data to the
    server.
    R   R.   N(   s   userss   users(   s   userss   groups(   t   remove(   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   user_change_detection_addedz   s    i   c         C   s   |  j  d ƒ d S(   sî   
    The 'users' data used to be stored at /users/data, but now it is
    in /users/users, next to /users/groups. The key will be created
    automatically, but the old location will be deleted to prevent
    cruft from accumulating.
    R   t   dataN(   s   userss   data(   RB   (   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   group_support_added†   s    i   c         C   s   |  j  d ƒ d S(   s0   
    Urgent exchange is now in-memory only.
    s    message-exchange.urgent-exchangeN(   RB   (   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   delete_urgent_exchange‘   s    i   c         C   sR   |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ |  j  d ƒ d S(   su  
    The accumulation logic in the client has been refactored.  The
    previous logic required the mount info plugin to persist last
    known values.  The new logic doesn't required the plugin to worry
    about this detail, so we can remove old persisted values.

    Also, some keys for persisted information have changed, so stored
    information is being reset.
    s   load-averages   memory-infos
   mount-infos   processor-infoR   s   trip-pointsN(   RB   (   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   delete_old_resource_data™   s    i   c         C   s   |  j  d ƒ d S(   s  
    The client was released with user support before the server was
    deployed; the client tried sending messages about user data and
    the server ignored it. Unfortunately, the client didn't know they
    were ignored, so it's not sending new data.
    R   RD   N(   s   userss   data(   RB   (   R#   (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   delete_user_data¬   s    (   R   t   landscape.patchR    t   landscape.lib.persistR   t   landscape.package.storeR   t   upgrade_managerR,   t   upgraderR>   R@   RA   RC   RE   RF   RG   RH   (    (    (    s>   /usr/lib/python2.7/dist-packages/landscape/upgraders/legacy.pyt   <module>   s$   	>