mac: begin to downstrip
This commit is contained in:
parent
64ab011299
commit
53c6a14d60
1 changed files with 22 additions and 34 deletions
|
@ -26,29 +26,32 @@ import os.path
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import cinv
|
|
||||||
from cinv import fsproperty
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Error(cinv.Error):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Mac(object):
|
class Mac(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.base_dir = self.get_base_dir()
|
self.base_dir = "."
|
||||||
|
|
||||||
_prefix = fsproperty.FileStringProperty(lambda obj: os.path.join(obj.base_dir, "prefix"))
|
self._prefix = "02:00"
|
||||||
free = fsproperty.FileListProperty(lambda obj: os.path.join(obj.base_dir, "free"))
|
|
||||||
last = fsproperty.FileStringProperty(lambda obj: os.path.join(obj.base_dir, "last"))
|
self.free = self.read_file("mac-free")
|
||||||
|
self.last = self.read_file("mac-last")
|
||||||
|
|
||||||
|
def read_file(self, filename):
|
||||||
|
fname = os.path.join(self.base_dir, filename)
|
||||||
|
ret = []
|
||||||
|
|
||||||
def _init_base_dir(self):
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(self.base_dir, exist_ok=True)
|
with open(fname, "r") as fd:
|
||||||
except OSError as e:
|
ret = fd.readlines()
|
||||||
raise Error(e)
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_mac(mac):
|
def validate_mac(mac):
|
||||||
|
@ -146,26 +149,11 @@ class Mac(object):
|
||||||
host.host_type = args.type
|
host.host_type = args.type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def commandline_args(cls, parent_parser, parents):
|
def commandline(cls):
|
||||||
"""Add us to the parent parser and add all parents to our parsers"""
|
pass
|
||||||
|
|
||||||
parser = {}
|
|
||||||
parser['sub'] = parent_parser.add_subparsers(title="Mac Commands")
|
|
||||||
|
|
||||||
parser['free-add'] = parser['sub'].add_parser('free-add', parents=parents)
|
if __name__ == '__main__':
|
||||||
parser['free-add'].add_argument('address', help='Address to add to free database')
|
m = Mac()
|
||||||
parser['free-add'].set_defaults(func=cls.commandline_free_add)
|
m.commandline()
|
||||||
|
print(m.free)
|
||||||
parser['free-list'] = parser['sub'].add_parser('free-list', parents=parents,
|
|
||||||
help="List free mac addresses")
|
|
||||||
parser['free-list'].set_defaults(func=cls.commandline_free_list)
|
|
||||||
|
|
||||||
parser['generate'] = parser['sub'].add_parser('generate', parents=parents)
|
|
||||||
parser['generate'].set_defaults(func=cls.commandline_generate)
|
|
||||||
|
|
||||||
parser['prefix-get'] = parser['sub'].add_parser('prefix-get', parents=parents)
|
|
||||||
parser['prefix-get'].set_defaults(func=cls.commandline_prefix_get)
|
|
||||||
|
|
||||||
parser['prefix-set'] = parser['sub'].add_parser('prefix-set', parents=parents)
|
|
||||||
parser['prefix-set'].add_argument('prefix', help="3 Byte address prefix (f.i. '00:16:3e')")
|
|
||||||
parser['prefix-set'].set_defaults(func=cls.commandline_prefix_set)
|
|
||||||
|
|
Loading…
Reference in a new issue