From 32034db4a30605577202f855969bd0f887246063 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 5 Oct 2023 13:10:21 -0700 Subject: [PATCH] Update ip_addresses to match new format in sync (#264) * Update ip_addresses to hash format * Add nix flake support --- unix/.envrc | 1 + unix/flake.lock | 27 ++++++++++++++++++ unix/flake.nix | 46 ++++++++++++++++++++++++++++++ unix/src/machine_stats/__init__.py | 4 +++ 4 files changed, 78 insertions(+) create mode 100644 unix/.envrc create mode 100644 unix/flake.lock create mode 100644 unix/flake.nix diff --git a/unix/.envrc b/unix/.envrc new file mode 100644 index 0000000..ff5954f --- /dev/null +++ b/unix/.envrc @@ -0,0 +1 @@ +use flake . --impure \ No newline at end of file diff --git a/unix/flake.lock b/unix/flake.lock new file mode 100644 index 0000000..236fa28 --- /dev/null +++ b/unix/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1696419054, + "narHash": "sha256-EdR+dIKCfqL3voZUDYwcvgRDOektQB9KbhBVcE0/3Mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7131f3c223a2d799568e4b278380cd9dac2b8579", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/unix/flake.nix b/unix/flake.nix new file mode 100644 index 0000000..44878b6 --- /dev/null +++ b/unix/flake.nix @@ -0,0 +1,46 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in + { + devShells = forAllSystems (system: { + default = pkgs.${system}.mkShellNoCC { + venvDir = "./.venv"; + buildInputs = with pkgs.${system}; [ + # A Python interpreter including the 'venv' module is required to bootstrap + # the environment. + python3Packages.python + + # This execute some shell code to initialize a venv in $venvDir before + # dropping into the shell + python3Packages.venvShellHook + python3Packages.python-lsp-server + # In this particular example, in order to compile any binary extensions they may + # require, the Python modules listed in the hypothetical requirements.txt need + # the following packages to be installed locally: + python3Packages.wheel + python3Packages.setuptools + libvirt + ]; + + # Run this command, only after creating the virtual environment + postVenvCreation = '' + unset SOURCE_DATE_EPOCH + pip install -r ./requirements.txt + ''; + + # Now we can execute any commands within the virtual environment. + # This is optional and can be left out to run pip manually. + postShellHook = '' + # allow pip to install wheels + unset SOURCE_DATE_EPOCH + ''; + }; + }); + }; +} diff --git a/unix/src/machine_stats/__init__.py b/unix/src/machine_stats/__init__.py index 589fca9..3244e83 100644 --- a/unix/src/machine_stats/__init__.py +++ b/unix/src/machine_stats/__init__.py @@ -155,6 +155,10 @@ def cpu_name(proc): return proc[2] return "Unknown" +def ip_addresses(facts): + """Return IP addresses formatted for the tidal API""" + return list(map(lambda ip: {"address": ip}, + facts["ansible_all_ipv4_addresses"] + facts["ansible_all_ipv6_addresses"])) class ResultCallback(CallbackBase): """A sample callback plugin used for performing an action as results come in