af4e177ed749f1cd765e8b5e3a1f19f51ced6319
[ira/wip.git] / source4 / scripting / python / samba / netcmd / time.py
1 #!/usr/bin/env python
2 #
3 # time
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 import common
24 from samba.net import Net
25
26 from samba.netcmd import (
27     Command,
28     )
29
30 class cmd_time(Command):
31     """Retrieve the time on a remote server [server connection needed]"""
32     synopsis = "%prog time <server-name>"
33
34     takes_args = ["server_name?"]
35
36     def run(self, server_name=None, credopts=None, sambaopts=None, versionopts=None):
37         lp = sambaopts.get_loadparm()
38         creds = credopts.get_credentials(lp, fallback_machine=True)
39         net = Net(creds, lp, server=credopts.ipaddress)
40         if server_name is None:
41             server_name = common.netcmd_dnsname(lp)
42         print net.time(server_name)