Hadron / carthage

Carthage is an Infrastructure as Code (IAC) framework
Other
7 stars 4 forks source link

dump_assignments is a little tricky #42

Open kdienes opened 1 year ago

kdienes commented 1 year ago

Assume my goal is to understand the persistent assignments that are being used by Carthage.

I can find /root/.carthage/state/persistent_assignments/*.mdb

I can install lmdb-utils and run mdb_dump -p /root/.carthage/state/persistent_assignments and get a dump that's not ideal but at least usable

If someone gives me a hint, and I figure out that I need to add add_provider(carthage.kvstore.persistent_seed_path, 'seed.yml') , I can use the dump_assignments command to get a yaml dump of the assignments, I think. It writes it to the file and then I have to read the file, which is a bit awkward but OK. But the file has a lot fewer K/V pairs than there are in the mdb file, which makes me suspicious.

root@radiosim-vm:~/radio-simulation-engine# mdb_dump -p /root/.carthage/state/persistent_assignments
VERSION=3
format=print
type=btree
mapsize=4294967296
maxreaders=126
db_pagesize=4096
HEADER=END
 container_net/v4_pool/assignments:10.20.0.48
 radiosim_pod|eth0
 container_net/v4_pool/assignments:10.20.0.49
 webserver.jeff-sandbox.photon.ac|eth0
 container_net/v4_pool/assignments:10.20.0.84
 keycloak-pod|eth0
 container_net/v4_pool/assignments:10.20.0.96
 photon.jeff-sandbox.photon.ac|eth0
 container_net/v4_pool/assignments:keycloak-pod|eth0
 10.20.0.84
 container_net/v4_pool/assignments:photon.jeff-sandbox.photon.ac|eth0
 10.20.0.96
 container_net/v4_pool/assignments:radiosim_pod|eth0
 10.20.0.48
 container_net/v4_pool/assignments:webserver.jeff-sandbox.photon.ac|eth0
 10.20.0.49
 container_net/v4_pool/hints:keycloak-pod|eth0
 10.20.0.84
 container_net/v4_pool/hints:photon.jeff-sandbox.photon.ac|eth0
 10.20.0.96
 container_net/v4_pool/hints:radiosim_pod|eth0
 10.20.0.48
 container_net/v4_pool/hints:webserver.jeff-sandbox.photon.ac|eth0
 10.20.0.49
 dump:container_net/v4_pool/hints
 true
DATA=END
Task Handle Certificates last run for <carthage_base.aces.AcesIntegration object at 0x7f341c42c9d0> at 2023-05-23T16:57:22.923692
Task make download last run for <carthage_base.aces.AcesIntegration object at 0x7f341c42c9d0> at 2023-05-23T16:57:26.959704
Task Render config.yml.mako template last run for <radiosim_vm model name: radiosim-vm.jeff-sandbox.photon.ac> at 2023-05-23T16:57:26.987705
root@radiosim-vm:~/radio-simulation-engine# ls
README.md  ansible  carthage_plugin.yml  config.yml  container.log  design  engine  radiosim  resources  sample-carthage-config.yml  seed.yml
root@radiosim-vm:~/radio-simulation-engine# cat seed.yml 
container_net/v4_pool/hints:
  radiosim_pod|eth0: 10.20.0.48
  webserver.jeff-sandbox.photon.ac|eth0: 10.20.0.49

I suspect that I want !dump_assignments to be able to dump to stdout even if I don't define persistent_seed_path. I might also want to be able to set it in config.yml?

hartmans commented 1 year ago

So, there are two directions in the assignments database: there is a hint--what would we like to assign, and there is a reservation--what is currently assigned. dump_assignments only dumps out the hint.

The intent of dump_assignments is to allow you to store hints for IP and MAC addresses in a persistent manner so that they can be reused even when the state directory is cleared.

In retrospect I may have incorrectly implied that dump_assignments was intended as a debugging tool. It's great if it helps with that, but that's not its primary purpose.

dump_assignments does take a path argument and you can dump somewhere other than the seed_path.

I'd be happy to figure out a different heuristic for when the command should be registered. I want something efficient to compute (so not going over all the networks in the layout to see if they have pools defined, or use persistent_random_mac), indicating there is a high chance the persistent_assignments is used in the layout. My goal is not to register too many irrelevant commands on a carthage layout so that !help doesn't drown a user in things they think might be useful/apply to their circumstance, but actually do not.

--Sam

kdienes commented 1 year ago

I assume that it's setting webserver and radiosim as persistent because those are the two addresses you might want to have be stable externally, or something along those lines?

I agree that it makes sense for dump_assignments to only exist when you are using dumped assignments. I think a somewhat-generalized K/V dump/inspect command would be helpful, because I know that I'm not going to be the only one who ends up looking at an mdb file trying to figure out why Carthage is picking a particular address. It's a shame that you probably can't put a comment in the mdb file itself, but I wonder if dropping a README.txt into the mdb/ directory would be easy and helpful.

Why is persistent_seed_path only an add_provider() and not a configvar? Is it "because loading persistent state from a file is part of a layout, and we use configvars for environment-specific configuration"?

hartmans commented 1 year ago

"Klee" == Klee Dienes @.***> writes:

Klee> I assume that it's setting webserver and radiosim as
Klee> persistent because those are the two addresses you might want
Klee> to have be stable externally, or something along those lines?

It dumps all addresses that you have assigned through a pool corresponding to models still in the layout. Klee> Why is persistent_seed_path only an add_provider() and not a Klee> configvar? Is it "because loading persistent state from a Klee> file is part of a layout, and we use configvars for Klee> environment-specific configuration"?

More or less, yes. Whether a layout wants its assignments persisted across state directory resets is a property of the layout not the config.