def update_vm_settings(self, vm, settings):
        """
        Updates the VM settings.

        :param vm: VM instance
        :param settings: settings to update (dict)
        """

        for name, value in settings.items():
            if hasattr(vm, name) and getattr(vm, name) != value:
                if hasattr(vm, "set_{}".format(name)):
                    setter = getattr(vm, "set_{}".format(name))
                    yield from setter(value)
            elif name.startswith("slot") and value in ADAPTER_MATRIX:
                slot_id = int(name[-1])
                adapter_name = value
                adapter = ADAPTER_MATRIX[adapter_name]()
                try:
                    if vm.slots[slot_id] and not isinstance(vm.slots[slot_id], type(adapter)):
                        yield from vm.slot_remove_binding(slot_id)
                    if not isinstance(vm.slots[slot_id], type(adapter)):
                        yield from vm.slot_add_binding(slot_id, adapter)
                except IndexError:
                    raise DynamipsError("Slot {} doesn't exist on this router".format(slot_id))
            elif name.startswith("slot") and (value is None or value is ""):
                slot_id = int(name[-1])
                try:
                    if vm.slots[slot_id]:
                        yield from vm.slot_remove_binding(slot_id)
                except IndexError:
                    raise DynamipsError("Slot {} doesn't exist on this router".format(slot_id))
            elif name.startswith("wic") and value in WIC_MATRIX:
                wic_slot_id = int(name[-1])
                wic_name = value
                wic = WIC_MATRIX[wic_name]()
                try:
                    if vm.slots[0].wics[wic_slot_id] and not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
                        yield from vm.uninstall_wic(wic_slot_id)
                    if not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
                        yield from vm.install_wic(wic_slot_id, wic)
                except IndexError:
                    raise DynamipsError("WIC slot {} doesn't exist on this router".format(wic_slot_id))
            elif name.startswith("wic") and (value is None or value is ""):
                wic_slot_id = int(name[-1])
                try:
                    if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]:
                        yield from vm.uninstall_wic(wic_slot_id)
                except IndexError:
                    raise DynamipsError("WIC slot {} doesn't exist on this router".format(wic_slot_id))

        mmap_support = self.config.get_section_config("Dynamips").getboolean("mmap_support", True)
        if mmap_support is False:
            yield from vm.set_mmap(False)

        sparse_memory_support = self.config.get_section_config("Dynamips").getboolean("sparse_memory_support", True)
        if sparse_memory_support is False:
            yield from vm.set_sparsemem(False)

        # update the configs if needed
        yield from self.set_vm_configs(vm, settings)
def update_vm_settings ( self , vm , settings ) : for name , value in settings . items ( ) : if hasattr ( vm , name ) and getattr ( vm , name ) != value : if hasattr ( vm , "set_{}" . format ( name ) ) : setter = getattr ( vm , "set_{}" . format ( name ) ) yield from setter ( value ) elif name . startswith ( "slot" ) and value in ADAPTER_MATRIX : slot_id = int ( name [ - 1 ] ) adapter_name = value adapter = ADAPTER_MATRIX [ adapter_name ] ( ) try : if vm . slots [ slot_id ] and not isinstance ( vm . slots [ slot_id ] , type ( adapter ) ) : yield from vm . slot_remove_binding ( slot_id ) if not isinstance ( vm . slots [ slot_id ] , type ( adapter ) ) : yield from vm . slot_add_binding ( slot_id , adapter ) except IndexError : raise DynamipsError ( "Slot {} doesn't exist on this router" . format ( slot_id ) ) elif name . startswith ( "slot" ) and ( value is None or value is "" ) : slot_id = int ( name [ - 1 ] ) try : if vm . slots [ slot_id ] : yield from vm . slot_remove_binding ( slot_id ) except IndexError : raise DynamipsError ( "Slot {} doesn't exist on this router" . format ( slot_id ) ) elif name . startswith ( "wic" ) and value in WIC_MATRIX : wic_slot_id = int ( name [ - 1 ] ) wic_name = value wic = WIC_MATRIX [ wic_name ] ( ) try : if vm . slots [ 0 ] . wics [ wic_slot_id ] and not isinstance ( vm . slots [ 0 ] . wics [ wic_slot_id ] , type ( wic ) ) : yield from vm . uninstall_wic ( wic_slot_id ) if not isinstance ( vm . slots [ 0 ] . wics [ wic_slot_id ] , type ( wic ) ) : yield from vm . install_wic ( wic_slot_id , wic ) except IndexError : raise DynamipsError ( "WIC slot {} doesn't exist on this router" . format ( wic_slot_id ) ) elif name . startswith ( "wic" ) and ( value is None or value is "" ) : wic_slot_id = int ( name [ - 1 ] ) try : if vm . slots [ 0 ] . wics and vm . slots [ 0 ] . wics [ wic_slot_id ] : yield from vm . uninstall_wic ( wic_slot_id ) except IndexError : raise DynamipsError ( "WIC slot {} doesn't exist on this router" . format ( wic_slot_id ) ) mmap_support = self . config . get_section_config ( "Dynamips" ) . getboolean ( "mmap_support" , True ) if mmap_support is False : yield from vm . set_mmap ( False ) sparse_memory_support = self . config . get_section_config ( "Dynamips" ) . getboolean ( "sparse_memory_support" , True ) if sparse_memory_support is False : yield from vm . set_sparsemem ( False ) yield from self . set_vm_configs ( vm , settings )
Updates the VM settings.

        :param vm: VM instance
        :param settings: settings to update (dict)