Skip to content
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

[GOCA] fix template and enhance dynamic template parsing/building #3219

Closed
7 tasks
treywelsh opened this issue Apr 11, 2019 · 3 comments
Closed
7 tasks

[GOCA] fix template and enhance dynamic template parsing/building #3219

treywelsh opened this issue Apr 11, 2019 · 3 comments

Comments

@treywelsh
Copy link
Contributor

treywelsh commented Apr 11, 2019

Description

/!\ breaking changes /!\

What's inside:

  • bug fixes on static XML structures: fix the type of some attributes, XML tag typos...
  • bug fix on template: the previous implementation couldn't parse vectors defined by the user.
  • Enable marshalling of XML structures, static and dynamic parts: allow to build entities from structures
  • Adds helpers on template to build or browse them easily
  • Templates parts are fully dynamic: there is no mix of static attributes with dynamic anymore.
    Use getter/setters with keys instead (see point below). It will simply a bit the GOCA code
  • Now, a set of keys are added to help the user to build/browse template data.

Overall it's more flexible, and it's more compliant with OpenNebula templates.
Among others, it should also reduce developer code size with less type conversions (string to int or float ... )

A side note:
The code to unmarshal the XML could be a bit complex, I'll see if I can simplify it but if anyone has a better idea, please share :)

Potential improvements:

  • Make the methode of entities "Create" and "Update" take a template instead of a string ?

It may still contains some problems or bugs, I tested it, but it lacks a lot of automatic testing, so I could miss some errors.

/!\ breaking changes /!
It breaks due to the rework of the dynamic parsing/building of template parts. Some elements are renamed etc.
And also because there is a commit fixing the XML structures.

To Reproduce
Create a vector in the template of any entity with custom tag names.

Expected behavior
Better parsing, building, and better code reuse and more flexible

Details

  • Affected Component: [e.g. Sunstone, Scheduler or Storage]
  • Hypervisor: [e.g. KVM]
  • Version: [e.g. 5.4.12 or development]

Additional context
Add any other context about the problem here.

Progress Status

  • Branch created
  • Code committed to development branch
  • Testing - QA
  • Documentation
  • Release notes - resolved issues, compatibility, known issues
  • Code committed to upstream release/hotfix branches
  • Documentation committed to upstream release/hotfix branches
@treywelsh
Copy link
Contributor Author

I closed the related pull request because I reworked some part and I work with a more complete and up to date version, rebased on top of #2940.
I will submit a new version when #2940 will be merged.
For now, my currents changes (among others) are on branch: https://github.com/iguanesolutions/one/commits/goca_pr_ready

@treywelsh
Copy link
Contributor Author

treywelsh commented Oct 11, 2019

I submit a new pull request with my changes, rebased on master.

I'm testing it, but as it remains a lot of work to do on the tests, I could miss some errors anyway.

@treywelsh
Copy link
Contributor Author

treywelsh commented Dec 18, 2019

Known limitation of current implementation of templates (not necessarily a bug but I prefer leave a note on this behaviour):

This concern only people that may want to generate XML format from dynamic templates, instead of generate strings.

For instance, this code sample on VMs:

        tpl := vm.NewTemplate()
	tpl.CPU(0.5)

	nic := tpl.AddNIC()
	nic.Add(shared.Network, "tutu")

	disk := tpl.AddDisk()
	disk.Add(shared.DiskType, "toto")

	data, err := xml.MarshalIndent(tpl, "", "  ")
	if err != nil {
		fmt.Printf("error: %v", err)
		return
	}
	fmt.Println(string(data))

Give:

<Template>
  <CPU>0.500000</CPU>
  <Elements>
    <NETWORK>tutu</NETWORK>
  </Elements>
  <Elements>
    <DISK_TYPE>toto</DISK_TYPE>
  </Elements>
</Template>

It's broken and shouldn't be used as an OpenNebula input (create, update ... methods).
As a side note, it could be solved making these changes: treywelsh/one@master...treywelsh:F-3219_fix_standalone_marshaling
(In addition, it would be probably slightly more efficient as the code is a bit less generic: pairs and vectors would live in a separate slice. Also: more efficient searching methods).

But, for now, it's possible to work with current templates:
The right way to do is just to call the string method on the template:

	tpl := vm.NewTemplate()
	tpl.CPU(0.5)

	nic := tpl.AddNIC()
	nic.Add(shared.Network, "tutu")

	disk := tpl.AddDisk()
	disk.Add(shared.DiskType, "toto")

	fmt.Println(tpl.String())

Give:

CPU="0.500000"
NIC=[
    NETWORK="tutu" ]
DISK=[
    DISK_TYPE="toto" ]

This work properly as OpenNebula input.
The current implementation work like this as I kept orginal template building helpers with Element interface.

treywelsh added a commit to treywelsh/one that referenced this issue Jan 30, 2020
Signed-off-by: Pierre Lafievre <pierre.lafievre@iguanesolutions.com>
tinova pushed a commit that referenced this issue Jan 30, 2020
* Less restrictive parameter
* Fix quota structs marshalling
* Fix omitempty for consistency

Signed-off-by: Pierre Lafievre <pierre.lafievre@iguanesolutions.com>
tinova pushed a commit that referenced this issue Jan 30, 2020
* Less restrictive parameter
* Fix quota structs marshalling
* Fix omitempty for consistency

Signed-off-by: Pierre Lafievre <pierre.lafievre@iguanesolutions.com>
(cherry picked from commit 211617b)
rsmontero pushed a commit that referenced this issue Oct 4, 2024
Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant