]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdownaddons/utilsbase.py
3 # Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
11 from ifupdown2
.ifupdown
.iface
import *
12 from ifupdown2
.ifupdown
.utils
import utils
13 from ifupdown2
.ifupdownaddons
.cache
import *
15 import ifupdown2
.ifupdown
.ifupdownflags
as ifupdownflags
17 from ifupdown
.iface
import *
18 from ifupdown
.utils
import utils
19 from ifupdownaddons
.cache
import *
21 import ifupdown
.ifupdownflags
as ifupdownflags
25 def wrap(*args
, **kwargs
):
26 started_at
= time
.time()
27 result
= func(*args
, **kwargs
)
29 print (time
.time() - started_at
)
33 class utilsBase(object):
34 """ Base class for ifupdown addon utilities """
36 def __init__(self
, *args
, **kargs
):
37 modulename
= self
.__class
__.__name
__
38 self
.logger
= logging
.getLogger('ifupdown.' + modulename
)
40 def write_file(self
, filename
, strexpr
):
42 self
.logger
.info('writing \'%s\'' %strexpr
+
43 ' to file %s' %filename
)
44 if ifupdownflags
.flags
.DRYRUN
:
46 with
open(filename
, 'w') as f
:
49 self
.logger
.warn('error writing to file %s'
50 %filename
+ '(' + str(e
) + ')')
54 def read_file(self
, filename
):
56 self
.logger
.debug('reading \'%s\'' %filename
)
57 with
open(filename
, 'r') as f
:
63 def read_file_oneline(self
, filename
):
65 self
.logger
.debug('reading \'%s\'' %filename
)
66 with
open(filename
, 'r') as f
:
67 return f
.readline().strip('\n')
72 def sysctl_set(self
, variable
, value
):
73 utils
.exec_command('%s %s=%s' %
74 (utils
.sysctl_cmd
, variable
, value
))
76 def sysctl_get(self
, variable
):
77 return utils
.exec_command('%s %s' %
79 variable
)).split('=')[1].strip()