NixOS / nixops

NixOps is a tool for deploying to NixOS machines in a network or cloud.
https://nixos.org/nixops
GNU Lesser General Public License v3.0
1.87k stars 364 forks source link

Renaming deployments #1350

Closed deepfire closed 4 years ago

deepfire commented 4 years ago

~Currently deployments cannot be renamed.~

This complicates their management, if you have a bunch of those, and the initial choice of their names isn't matching changed requirements.

tewfik-ghariani commented 4 years ago

It is possible to rename deployments using 'modify' sub-command and the -n option

Help Menu

$ nixops modify --help
usage: nixops modify [-h] [--state FILE] [--deployment UUID_OR_NAME] [--debug]
                     [--confirm] [-I PATH] [--max-jobs N] [--cores N]
                     [--keep-going] [--keep-failed] [--show-trace]
                     [--fallback] [--no-build-output] [--option NAME VALUE]
                     [--read-only-mode] [--name NAME] [--template TEMPLATE]
                     [NIX-FILE [NIX-FILE ...]]
..
..
..
  --name NAME, -n NAME  new symbolic name of deployment

Code :

https://github.com/NixOS/nixops/blob/4642152dcd9608b53481a0018d4285b13449c965/nixops/script_defs.py#L172-L176

Example List the deployments

$ nixops list
+--------------------------------------+---------------------+------------------------+------------+------+
| UUID                                 | Name                | Description            | # Machines | Type |
+--------------------------------------+---------------------+------------------------+------------+------+
| a71b3f0c-9178-11ea-86f7-f430b9cbe870 | deployment          | Unnamed NixOps network |          0 |      |
| bc593b42-9181-11ea-8e03-f430b9cbe870 | old-deployment-name | Unnamed NixOps network |          0 |      |
+--------------------------------------+---------------------+------------------------+------------+------+

Check the nix expressions and path of the deployment "old-deployment-name"

$ nixops info -d old-deployment-name
Network name: old-deployment-name
Network UUID: bc593b42-9181-11ea-8e03-f430b9cbe870
Network description: Unnamed NixOps network
Nix expressions: /examples/network.nix
Nix path: -I keys=/data/keys
Nix arguments: token = "<keys/token>"

+-------------------------+---------+-------------------+-------------+------------+
| Name                    |  Status | Type              | Resource Id | IP address |
+-------------------------+---------+-------------------+-------------+------------+
| first-sample-dashboard  | Missing | grafana-dashboard |             |            |
| parent-folder           | Missing | grafana-folder    |             |            |
+-------------------------+---------+-------------------+-------------+------------+

Modify that deployment while specifying all nix inputs

nixops modify -d bc593b42-9181-11ea-8e03-f430b9cbe870  \
                       /examples/network.nix           \
                      -I keys=/data/keys               \
                      -n new-deployment-name
$ nixops list
+--------------------------------------+---------------------+------------------------+------------+------+
| UUID                                 | Name                | Description            | # Machines | Type |
+--------------------------------------+---------------------+------------------------+------------+------+
| a71b3f0c-9178-11ea-86f7-f430b9cbe870 | deployment          | Unnamed NixOps network |          0 |      |
| bc593b42-9181-11ea-8e03-f430b9cbe870 | new-deployment-name | Unnamed NixOps network |          0 |      |
+--------------------------------------+---------------------+------------------------+------------+------+
deepfire commented 4 years ago

Thank you a lot, @tewfik-ghariani, that works indeed!