@@ -552,25 +552,25 @@ def __init__(self, backend_domain, devclass, ident, **kwargs):
552552class DeviceAssignment (Device ):
553553 """ Maps a device to a frontend_domain. """
554554
555- def __init__ (self , backend_domain , ident , options = None , persistent = False ,
555+ def __init__ (self , backend_domain , ident , options = None ,
556556 frontend_domain = None , devclass = None ,
557557 required = False , attach_automatically = False ):
558558 super ().__init__ (backend_domain , ident , devclass )
559559 self .__options = options or {}
560- self .persistent = persistent
561560 self .__required = required
562561 self .__attach_automatically = attach_automatically
563562 self .__frontend_domain = frontend_domain
564563
565564 def clone (self ):
566565 """Clone object instance"""
567566 return self .__class__ (
568- self .backend_domain ,
569- self .ident ,
570- self .options ,
571- self .persistent ,
572- self .frontend_domain ,
573- self .devclass ,
567+ backend_domain = self .backend_domain ,
568+ ident = self .ident ,
569+ options = self .options ,
570+ required = self .required ,
571+ attach_automatically = self .attach_automatically ,
572+ frontend_domain = self .frontend_domain ,
573+ devclass = self .devclass ,
574574 )
575575
576576 @property
@@ -595,28 +595,24 @@ def required(self) -> bool:
595595 """
596596 Is the presence of this device required for the domain to start? If yes,
597597 it will be attached automatically.
598- TODO: this possibly should not be available for usb device? or always False?
599- TODO: this is a reworking of the previously existing "persistent" attachment, split in two option
600598 """
601- return self .persistent # TODO
599+ return self .__required
602600
603601 @required .setter
604602 def required (self , required : bool ):
605- self .persistent = required # TODO
603+ self .__required = required
606604
607605 @property
608606 def attach_automatically (self ) -> bool :
609607 """
610608 Should this device automatically connect to the frontend domain when
611609 available and not connected to other qubes?
612- TODO: this possibly should not be available for usb device? or always False?
613- TODO: this is a reworking of the previously existing "persistent" attachment, split in two option
614610 """
615- return self .persistent # TODO
611+ return self .__attach_automatically
616612
617613 @attach_automatically .setter
618614 def attach_automatically (self , attach_automatically : bool ):
619- self .persistent = attach_automatically # TODO
615+ self .__attach_automatically = attach_automatically
620616
621617 @property
622618 def options (self ) -> Dict [str , Any ]:
@@ -663,8 +659,10 @@ def attach(self, device_assignment):
663659 f"{ device_assignment .devclass = } !={ self ._class = } " )
664660
665661 options = device_assignment .options .copy ()
666- if device_assignment .persistent :
667- options ['persistent' ] = 'True'
662+ if device_assignment .required :
663+ options ['required' ] = 'True'
664+ # if device_assignment.attach_automatically:
665+ # options['attach_automatically'] = 'True'
668666 options_str = ' ' .join ('{}={}' .format (opt , val )
669667 for opt , val in sorted (options .items ()))
670668 self ._vm .qubesd_call (None ,
@@ -698,16 +696,17 @@ def detach(self, device_assignment):
698696 device_assignment .backend_domain ,
699697 device_assignment .ident ))
700698
701- def assignments (self , persistent = None ):
699+ def assignments (self , required = None ):
702700 """List assignments for devices which are (or may be) attached to the
703701 vm.
704702
703+ # TODO: handle auto-attach
705704 Devices may be attached persistently (so they are included in
706705 :file:`qubes.xml`) or not. Device can also be in :file:`qubes.xml`,
707706 but be temporarily detached.
708707
709- :param bool persistent : only include devices which are or are not
710- attached persistently .
708+ :param bool required : only include devices which are or are not
709+ required to start qube .
711710 """
712711
713712 assignments_str = self ._vm .qubesd_call (None ,
@@ -719,28 +718,28 @@ def assignments(self, persistent=None):
719718 options = dict (opt_single .split ('=' , 1 )
720719 for opt_single in options_all .split (' ' ) if
721720 opt_single )
722- dev_persistent = (options .pop ('persistent ' , False ) in
721+ dev_required = (options .pop ('required ' , False ) in
723722 ['True' , 'yes' , True ])
724- if persistent is not None and dev_persistent != persistent :
723+ dev_auto_attach = (options .pop ('attach_automatically' , False ) in
724+ ['True' , 'yes' , True ]) # TODO
725+ if required is not None and dev_required != required :
725726 continue
726727 backend_domain = self ._vm .app .domains .get_blind (backend_domain )
727728 yield DeviceAssignment (backend_domain , ident , options ,
728- persistent = dev_persistent ,
729+ required = dev_required ,
729730 frontend_domain = self ._vm ,
730731 devclass = self ._class )
731732
732733 def attached (self ):
733734 """List devices which are (or may be) attached to this vm """
734-
735735 for assignment in self .assignments ():
736736 yield assignment .device
737737
738- def persistent (self ):
738+ def required (self ):
739739 """ Devices persistently attached and safe to access before libvirt
740740 bootstrap.
741741 """
742-
743- for assignment in self .assignments (True ):
742+ for assignment in self .assignments (required = True ):
744743 yield assignment .device
745744
746745 def available (self ):
@@ -754,19 +753,19 @@ def available(self):
754753 expected_devclass = self ._class ,
755754 )
756755
757- def update_persistent (self , device , persistent ):
758- """Update `persistent ` flag of already attached device.
756+ def update_required (self , device : DeviceInfo , required : bool ): # TODO: update auto-attach
757+ """Update `required ` flag of already attached device.
759758
760- :param DeviceInfo device: device for which change persistent flag
761- :param bool persistent : new persistent flag
759+ :param DeviceInfo device: device for which change required flag
760+ :param bool required : new required flag
762761 """
763762
764763 self ._vm .qubesd_call (None ,
765764 'admin.vm.device.{}.Set.persistent' .format (
766765 self ._class ),
767766 '{!s}+{!s}' .format (device .backend_domain ,
768767 device .ident ),
769- str (persistent ).encode ('utf-8' ))
768+ str (required ).encode ('utf-8' ))
770769
771770 __iter__ = available
772771
0 commit comments