ó
E®Uc           @   s   d  Z  d d l Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d „  Z d „  Z	 d S(   s   Manipulating sites.iÿÿÿÿN(   t   FLAG_MOD_ADDt   SiteExceptionc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   Base element for Sites errorsc         C   s   | |  _  d  S(   N(   t   value(   t   selfR   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyt   __init__   s    c         C   s   d |  j  S(   Ns   SiteException: (   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR      s   	t   SiteNotFoundExceptionc           B   s    e  Z d  Z d „  Z d „  Z RS(   s>   Raised when the site is not found and it's expected to exists.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   %   s    c         C   s   d |  j  S(   Ns   SiteNotFoundException: (   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   (   s    (   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR	   "   s   	t   SiteAlreadyExistsExceptionc           B   s    e  Z d  Z d „  Z d „  Z RS(   sB   Raised when the site is not found and it's expected not to exists.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   .   s    c         C   s   d |  j  S(   Ns   SiteAlreadyExists: (   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   1   s    (   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR
   +   s   	t   SiteServerNotEmptyExceptionc           B   s    e  Z d  Z d „  Z d „  Z RS(   s0   Raised when the site still has servers attached.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   7   s    c         C   s   d |  j  S(   Ns   SiteServerNotEmpty: (   R   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   :   s    (   R   R   R   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyR   4   s   	c         C   sM  |  j  d | d t j d d | ƒ } t | ƒ d k rJ t d | ƒ ‚ n  t j ƒ  } t j |  d | t | ƒ f ƒ | _ t j	 d t
 d	 ƒ | d	 <|  j | ƒ t j ƒ  } t j |  d
 t | j ƒ ƒ | _ t j	 d t
 d	 ƒ | d	 <|  j | ƒ t j ƒ  } t j |  d t | j ƒ ƒ | _ t j	 d t
 d	 ƒ | d	 <|  j | ƒ t S(   s  
    Create a site

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param siteName: Name of the site to create
    :return: True upon success
    :raise SiteAlreadyExists: if the site to be created already exists.
    t   baset   scopet
   expressions   (&(objectclass=Site)(cn=%s))i    s&   A site with the name %s already existss   Cn=%s,CN=Sites,%st   sitet   objectclasss   Cn=NTDS Site Settings,%st   nTDSSiteSettingss   Cn=Servers,%st   serversContainer(   t   searcht   ldbt   SCOPE_SUBTREEt   lenR
   t   Messaget   Dnt   strt   dnt   MessageElementR    t   addt   True(   t   samdbt   configDnt   siteNamet   rett   mt   m2t   m3(    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyt   create_site=   s"    %""c      	   C   s  t  j |  d t | ƒ ƒ } t  j |  d | t | ƒ f ƒ } t  j |  d t | ƒ ƒ } |  j d | d t  j d d t | ƒ ƒ } t | ƒ d k rª t d	 | ƒ ‚ n  |  j d | d t  j d d
 ƒ } t | ƒ d k rð t d | ƒ ‚ n  |  j | d g ƒ t	 S(   sV  
    Delete a site

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param siteName: Name of the site to delete
    :return: True upon success
    :raise SiteNotFoundException: if the site to be deleted do not exists.
    :raise SiteServerNotEmpty: if the site has still servers in it.
    s   CN=Sites,%ss   Cn=%s,CN=Sites,%ss   Cn=Servers,%sR   R   R   s   (dn=%s)i   s   Site %s do not existss   (objectclass=server)i    s9   Site %s still has servers in it, move them before removals   tree_delete:0(
   R   R   R   R   t   SCOPE_ONELEVELR   R	   R   t   deleteR   (   R   R   R    t   dnsitest   dnsitet   dnserverR!   (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyt   delete_sitea   s    "	(
   R   R   R    t	   ExceptionR   R	   R
   R   R%   R+   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/sites.pyt   <module>   s   
				$