samba-tool: epilog option to OptionParser available in python >= 2.6
[mat/samba.git] / source4 / scripting / python / samba / netcmd / vampire.py
1 #!/usr/bin/env python
2 #
3 # Vampire
4 #
5 # Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
6 # Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 import samba.getopt as options
23
24 from samba.net import Net
25
26 from samba.netcmd import (
27     Command,
28     Option,
29     SuperCommand,
30     CommandError
31     )
32
33 class cmd_vampire(Command):
34     """Join and synchronise a remote AD domain to the local server"""
35     synopsis = "%prog vampire [options] <domain>"
36
37     takes_options = [
38         Option("--target-dir", help="Target directory.", type=str),
39         Option("--force", help="force run", action='store_true', default=False),
40         ]
41
42     takes_args = ["domain"]
43
44     def run(self, domain, target_dir=None, credopts=None, sambaopts=None, versionopts=None, force=False):
45         if not force:
46             raise CommandError("samba-tool vampire is deprecated, please use samba-tool domain join. Use --force to override")
47         lp = sambaopts.get_loadparm()
48         creds = credopts.get_credentials(lp)
49         net = Net(creds, lp, server=credopts.ipaddress)
50         (domain_name, domain_sid) = net.vampire(domain=domain, target_dir=target_dir)
51         self.outf.write("Vampired domain %s (%s)\n" % (domain_name, domain_sid))