]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdown/utils.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
16 def importName(cls
, modulename
, name
):
17 """ Import a named object """
19 module
= __import__(modulename
, globals(), locals(), [name
])
22 return getattr(module
, name
)
25 def lockFile(cls
, lockfile
):
27 fp
= os
.open(lockfile
, os
.O_CREAT | os
.O_TRUNC | os
.O_WRONLY
)
28 fcntl
.flock(fp
, fcntl
.LOCK_EX | fcntl
.LOCK_NB
)
34 def parse_iface_range(cls
, name
):
35 range_match
= re
.match("^([\w\.]+)\[([\d]+)-([\d]+)\]", name
)
37 range_groups
= range_match
.groups()
38 if range_groups
[1] and range_groups
[2]:
39 return (range_groups
[0], int(range_groups
[1], 10),
40 int(range_groups
[2], 10))
44 def expand_iface_range(cls
, name
):
46 iface_range
= cls
.parse_iface_range(name
)
48 for i
in range(iface_range
[1], iface_range
[2]):
49 ifacenames
.append('%s-%d' %(iface_range
[0], i
))