@@ -552,25 +552,25 @@ def __init__(self, backend_domain, devclass, ident, **kwargs):
552
552
class DeviceAssignment (Device ):
553
553
""" Maps a device to a frontend_domain. """
554
554
555
- def __init__ (self , backend_domain , ident , options = None , persistent = False ,
555
+ def __init__ (self , backend_domain , ident , options = None ,
556
556
frontend_domain = None , devclass = None ,
557
557
required = False , attach_automatically = False ):
558
558
super ().__init__ (backend_domain , ident , devclass )
559
559
self .__options = options or {}
560
- self .persistent = persistent
561
560
self .__required = required
562
561
self .__attach_automatically = attach_automatically
563
562
self .__frontend_domain = frontend_domain
564
563
565
564
def clone (self ):
566
565
"""Clone object instance"""
567
566
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 ,
574
574
)
575
575
576
576
@property
@@ -595,28 +595,24 @@ def required(self) -> bool:
595
595
"""
596
596
Is the presence of this device required for the domain to start? If yes,
597
597
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
600
598
"""
601
- return self .persistent # TODO
599
+ return self .__required
602
600
603
601
@required .setter
604
602
def required (self , required : bool ):
605
- self .persistent = required # TODO
603
+ self .__required = required
606
604
607
605
@property
608
606
def attach_automatically (self ) -> bool :
609
607
"""
610
608
Should this device automatically connect to the frontend domain when
611
609
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
614
610
"""
615
- return self .persistent # TODO
611
+ return self .__attach_automatically
616
612
617
613
@attach_automatically .setter
618
614
def attach_automatically (self , attach_automatically : bool ):
619
- self .persistent = attach_automatically # TODO
615
+ self .__attach_automatically = attach_automatically
620
616
621
617
@property
622
618
def options (self ) -> Dict [str , Any ]:
@@ -663,8 +659,10 @@ def attach(self, device_assignment):
663
659
f"{ device_assignment .devclass = } !={ self ._class = } " )
664
660
665
661
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'
668
666
options_str = ' ' .join ('{}={}' .format (opt , val )
669
667
for opt , val in sorted (options .items ()))
670
668
self ._vm .qubesd_call (None ,
@@ -698,16 +696,17 @@ def detach(self, device_assignment):
698
696
device_assignment .backend_domain ,
699
697
device_assignment .ident ))
700
698
701
- def assignments (self , persistent = None ):
699
+ def assignments (self , required = None ):
702
700
"""List assignments for devices which are (or may be) attached to the
703
701
vm.
704
702
703
+ # TODO: handle auto-attach
705
704
Devices may be attached persistently (so they are included in
706
705
:file:`qubes.xml`) or not. Device can also be in :file:`qubes.xml`,
707
706
but be temporarily detached.
708
707
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 .
711
710
"""
712
711
713
712
assignments_str = self ._vm .qubesd_call (None ,
@@ -719,28 +718,28 @@ def assignments(self, persistent=None):
719
718
options = dict (opt_single .split ('=' , 1 )
720
719
for opt_single in options_all .split (' ' ) if
721
720
opt_single )
722
- dev_persistent = (options .pop ('persistent ' , False ) in
721
+ dev_required = (options .pop ('required ' , False ) in
723
722
['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 :
725
726
continue
726
727
backend_domain = self ._vm .app .domains .get_blind (backend_domain )
727
728
yield DeviceAssignment (backend_domain , ident , options ,
728
- persistent = dev_persistent ,
729
+ required = dev_required ,
729
730
frontend_domain = self ._vm ,
730
731
devclass = self ._class )
731
732
732
733
def attached (self ):
733
734
"""List devices which are (or may be) attached to this vm """
734
-
735
735
for assignment in self .assignments ():
736
736
yield assignment .device
737
737
738
- def persistent (self ):
738
+ def required (self ):
739
739
""" Devices persistently attached and safe to access before libvirt
740
740
bootstrap.
741
741
"""
742
-
743
- for assignment in self .assignments (True ):
742
+ for assignment in self .assignments (required = True ):
744
743
yield assignment .device
745
744
746
745
def available (self ):
@@ -754,19 +753,19 @@ def available(self):
754
753
expected_devclass = self ._class ,
755
754
)
756
755
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.
759
758
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
762
761
"""
763
762
764
763
self ._vm .qubesd_call (None ,
765
764
'admin.vm.device.{}.Set.persistent' .format (
766
765
self ._class ),
767
766
'{!s}+{!s}' .format (device .backend_domain ,
768
767
device .ident ),
769
- str (persistent ).encode ('utf-8' ))
768
+ str (required ).encode ('utf-8' ))
770
769
771
770
__iter__ = available
772
771
0 commit comments