Skip to content

Commit 6f1777b

Browse files
committed
[airos] handled file creation without tar archive
1 parent 309e712 commit 6f1777b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

netjsonconfig/backends/airos/airos.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import OrderedDict
2+
from io import BytesIO
3+
import six
24

35
from ..base.backend import BaseBackend
46
from .converters import (Aaa, Bridge, Dhcpc, Discovery, Dyndns, Ebtables, Gui,
@@ -64,3 +66,22 @@ def to_intermediate(self):
6466
super(AirOs, self).to_intermediate()
6567
for k, v in self.intermediate_data.items():
6668
self.intermediate_data[k] = to_ordered_list(v)
69+
70+
def generate(self):
71+
"""
72+
Returns a ``BytesIO`` instance representing the configuration file
73+
74+
:returns: in-memory configuration file, instance of ``BytesIO``
75+
"""
76+
fl = BytesIO()
77+
fl.write(six.b(self.render()))
78+
fl.seek(0)
79+
return fl
80+
81+
def write(self, name, path='./'):
82+
byte_object = self.generate()
83+
file_name = '{0}.cfg'.format(name)
84+
if not path.endswith('/'):
85+
path += '/'
86+
with open('{0}{1}'.format(path, file_name), 'wb') as out:
87+
out.write(byte_object.getvalue())

0 commit comments

Comments
 (0)