<s> import os <EOL> from samba import sites <EOL> from samba . samdb import SamDB <EOL> import samba . getopt as options <EOL> from samba . auth import system_session <EOL> from samba . netcmd import ( <EOL> Command , <EOL> CommandError , <EOL> SuperCommand <EOL> ) <EOL> class cmd_sites_create ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_args = [ "<STR_LIT>" ] <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> def run ( self , sitename , sambaopts = None , credopts = None , versionopts = None ) : <EOL> lp = sambaopts . get_loadparm ( ) <EOL> creds = credopts . get_credentials ( lp , fallback_machine = True ) <EOL> url = lp . private_path ( "<STR_LIT>" ) <EOL> if not os . path . exists ( url ) : <EOL> raise CommandError ( "<STR_LIT>" % url ) <EOL> samdb = SamDB ( url = url , session_info = system_session ( ) , <EOL> credentials = creds , lp = lp ) <EOL> samdb . transaction_start ( ) <EOL> try : <EOL> ok = sites . create_site ( samdb , samdb . get_config_basedn ( ) , sitename ) <EOL> samdb . transaction_commit ( ) <EOL> except sites . SiteAlreadyExistsException , e : <EOL> samdb . transaction_cancel ( ) <EOL> raise CommandError ( "<STR_LIT>" % ( sitename , str ( e ) ) ) <EOL> self . outf . write ( "<STR_LIT>" % sitename ) <EOL> class cmd_sites_delete ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_args = [ "<STR_LIT>" ] <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> def run ( self , sitename , sambaopts = None , credopts = None , versionopts = None ) : <EOL> lp = sambaopts . get_loadparm ( ) <EOL> creds = credopts . get_credentials ( lp , fallback_machine = True ) <EOL> url = lp . private_path ( "<STR_LIT>" ) <EOL> if not os . path . exists ( url ) : <EOL> raise CommandError ( "<STR_LIT>" % url ) <EOL> samdb = SamDB ( url = url , session_info = system_session ( ) , <EOL> credentials = creds , lp = lp ) <EOL> samdb . transaction_start ( ) <EOL> try : <EOL> ok = sites . delete_site ( samdb , samdb . get_config_basedn ( ) , sitename ) <EOL> samdb . transaction_commit ( ) <EOL> except sites . SiteException , e : <EOL> samdb . transaction_cancel ( ) <EOL> raise CommandError ( <EOL> "<STR_LIT>" % ( sitename , str ( e ) ) ) <EOL> self . outf . write ( "<STR_LIT>" % sitename ) <EOL> class cmd_sites ( SuperCommand ) : <EOL> """<STR_LIT>""" <EOL> subcommands = { } <EOL> subcommands [ "<STR_LIT>" ] = cmd_sites_create ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_sites_delete ( ) </s>
