[PATCH V3] [Kimchi 0/3] Issue #372: Add support to netboot installation.

From: Paulo Vital <pvital@linux.vnet.ibm.com> V3: * set network as third default option to boot order V2: * Adapted patch to new template API (automatic detection of cdrom) V1: This patchset adds support in backend to create templates and guests to netboot without setting a cdrom path or URL as image to install. Once created a guest to boot via network, the guest will request DHCP/TFTP/(NFS/HTTP/FTP) network installation servers to download the configured images and start the install. Reference: http://miud.in/1Ht3 To test, use the curl commands (look the parameters used): $ curl -k -u test -H "Content-Type: application/json" -H \ "Accept: application/json" 'https://localhost:8001/plugins/kimchi/templates' \ -X POST -d '{"name": "test-netboot", "source_media": "netboot"}' Enter host password for user 'test': { "cpu_info":{ "maxvcpus":1, "vcpus":1 }, "graphics":{ "type":"vnc", "listen":"127.0.0.1" }, "cdrom":null, "networks":[ "default" ], "icon":"plugins/kimchi/images/icon-vm.png", "os_distro":"unknown", "name":"test-netboot", "disks":[ { "index":0, "format":"qcow2", "pool":{ "type":"dir", "name":"/plugins/kimchi/storagepools/default" }, "size":10 } ], "invalid":{}, "os_version":"unknown", "memory":{ "current":1024, "maxmemory":1024 }, "folder":[] } $ curl -k -u test -H "Content-Type: application/json" -H \ "Accept: application/json" 'https://localhost:8001/plugins/kimchi/vms' -X POST \ -d '{"name":"1netboot-test","template":"/plugins/kimchi/templates/test-netboot"}' Enter host password for user 'test': { "status":"running", "message":"Provisioning storages for new VM", "id":"1", "target_uri":"/plugins/kimchi/vms/1netboot-test" } $ sudo virsh dumpxml 1netboot-test <domain type='kvm'> <name>1netboot-test</name> <uuid>5c9fa5b3-3203-4c93-92d6-2b4103fe7b40</uuid> <metadata> <kimchi:metadata xmlns:kimchi="https://github.com/kimchi-project/kimchi"> <kimchi:os version="unknown" distro="unknown"/> </kimchi:metadata> </metadata> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> <memtune> <hard_limit unit='KiB'>2097152</hard_limit> </memtune> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc-i440fx-2.4'>hvm</type> <boot dev='hd'/> <boot dev='cdrom'/> <boot dev='network'/> </os> <acpi/> <apic/> <pae/> </features> <cpu> <numa> <cell id='0' cpus='0' memory='1048576' unit='KiB'/> </numa> </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/var/lib/libvirt/images/5c9fa5b3-3203-4c93-92d6-2b4103fe7b40-0.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='pci' index='0' model='pci-root'/> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='network'> <mac address='52:54:00:ea:7e:ad'/> <source network='default'/> <model type='e1000'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'> <listen type='address' address='127.0.0.1'/> </graphics> <sound model='ich6'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </sound> <video> <model type='cirrus' vram='16384' heads='1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </memballoon> </devices> </domain> Paulo Vital (3): Add support to create netboot templates. Add support to create guests to netboot. Update test cases to support netboot. API.json | 4 ++-- model/templates.py | 11 ++++++++++- tests/test_template.py | 17 +++++++++++++++++ tests/test_vmtemplate.py | 18 ++++++++++++++++++ vmtemplate.py | 22 ++++++++++++---------- 5 files changed, 59 insertions(+), 13 deletions(-) -- 2.5.5

From: Paulo Vital <pvital@linux.vnet.ibm.com> Changed API.json and model to accept 'netboot' as source media parameter while creating a new template. Now, when creating a new template and specifying 'netboot' as source media parameter, it is assumed the template will use netboot process - PXE/DHCP/TFTP/(NFS/HTTP/FTP). This is part of solution to Issue #372. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- API.json | 4 ++-- model/templates.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/API.json b/API.json index ff505b1..2926620 100644 --- a/API.json +++ b/API.json @@ -469,9 +469,9 @@ }, "memory": { "$ref": "#/kimchitype/memory" }, "source_media": { - "description": "Path for installation media (ISO, disk, remote ISO)", + "description": "Path for installation media (ISO, disk, remote ISO) or netboot", "type" : "string", - "pattern" : "^((/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$", + "pattern" : "^((/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$|(netboot)", "required": true }, "disks": { diff --git a/model/templates.py b/model/templates.py index a02099c..043fe49 100644 --- a/model/templates.py +++ b/model/templates.py @@ -65,6 +65,12 @@ class TemplatesModel(object): # get source_media path = params.pop("source_media") + # Check if source_media is 'netboot' + if path == 'netboot': + params['os_distro'] = 'unknown' + params['os_version'] = 'unknown' + return self.save_template(params) + # not local image: set as remote ISO if urlparse.urlparse(path).scheme in ["http", "https", "tftp", "ftp", "ftps"]: @@ -104,7 +110,10 @@ class TemplatesModel(object): def save_template(self, params): # Creates the template class with necessary information - t = LibvirtVMTemplate(params, scan=True, conn=self.conn) + if 'cdrom' not in params.keys(): + t = LibvirtVMTemplate(params, conn=self.conn) + else: + t = LibvirtVMTemplate(params, scan=True, conn=self.conn) # Validate cpu info t.cpuinfo_validate() -- 2.5.5

