]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdownaddons/utilsbase.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
11 from ifupdown
.utils
import utils
12 import ifupdown
.ifupdownflags
as ifupdownflags
13 from ifupdown
.iface
import *
19 def wrap(*args
, **kwargs
):
20 started_at
= time
.time()
21 result
= func(*args
, **kwargs
)
23 print (time
.time() - started_at
)
27 class utilsBase(object):
28 """ Base class for ifupdown addon utilities """
30 def __init__(self
, *args
, **kargs
):
31 modulename
= self
.__class
__.__name
__
32 self
.logger
= logging
.getLogger('ifupdown.' + modulename
)
34 def write_file(self
, filename
, strexpr
):
36 self
.logger
.info('writing \'%s\'' %strexpr
+
37 ' to file %s' %filename
)
38 if ifupdownflags
.flags
.DRYRUN
:
40 with
open(filename
, 'w') as f
:
43 self
.logger
.warn('error writing to file %s'
44 %filename
+ '(' + str(e
) + ')')
48 def read_file(self
, filename
):
50 self
.logger
.debug('reading \'%s\'' %filename
)
51 with
open(filename
, 'r') as f
:
57 def read_file_oneline(self
, filename
):
59 self
.logger
.debug('reading \'%s\'' %filename
)
60 with
open(filename
, 'r') as f
:
61 return f
.readline().strip('\n')
66 def sysctl_set(self
, variable
, value
):
67 utils
.exec_command('sysctl %s=%s' % (variable
, value
))
69 def sysctl_get(self
, variable
):
70 return utils
.exec_command('sysctl %s' % variable
).split('=')[1].strip()