OSDN Git Service

Add validate
[karesansui/karesansui.git] / bin / restart_network_interface.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # This file is part of Karesansui.
5 #
6 # Copyright (C) 2010 HDE, Inc.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13
14 import os
15 import sys
16 import logging
17 import fcntl
18 from optparse import OptionParser
19
20 from ksscommand import KssCommand, KssCommandException, KssCommandOptException
21 import __cmd__
22
23 try:
24     import karesansui
25     from karesansui import __version__
26     from karesansui.lib.utils import load_locale, execute_command
27     from karesansui.lib.const import NETWORK_COMMAND
28
29 except ImportError:
30     print >>sys.stderr, "[Error] karesansui package was not found."
31     sys.exit(1)
32
33 _ = load_locale()
34
35 usage = '%prog [options]'
36
37 def getopts():
38     optp = OptionParser(usage=usage, version=__version__)
39     return optp.parse_args()
40
41 def chkopts(opts):
42     return True
43
44 class RestartNetworkInterface(KssCommand):
45
46     def process(self):
47         (opts, args) = getopts()
48         chkopts(opts)
49         self.up_progress(10)
50
51         network_restart_cmd = (NETWORK_COMMAND,
52                                "restart",
53                                )
54         (rc, res) = execute_command(network_restart_cmd)
55         if rc != 0:
56             raise KssCommandException('Failure restart network.')
57
58         return True
59
60 if __name__ == "__main__":
61     target = RestartNetworkInterface()
62     sys.exit(target.run())