@@ -2038,3 +2038,43 @@ async def vm_current_state(self):
20382038 "power_state" : self .dest .get_power_state (),
20392039 }
20402040 return " " .join ("{}={}" .format (k , v ) for k , v in state .items ())
2041+
2042+ @qubes .api .method (
2043+ "admin.vm.notes.Get" , no_payload = True , scope = "local" , read = True
2044+ )
2045+ async def vm_notes_get (self ):
2046+ """Get qube notes"""
2047+ self .enforce (self .dest .name != "dom0" )
2048+ self .fire_event_for_permission ()
2049+ try :
2050+ notes = self .dest .get_notes ()
2051+ except Exception as e :
2052+ raise qubes .exc .QubesException (
2053+ "Could not read qube notes: " + str (e )
2054+ )
2055+ return notes
2056+
2057+ @qubes .api .method ("admin.vm.notes.Set" , scope = "local" , write = True )
2058+ async def vm_notes_set (self , untrusted_payload ):
2059+ """Set qube notes"""
2060+ self .enforce (self .dest .name != "dom0" )
2061+ self .fire_event_for_permission ()
2062+ if len (untrusted_payload ) > 256000 :
2063+ raise qubes .exc .ProtocolError (
2064+ "Maximum note size is 256000 bytes ({} bytes received)" .format (
2065+ len (untrusted_payload )
2066+ )
2067+ )
2068+ allowed_chars = string .printable
2069+ notes = "" .join (
2070+ [
2071+ c if c in allowed_chars else "_"
2072+ for c in untrusted_payload .decode ("ascii" )
2073+ ]
2074+ )
2075+ try :
2076+ self .dest .set_notes (notes )
2077+ except Exception as e :
2078+ raise qubes .exc .QubesException (
2079+ "Could not write qube notes: " + str (e )
2080+ )
0 commit comments