Generate an init file that can be used with exported images - #477
Conversation
39bde16 to
5fd1373
Compare
nvgoldin
left a comment
There was a problem hiding this comment.
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.
| 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.
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.
What do you mean by "cross-references" ?
There was a problem hiding this comment.
See the discussion here: #346 (review)
Not 100% if its relevant, just checking.
| return self._spec['disks'][:] | ||
|
|
||
| @property | ||
| def spec(self): |
There was a problem hiding this comment.
This makes the new spec somewhat "read only", no? was that the intention?
There was a problem hiding this comment.
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.
| 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.
Its a dict(not a file) :) as you wrote..
| paths (list): list of paths to the keys that should be removed | ||
|
|
||
| Returns: | ||
| None |
There was a problem hiding this comment.
Please add 'raises' here(look elsewhere in the file the exact syntax so it would format sphinixily nicely)
| elif len(path) == 1: | ||
| key = path.pop() | ||
| if not isinstance(spec, dict): | ||
| raise LagoUserException( |
There was a problem hiding this comment.
I would print a more detailed message here, that hints what to do or what the user did wrong.
| 'does not exist'.format('/'.join(path), current) | ||
| ) | ||
| except TypeError: | ||
| raise LagoUserException( |
There was a problem hiding this comment.
when is this condition met and why? and how is it different from line 726?
There was a problem hiding this comment.
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.
Not sure if this is the right place for this logic. Should probably be a different method.
There was a problem hiding this comment.
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_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.
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.
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.
| 'metadata': metadata, | ||
| 'type': disk['type'] | ||
| 'type': disk['type'], | ||
| 'name': disk['name'] |
| spec.pop(key, None) | ||
| else: | ||
| current = path[0] | ||
| if current == '*': |
There was a problem hiding this comment.
probably better to add this as a default to the function:
def .... (..., sep='*')
5876889 to
db1efb5
Compare
| 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.
Cool. This should work for OrderedDicts also?
| 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( |
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 <galbh2@gmail.com>
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 galbh2@gmail.com
closes #473