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

Add support for LXC clone #99

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@
"net/url"
)

func (c *Container) Clone(ctx context.Context, params *ContainerCloneOptions) (newid int, task *Task, err error) {
var upid UPID

if params == nil {
params = &ContainerCloneOptions{}
}
if params.NewID <= 0 {
cluster, err := c.client.Cluster(ctx)
if err != nil {
return newid, nil, err
}
newid, err := cluster.NextID(ctx)
if err != nil {
return newid, nil, err
}
params.NewID = newid

Check warning on line 24 in containers.go

View check run for this annotation

Codecov / codecov/patch

containers.go#L9-L24

Added lines #L9 - L24 were not covered by tests
}
if err := c.client.Post(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/clone", c.Node, c.VMID), params, &upid); err != nil {
return 0, nil, err
}
return newid, NewTask(upid, c.client), nil

Check warning on line 29 in containers.go

View check run for this annotation

Codecov / codecov/patch

containers.go#L26-L29

Added lines #L26 - L29 were not covered by tests
}

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)
}
Expand Down
12 changes: 12 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ type Container struct {
MaxSwap uint64
}

type ContainerCloneOptions struct {
NewID int `json:"newid"`
BWLimit uint64 `json:"bwlimit,omitempty"`
Description string `json:"description,omitempty"`
Full uint8 `json:"full,omitempty"`
Hostname string `json:"hostname,omitempty"`
Pool string `json:"pool,omitempty"`
SnapName string `json:"snapname,omitempty"`
Storage string `json:"storage,omitempty"`
Target string `json:"target,omitempty"`
}

type ContainerStatuses []*ContainerStatus
type ContainerStatus struct {
Data string `json:",omitempty"`
Expand Down