-
Notifications
You must be signed in to change notification settings - Fork 39
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
Generate an init file that can be used with exported images #477
Conversation
39bde16
to
5fd1373
Compare
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.
Looks good!
About the overall approach - I'm still not sure if "positive" checking wouldn't have made it easier:
- You have a list of "filters", which can even be callables(like re.match partials).
- You traverse through the graph, always keeping your current 'path'. For each node you visit you check if any of the callables returns True. If it does you delete it and never visit his sons(so BFS would make sense here).
So when you finish travelling, you get only the nodes which passed(or should I say did not pass) the filters.
But, you'd still have to decide how to construct "paths" when you meet lists versus dicts... so perhaps its not worth it.
@@ -27,6 +27,7 @@ | |||
create an alternative implementation of the provisioning details for the VM, | |||
for example, using a remote libvirt instance or similar. | |||
""" | |||
from copy import deepcopy |
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.
We have our "specific" implementation of deepcopy in 'utils.py', I guess here its safe? (it was added to avoid the cross-references issue iirc)
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.
What do you mean by "cross-references" ?
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.
See the discussion here: #346 (review)
Not 100% if its relevant, just checking.
@@ -364,6 +365,10 @@ def metadata(self): | |||
def disks(self): | |||
return self._spec['disks'][:] | |||
|
|||
@property | |||
def spec(self): |
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 makes the new spec somewhat "read only", no? was that the intention?
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.
Yes.
Any change to the spec will effect the structure of the env. IMO changes to the env should be done with specific object's methods (in this case the 'vm' object), and not directly to its data.
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.
👍
lago/utils.py
Outdated
all the metadata dicts from all domains disks will be removed. | ||
|
||
Args: | ||
spec (dict): spec file to remove keys from |
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.
Its a dict(not a file) :) as you wrote..
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.
done
lago/utils.py
Outdated
paths (list): list of paths to the keys that should be removed | ||
|
||
Returns: | ||
None |
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.
Please add 'raises' here(look elsewhere in the file the exact syntax so it would format sphinixily nicely)
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.
done
lago/utils.py
Outdated
elif len(path) == 1: | ||
key = path.pop() | ||
if not isinstance(spec, dict): | ||
raise LagoUserException( |
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 would print a more detailed message here, that hints what to do or what the user did wrong.
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.
done
lago/utils.py
Outdated
'does not exist'.format('/'.join(path), current) | ||
) | ||
except TypeError: | ||
raise LagoUserException( |
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.
when is this condition met and why? and how is it different from line 726?
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.
Example for each exception (by the order I catch them):
You have tried to remove the following key - "template".
Keys can not be removed from type <type 'list'>
Please verify that path - "domains/*/disks/template" is valid
Glob char * should refer only to dict or list, not to <type 'int'>
Please fix path - "domains/*/memory/*/some_key"
Malformed path "domains/*/gpu/*", key "gpu" does not exist
Malformed path "domains/*/disks/root/vda", can not get by key from type <type 'list'>
for _, domain in spec['domains'].viewitems(): | ||
for disk in domain['disks']: | ||
if disk['type'] == 'template': | ||
disk['template_type'] = 'qcow2' |
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.
Not sure if this is the right place for this logic. Should probably be a different method.
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 method is for generating an init file that can be used with the exported images 'out of the box'.
For general spec you should use get_env_spec
lago/virt.py
Outdated
'$LAGO_INITFILE_PATH', os.path.basename(disk['path']) | ||
) | ||
|
||
with open(os.path.join(dst_dir, 'LagoInitFile'), 'wt') as f: |
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.
The dumping filename should be configuable, moreover it should drop it to stdout by default(like ansible_hosts cmd), so you could do something like:
lago dump-init >> my-init-el73-2011
Not sure if its an issue but if the file already exists(LagoInitFile) it will override 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.
This method is called only when exporting images, so it makes sense to write directly to a file.
I agree that the filename should be configurable.
@@ -961,7 +961,8 @@ def _create_disks( | |||
'dev': disk['dev'], | |||
'format': disk['format'], | |||
'metadata': metadata, | |||
'type': disk['type'] | |||
'type': disk['type'], | |||
'name': disk['name'] |
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.
👍
lago/utils.py
Outdated
spec.pop(key, None) | ||
else: | ||
current = path[0] | ||
if current == '*': |
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.
probably better to add this as a default to the function:
def .... (..., sep='*')
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.
done
5876889
to
db1efb5
Compare
lago/utils.py
Outdated
""" | ||
|
||
def remove_key(path, spec): | ||
if len(path) == 0: | ||
return | ||
elif len(path) == 1: | ||
key = path.pop() | ||
if not isinstance(spec, dict): | ||
if not isinstance(spec, collections.Mapping): |
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.
Cool. This should work for OrderedDicts also?
lago/utils.py
Outdated
format(key, spec, type(spec)) | ||
'You have tried to remove the following key - "{key}".\n' | ||
'Keys can not be removed from type {spec_type}\n' | ||
'Please verify that path - "{{path}}" is valid'.format( |
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.
Nice.
db1efb5
to
57a17c5
Compare
ci merge please |
The generated init file will represent the env and will contain relative paths to the exported images. Signed-off-by: gbenhaim <[email protected]>
57a17c5
to
3441728
Compare
ci test please |
ci merge please |
The generated init file will represent the env and will contain
relative paths to the exported images.
Signed-off-by: gbenhaim [email protected]
closes #473