From: Paulo Vital <pvital@linux.vnet.ibm.com> Add support to create guests without CD-ROM device information and setting the second boot order option as 'netboot'. This is part of solution to Issue #372. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- vmtemplate.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/vmtemplate.py b/vmtemplate.py index a223beb..2639468 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -33,6 +33,7 @@ from wok.plugins.kimchi import imageinfo from wok.plugins.kimchi import osinfo from wok.plugins.kimchi.isoinfo import IsoImage from wok.plugins.kimchi.utils import check_url_path, pool_name_from_uri +from wok.plugins.kimchi.xmlutils.bootorder import get_bootorder_xml from wok.plugins.kimchi.xmlutils.cpu import get_cpu_xml from wok.plugins.kimchi.xmlutils.disk import get_disk_xml from wok.plugins.kimchi.xmlutils.graphics import get_graphics_xml @@ -146,9 +147,6 @@ class VMTemplate(object): d_info = imageinfo.probe_img_info(d['base']) d['size'] = d_info['virtual-size'] - if len(base_imgs) == 0: - raise MissingParameter("KCHTMPL0016E") - return distro, version def _gen_name(self, distro, version): @@ -170,7 +168,7 @@ class VMTemplate(object): def _get_cdrom_xml(self, libvirt_stream_protocols): if 'cdrom' not in self.info: - return '' + return None params = {} params['type'] = 'cdrom' @@ -350,12 +348,15 @@ class VMTemplate(object): libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', []) cdrom_xml = self._get_cdrom_xml(libvirt_stream_protocols) - if not urlparse.urlparse(self.info.get('cdrom', "")).scheme in \ - libvirt_stream_protocols and \ - params.get('iso_stream', False): - params['qemu-stream-cmdline'] = cdrom_xml - else: - params['cdroms'] = cdrom_xml + # Add information of CD-ROM device only if template have info about it. + # Also, set up correct boot order. + if cdrom_xml is not None: + if not urlparse.urlparse(self.info.get('cdrom', "")).scheme in \ + libvirt_stream_protocols and \ + params.get('iso_stream', False): + params['qemu-stream-cmdline'] = cdrom_xml + else: + params['cdroms'] = cdrom_xml # Setting maximum number of slots to avoid errors when hotplug memory # Number of slots are the numbers of chunks of 1GB that fit inside @@ -411,6 +412,7 @@ class VMTemplate(object): <type arch='%(arch)s'>hvm</type> <boot dev='hd'/> <boot dev='cdrom'/> + <boot dev='network'/> </os> <features> <acpi/> -- 2.5.5

From: Paulo Vital <pvital@linux.vnet.ibm.com> Update test cases to support the creation of netboot templates and creation of guests without cdrom. This is part of solution to Issue #372. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- tests/test_template.py | 17 +++++++++++++++++ tests/test_vmtemplate.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/test_template.py b/tests/test_template.py index 158bbeb..b9bb216 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -80,6 +80,23 @@ class TemplateTests(unittest.TestCase): resp = self.request('/plugins/kimchi/templates', req, 'POST') self.assertEquals(400, resp.status) + # Create a netboot template + t = {'name': 'test-netboot', 'source_media': 'netboot'} + req = json.dumps(t) + resp = self.request('/plugins/kimchi/templates', req, 'POST') + self.assertEquals(201, resp.status) + + # Verify the netboot template + tmpl = json.loads( + self.request('/plugins/kimchi/templates/test-netboot').read() + ) + self.assertIsNone(tmpl['cdrom']) + + # Delete the netboot template + resp = self.request('/plugins/kimchi/templates/test-netboot', '{}', + 'DELETE') + self.assertEquals(204, resp.status) + # Create a template t = {'name': 'test', 'source_media': MOCK_ISO} req = json.dumps(t) diff --git a/tests/test_vmtemplate.py b/tests/test_vmtemplate.py index 503d34a..92af9e7 100644 --- a/tests/test_vmtemplate.py +++ b/tests/test_vmtemplate.py @@ -135,3 +135,21 @@ class VMTemplateTests(unittest.TestCase): self.assertEquals(['foo'], t.info.get('networks')) self.assertEquals(self.iso, t.info.get('cdrom')) self.assertEquals(graphics, t.info.get('graphics')) + + def test_netboot_vmtemplate(self): + disk_bus = get_template_default('old', 'disk_bus') + memory = get_template_default('old', 'memory') + nic_model = get_template_default('old', 'nic_model') + fields = (('name', 'test'), ('os_distro', 'unknown'), + ('os_version', 'unknown'), + ('cpu_info', {'vcpus': 1, 'maxvcpus': 1}), + ('memory', memory), ('networks', ['default']), + ('disk_bus', disk_bus), ('nic_model', nic_model), + ('graphics', {'type': 'vnc', 'listen': '127.0.0.1'})) + + args = {'name': 'test', 'source_media': 'netboot'} + t = VMTemplate(args) + for name, val in fields: + self.assertEquals(val, t.info.get(name)) + + self.assertNotIn('cdrom', t.info.keys()) -- 2.5.5
participants (1)
-
pvital@linux.vnet.ibm.com