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.78k stars 365 forks source link

`nixops info` throws exception when no deployment exists #1395

Open andir opened 3 years ago

andir commented 3 years ago

Just started playing around with the current master branch of NixOps and ran into the following:

$ rm -rf ~/.nixops/

$ nixops info
Traceback (most recent call last):
  File "/nix/store/z5zgipf9x7xvl7jn1v1dc9mv815pgrnk-python3.8-nixops-2.0.0/bin/.nixops-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/ma7v0jcn82c4ymabn2gvdadyqm6vahvh-python3-3.8.5-env/lib/python3.8/site-packages/nixops/__main__.py", line 710, in main
    args.op(args)
  File "/nix/store/ma7v0jcn82c4ymabn2gvdadyqm6vahvh-python3-3.8.5-env/lib/python3.8/site-packages/nixops/script_defs.py", line 337, in op_info
    with deployment(args) as depl:
  File "/nix/store/fjgnz0xfl04hsblsi4ym5y5akfh6mlmy-python3-3.8.5/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/nix/store/ma7v0jcn82c4ymabn2gvdadyqm6vahvh-python3-3.8.5-env/lib/python3.8/site-packages/nixops/script_defs.py", line 37, in deployment
    depl = open_deployment(sf, args)
  File "/nix/store/ma7v0jcn82c4ymabn2gvdadyqm6vahvh-python3-3.8.5-env/lib/python3.8/site-packages/nixops/script_defs.py", line 117, in open_deployment
    depl = sf.open_deployment(uuid=args.deployment)
  File "/nix/store/ma7v0jcn82c4ymabn2gvdadyqm6vahvh-python3-3.8.5-env/lib/python3.8/site-packages/nixops/statefile.py", line 197, in open_deployment
    raise Exception(
Exception: could not find specified deployment in state file ‘/home/andi//.nixops/deployments.nixops’

$ ls -la ~/.nixops
total 62
drwx------   2 andi users     3 Sep  4 16:43 .
drwx------ 147 andi users   473 Sep  4 16:43 ..
-rw-------   1 andi users 40960 Sep  4 16:43 deployments.nixops

Not sure if that is the intended behavior but it doesn't look good as a first time experience.

tewfik-ghariani commented 3 years ago

To view the list of existing deployments, the first step would be to run nixops list

Example

$ nixops list
+--------------------------------------+----------------+----------------------------------+------------+------+
| UUID                                 | Name           | Description                      | # Machines | Type |
+--------------------------------------+----------------+----------------------------------+------------+------+
| c381a5ee-bfb5-11ea-91ff-f430b9cbe870 | digital-ocean  | Unnamed NixOps network           |          0 |      |
| a71b3f0c-9178-11ea-86f7-f430b9cbe870 | grafana-test   | Grafana Dashboard Example        |          0 |      |
| 0412ff9a-2dad-11eb-8fed-dd571b16a7af | rds-snapshot   | NixOps RDS Testing               |          0 |      |
| 3482ba64-a389-11ea-9274-f430b9cbe870 | test-aws       | Test AWS instance                |          0 |      |
| 5ffb7db8-a275-11ea-a860-f430b9cbe870 | test-gcp       | trivial GCP example              |          0 |      |
| 94ce856e-3e32-11eb-9133-378af37e2168 | zabbix         | Zabbix    NixOS                  |          0 |      |
+--------------------------------------+----------------+----------------------------------+------------+------+

You can then select a deployment to view its info with the -d flag

$ nixops info -d test-gcp
Network name: test-gcp
Network UUID: 5ffb7db8-a275-11ea-a860-f430b9cbe870
Network description: trivial GCP example
Nix expressions: /home/tewfikghariani/repositories/nix-community/nixops-gce-master/examples/machine-with-disk.nix
Nix arguments: description = "trivial GCP example", gcpProject = "operations", accessKey = /data/keys/gce.pem

+-----------------+---------+-----------------------+-------------+------------+
| Name            |  Status | Type                  | Resource Id | IP address |
+-----------------+---------+-----------------------+-------------+------------+
| frontend        | Missing | gce [us-east1-b]      |             |            |
| frontend-volume | Missing | gce-disk [us-east1-b] |             |            |
+-----------------+---------+-----------------------+-------------+------------+

To create a new deployment, you can use the create command

nixops create -d new-deployment /home/network.nix

With "network.nix" being the main file for the physical and logical architecture of your deployment