[Kimchi-devel] [PATCH][Kimchi 1/5] Create method to change bootorder of a guest

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Wed Jun 8 20:32:11 UTC 2016



On 06/08/2016 05:12 PM, Aline Manera wrote:
>
>
> On 06/07/2016 09:52 AM, Rodrigo Trujillo wrote:
>>
>>
>> On 06/06/2016 06:13 PM, Ramon Medeiros wrote:
>>> Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
>>> ---
>>>   model/vms.py | 34 +++++++++++++++++++++++++++++++++-
>>>   1 file changed, 33 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/model/vms.py b/model/vms.py
>>> index b0b4eb2..854cd04 100644
>>> --- a/model/vms.py
>>> +++ b/model/vms.py
>>> @@ -81,7 +81,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 
>>> 'memory', 'users']
>>>
>>>   # update parameters which are updatable when the VM is offline
>>>   VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 
>>> 'memory',
>>> -                            'name', 'users']
>>> +                            'name', 'users', 'boot']
>>>
>>>   XPATH_DOMAIN_DISK = 
>>> "/domain/devices/disk[@device='disk']/source/@file"
>>>   XPATH_DOMAIN_DISK_BY_FILE = 
>>> "./devices/disk[@device='disk']/source[@file='%s']"
>>> @@ -736,6 +736,34 @@ class VMModel(object):
>>>           else:
>>>               remove_metadata_node(dom, 'name')
>>>
>>> +    def _update_bootorder(self, xml, params):
>>> +        # get element tree from xml
>>> +        et = ET.fromstring(xml)
>>> +
>>> +        # get machine type
>>> +        os = et.find("os")
>>> +        mtype = os.find("type")
>>> +
>>> +        # create new element tree with new bootorder
>>> +        new_os = E.os()
>>> +        new_os.append(mtype)
>>> +
>>> +        # iterate over new bootorder and build tag
>>> +        for device in params["order"]:
>>> +
>>> +            # skip devices not in list
>>> +            if device not in ["hd", "cdrom", "network", "fd"]:
>> I would move this checking to the JSON schema, you can use ENUM for 
>> this.
>> Also add the names to the messages, so user can know what to change.
>
> +1
>
> Also move all the XML building to /xmlutils. Create a new file there 
> to work with <boot> tag.
I don't agree with this ... the xml manipulation is so simple and not 
reusable to demand a new file.

>
>>> +                continue
>>> +
>>> +            # add bootdevice
>>> +            new_os.append(E.boot(dev=device))
>>> +
>>> +        # update <os>
>>> +        et.remove(os)
>>> +        et.append(new_os)
>>> +
>>> +        return ET.tostring(et)
>>> +
>>>       def _static_vm_update(self, vm_name, dom, params):
>>>           old_xml = new_xml = 
>>> dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE)
>>>           params = copy.deepcopy(params)
>>> @@ -782,6 +810,10 @@ class VMModel(object):
>>>           if ('memory' in params and params['memory'] != {}):
>>>               new_xml = self._update_memory_config(new_xml, params, 
>>> dom)
>>>
>>> +        # update bootorder
>>> +        if "boot" in params:
>>> +            new_xml = self._update_bootorder(new_xml, params["boot"])
>>> +
>>>           snapshots_info = []
>>>           conn = self.conn.get()
>>>           try:
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>




More information about the Kimchi-devel mailing list