mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
feat(instances): a new VM can get a cloud-init seed with its hostname and SSH keys
Cloud images read their first-boot settings with cloud-init. The panel served them only over HTTP, which a VM reaches only with the network and a reverse DNS name for its address. A new VM can now carry them itself: Cloud-init seed (Advanced) on the create form, or cloud_init in the API. The job writes a NoCloud seed, an ISO labelled cidata, into the disk's directory pool as cidata-<uuid>.iso and puts it in the VM's CD-ROM drive. Its meta-data holds the VM's UUID as instance-id and its name as hostname, written as JSON so a VM named 123 or yes keeps a string hostname; its user-data is what the HTTP datasource serves, with the creating user's SSH keys. The ISO is built with pycdlib and written through a libvirt stream, as the NVRAM copy is, now one helper for both. A seed needs a CD-ROM bus and a directory pool, else the create is refused. A failed create deletes the seed with the new disk, recovery names one left behind, and deleting the VM with its disks deletes its seed, found in the pools by name even when ejected. A clone's drive is left empty: the seed is the source VM's identity.
This commit is contained in:
parent
890d82f44a
commit
f004552148
13 changed files with 352 additions and 20 deletions
|
|
@ -76,6 +76,16 @@ class CreateFormInputTests(TestCase):
|
|||
self.assertRedirects(response, reverse("instances", args=[compute.id]), fetch_redirect_response=False)
|
||||
self.assertEqual(Operation.objects.get().kind, "instance.create")
|
||||
|
||||
def test_the_cloud_init_seed_is_chosen_on_the_form(self):
|
||||
_, response = render_create_page(self)
|
||||
(box,) = html.fromstring(response.content).xpath("//input[@name='cloud_init']")
|
||||
self.assertIsNone(box.get("checked"))
|
||||
# the test driver has no CD-ROM bus to pass the job's checks: what the form hands over
|
||||
queued = Operation(pk=1, params={"machine": "pc"})
|
||||
with patch("instances.views.jobs.submit", return_value=queued) as submit:
|
||||
render_create_page(self, valid(disk_source="new", hdd_size="10", storage="default-pool", cloud_init="true"))
|
||||
self.assertIs(submit.call_args.args[2]["cloud_init"], True)
|
||||
|
||||
def test_two_disk_sources_are_refused(self):
|
||||
# the page sends only the chosen source; a crafted request with two queues nothing
|
||||
_, response = render_create_page(self, valid(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue