-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed to use template files #13
Conversation
if not isinstance(builder.builders[j], DebianBondedNetwork): | ||
del builder.builders[j] | ||
j -= 1 | ||
return builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't like the way this looked and went looking for some better looking code, but I only came up with:
builder.builders = next(builder for builders in builder.builders if isinstance(builder, DebianBondedNetwork))
return builder
and I'm not so sure its better. It does have the benefit of not needing to iterate through the whole list only to keep 1 item though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, good catch, much cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minus the typo. It should be
builder.builders = next(builder for builder in builder.builders if isinstance(builder, DebianBondedNetwork))
return builder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
{% endif %} | ||
bond-master bond0 | ||
{% endfor %} | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline
post-up route add -net {{ subnet }} gw {{ ip4priv.gateway }} | ||
post-down route del -net {{ subnet }} gw {{ ip4priv.gateway }} | ||
{% endfor %} | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline
import logging | ||
from textwrap import dedent | ||
from jinja2 import Template, StrictUndefined | ||
from ..utils import Tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split imports with a blank line between stdlib, 3party, this-repo
self.task_template( | ||
"etc/sysconfig/network-scripts/ifcfg-bond0:0", | ||
"bonded/etc_sysconfig_network-scripts_ifcfg-bond0_0.j2", | ||
) | ||
|
||
# If no ip4pub is specified, the ip4priv is configured on the bond0 interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment isn't really very useful here, maybe instead at the top of inside the if
and expanded to say bond0
will already by the private ip so we don't need bond0:0
and we don't need any extra route either?
@@ -11,3 +11,13 @@ class RedhatBuilder(DistroBuilder): | |||
"scientificcernslc", | |||
] | |||
network_builders = [RedhatBondedNetwork, RedhatIndividualNetwork] | |||
templates_base = "distros/redhat/templates" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would kind of be better of templates
was assumed to exist or that this os's templates are in distro/$distro/templates
and handle existence/non-existence of templates in the base class machinery
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of that, but went with this to be lazy. Will go ahead and implement that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
def build_tasks(self): | ||
self.tasks = {} | ||
|
||
self.task_template("etc/hostname", "etc_hostname.j2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evil me want to find some utf-8 char that looks like /
and use that in the template name and replace utf8-esq-/
-> /
and have the base class be able to handle these common cases :D Less duplicated code.
https://www.fileformat.info/info/unicode/char/2215/index.htm :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like having all the files in the same folder like this. But I could build out the actual structure. There's nothing keeping us from doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so with the unicode char hack it would still all be in one dir, its just that we would have a character that we could use to encode filepaths in the filename. Hence the evil part :p
@@ -1,4 +1,7 @@ | |||
from .distro_builder import DistroBuilder, get_distro_builder | |||
from ..builder import NetworkData | |||
from .. import utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these imports are in the wrong order right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh, not sure, flipped
@@ -1,7 +1,25 @@ | |||
#!/usr/bin/env python3 | |||
|
|||
import os | |||
from setuptools import setup, find_packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this a nono?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import os
? github has been selecting wrong lines. Or are you referring to package_dir =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope to the importing multiple things in one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have never heard multiple imports under a package on the same line being a problem. Quick google search hasn't brought anything up about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right you are. PEP8 explicitly allows this. Its the multiple different modules in 1 line that is a nono. Also google python style guide says
Do not use relative names in imports. Even if the module is in the same package, use the full package name. This helps prevent unintentionally importing a package twice.
But who cares.
9643767
to
bd4275d
Compare
|
||
def build(self): | ||
""" | ||
Build executes the `DistroBuilder.build_tasks` and each `NetworkBuilder.build` | ||
function which builds the `tasks` dictionary of files to be processed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but what does this mean? LIke how is build different than render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've given this another shot.
def build_tasks(self): | ||
self.tasks = {} | ||
|
||
self.task_template("etc/hostname", "etc_hostname.j2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so with the unicode char hack it would still all be in one dir, its just that we would have a character that we could use to encode filepaths in the filename. Hence the evil part :p
packetnetworking/utils.py
Outdated
@@ -1,9 +1,12 @@ | |||
import os | |||
import re | |||
import sys | |||
import json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click should be on its own line, and please2sort
@@ -1,7 +1,25 @@ | |||
#!/usr/bin/env python3 | |||
|
|||
import os | |||
from setuptools import setup, find_packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope to the importing multiple things in one line
Here I'm pulling the hard coded """{template}""" into actual template files. In doing so, I also brought common files that are shared between network configs such has hostname configuration and hosts files into the distro builder. By doing so, I also had to move the render and execution functions into the distro builder. This I think makes more sense, and allows for a better hierarchical structure to tasks. To better assist with adding tasks and using template files, a new parent class `Tasks` was created which allows a task to be set by calling `self.task(task, content, write_mode, mode, fmt)` which will build the structure accordingly. For a template file you can call `self.task_template(task, rel_path, write_mode, mode, fmt)`. `rel_path` is relative to the `templates_base` variable defined in the distro builder file.
bd4275d
to
c8665b7
Compare
Here I'm pulling the hard coded """{template}""" into actual
template files. In doing so, I also brought common files that
are shared between network configs such has hostname configuration
and hosts files into the distro builder.
By doing so, I also had to move the render and execution functions
into the distro builder. This I think makes more sense, and allows
for a better hierarchical structure to tasks.
To better assist with adding tasks and using template files, a new
parent class
Tasks
was created which allows a task to be set bycalling
self.task(task, content, write_mode, mode, fmt)
whichwill build the structure accordingly. For a template file you can
call
self.task_template(task, rel_path, write_mode, mode, fmt)
.rel_path
is relative to thetemplates_base
variable definedin the distro builder file.