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

✨feat: Enhance support for containers #126

Merged
merged 2 commits into from
Mar 7, 2024
Merged

✨feat: Enhance support for containers #126

merged 2 commits into from
Mar 7, 2024

Conversation

alperencelik
Copy link
Contributor

This PR aims to enhance LXC support for Proxmox. Here is the documentation of LXC(Containers) API.

https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc

Copy link

codecov bot commented Mar 6, 2024

Codecov Report

Attention: Patch coverage is 16.92308% with 108 lines in your changes are missing coverage. Please review.

Project coverage is 27.12%. Comparing base (fdb95a1) to head (cb546f4).
Report is 9 commits behind head on main.

Files Patch % Lines
containers.go 19.81% 86 Missing and 3 partials ⚠️
nodes.go 0.00% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #126      +/-   ##
==========================================
+ Coverage   25.95%   27.12%   +1.17%     
==========================================
  Files          15       15              
  Lines        1753     1928     +175     
==========================================
+ Hits          455      523      +68     
- Misses       1278     1377      +99     
- Partials       20       28       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alperencelik
Copy link
Contributor Author

I'm not sure if this PR satisfies #118.

@@ -52,24 +52,28 @@ func (c *Container) Start(ctx context.Context) (status string, err error) {
return status, c.client.Post(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/status/start", c.Node, c.VMID), nil, &status)
}

func (c *Container) Stop(ctx context.Context) (status *ContainerStatus, err error) {
func (c *Container) Stop(ctx context.Context) (status string, err error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh did we really add this before the the data field was being auto-parsed... goodness that was a long time ago. great fix and probably can remove the ContainerStatus type too right? it's at this point useless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually when I checked the API doc realized it turns the UPID as a string so I don't think we need something like containerStatus. IMO returning the UPID as it is might not be the correct way to do it so we can convert them to tasks. Here is an example of start but any status command returns the same object:

root@lowtower:~# pvesh create /nodes/lowtower/lxc/150/status/start UPID:lowtower:0035154F:068C3DB0:65E99E9D:vzstart:150:root@pam:

So what I'm offering is converting that one to

func (c *Container) Stop(ctx context.Context) (task *Task, err error) { var upid UPID if err := c.client.Post(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/status/stop", c.Node, c.VMID), nil, &upid); err != nil { return nil, err } return NewTask(upid, c.client), nil }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree to that change, let's do that. UPID and Tasks didnt exist when those funcs were initially wrote so let's go that route.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I've created #129 so if you agree we can continue from there.

return NewTask(upid, c.client), nil
}

func (c *Container) RRDData(ctx context.Context, timeframe Timeframe, consolidationFunction ConsolidationFunction) (rrddata []*RRDData, err error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance you learned anything writing the container RRDData func to help fix the virtualmachine func for this guy #112 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I didn't realize the issue before so I just followed the same method for Containers as we do on VirtualMachines. If you think that can cause issues we can remove or I can try to follow up on the issue and if I find anything I can come back to this one.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have no context, i thought it worked tbh and havent looked into it

@luthermonson
Copy link
Owner

@alperencelik this pretty much what most people need to get going with containers. Closes #118 imho

If you think we can drop that type and/or know of a fix for the rrddata func for vms then feel free to drop another PR. going to get this merged and cut a release tonight as this is a ton of new funcs added that people may way to use

@luthermonson luthermonson merged commit fbc1faa into luthermonson:main Mar 7, 2024
2 of 3 checks passed
@alperencelik
Copy link
Contributor Author

Thank you so much for reviewing @luthermonson.

I would like to hear your thoughts as well so for /lxc/status I'm offering to convert the strings to tasks since the /status returns a UPID but for /rrdData I guess I need some time to test it.

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

Successfully merging this pull request may close these issues.

2 participants