Creating a new LXD command or modify an existing LXD command

I was wondering if instead of creating a wrapper API to talk to LXD from remote servers, in order to implement some functionality I need, if it would make more sense to just add a command directly to LXD API instead.

If reasonable/feasible, where to start, documentation, where to start looking in the code, etc…

Best place to start is here by explaining your idea before starting to code as we maybe able to give you some pointers or guidance.

1 Like

Thank you @tomp,
OK, so for the simplest parts first, I need some commands like:

  • “new-tenant” = lxc launch imagename containername
    It needs to stop 2 containers (APP + DB).
    Then edit the HAProxy config file or connect to the hap control plane API so it does this for you.
    Create randomized credentials and apply to both ends.
    Check if the command was successful.
    Finally send an event or log to a DB whether the command was successful, etc.

  • “freeze” (tenant) command which is basically the same as:
    lxc stop conatainername
    Needs to stop 2 containers (APP + DB).
    Then edit the HAProxy config file or connect to the hap control plane API so it does this for you.
    Check if the command was successful.
    Finally send an event or log to a DB whether the command was successful, etc.

Just 2 examples from a total of 15 or so commands / about 50-75 endpoints…
Initially single host, then clustered in a second phase.

The current design implements one command as several endpoints, here’s an example for the “freeze” command.

/v2.1/tenant/manage/freeze Stops the APP and MySQL Containers for a specific tenant and accordingly adjust the HAP configuration.
/v2.1/tenant/manage/freeze/app Stops the APP container for a specific tenant
/v2.1/tenant/manage/freeze/mysql Stops the MySQL container for a specific tenant
/v2.1/tenant/manage/freeze/hap Adjusts the HAP configuration for a specific container that is being frozen.

And if we want to keep things assynchronous…
/v2.1/tenant/manage/freeze/check/app
/v2.1/tenant/manage/freeze/check/mysql
/v2.1/tenant/manage/freeze/check/hap

Thanks!

This seems a bit too specific to be including into LXD’s own API.

LXD does have the concept of Projects, which you may find useful for grouping instances associated with a particular tenant.

See https://linuxcontainers.org/lxd/docs/master/projects/

Also, from a terminology perspective, LXD does have lxc freeze <instance> (an alias of lxc pause) that will freeze a running instance, but not stop it, allowing it to be resumed using lxc start <instance>.

1 Like