2013-09-18 17:29:28 +04:00
#
2013-10-28 00:59:47 +04:00
# Copyright 2013 Red Hat, Inc.
2013-09-18 17:29:28 +04:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-09-18 17:29:28 +04:00
2018-03-20 19:18:35 +03:00
from . device import Device
2018-03-20 19:27:37 +03:00
from . . xmlbuilder import XMLProperty
2013-09-18 17:29:28 +04:00
2018-03-20 19:18:35 +03:00
class DeviceRng ( Device ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " rng "
2013-09-18 17:29:28 +04:00
TYPE_RANDOM = " random "
TYPE_EGD = " egd "
BACKEND_TYPE_UDP = " udp "
BACKEND_TYPE_TCP = " tcp "
BACKEND_MODE_BIND = " bind "
BACKEND_MODE_CONNECT = " connect "
@staticmethod
def get_pretty_type ( rng_type ) :
2018-03-20 19:18:35 +03:00
if rng_type == DeviceRng . TYPE_RANDOM :
2013-09-18 17:29:28 +04:00
return _ ( " Random " )
2018-03-20 19:18:35 +03:00
if rng_type == DeviceRng . TYPE_EGD :
2013-09-18 17:29:28 +04:00
return _ ( " Entropy Gathering Daemon " )
return rng_type
@staticmethod
def get_pretty_backend_type ( backend_type ) :
2017-08-05 09:39:32 +03:00
return { " udp " : " UDP " ,
2013-09-18 17:29:28 +04:00
" tcp " : " TCP " } . get ( backend_type ) or backend_type
@staticmethod
def get_pretty_mode ( mode ) :
2017-08-05 09:39:32 +03:00
return { " bind " : _ ( " Bind " ) ,
2016-02-05 18:18:16 +03:00
" connect " : _ ( " Connect " ) } . get ( mode ) or mode
2013-09-18 17:29:28 +04:00
def supports_property ( self , propname ) :
"""
Whether the rng dev type supports the passed property name
"""
users = {
2017-08-05 09:39:32 +03:00
" type " : [ self . TYPE_EGD , self . TYPE_RANDOM ] ,
" model " : [ self . TYPE_EGD , self . TYPE_RANDOM ] ,
" bind_host " : [ self . TYPE_EGD ] ,
" bind_service " : [ self . TYPE_EGD ] ,
" connect_host " : [ self . TYPE_EGD ] ,
" connect_service " : [ self . TYPE_EGD ] ,
" backend_type " : [ self . TYPE_EGD ] ,
" device " : [ self . TYPE_RANDOM ] ,
" rate_bytes " : [ self . TYPE_EGD , self . TYPE_RANDOM ] ,
" rate_period " : [ self . TYPE_EGD , self . TYPE_RANDOM ] ,
2013-09-18 17:29:28 +04:00
}
if users . get ( propname ) :
return self . type in users [ propname ]
return hasattr ( self , propname )
2015-09-06 00:20:43 +03:00
type = XMLProperty ( " ./backend/@model " )
2018-09-02 02:58:24 +03:00
model = XMLProperty ( " ./@model " )
2013-09-18 17:29:28 +04:00
2015-09-06 00:20:43 +03:00
backend_type = XMLProperty ( " ./backend/@type " )
2013-10-25 19:13:26 +04:00
2018-09-03 23:18:03 +03:00
bind_host = XMLProperty ( " ./backend/source[@mode= ' bind ' ]/@host " )
bind_service = XMLProperty ( " ./backend/source[@mode= ' bind ' ]/@service " )
2013-10-25 19:13:26 +04:00
2018-09-03 23:18:03 +03:00
connect_host = XMLProperty ( " ./backend/source[@mode= ' connect ' ]/@host " )
connect_service = XMLProperty ( " ./backend/source[@mode= ' connect ' ]/@service " )
2013-09-18 17:29:28 +04:00
2015-09-06 00:20:43 +03:00
rate_bytes = XMLProperty ( " ./rate/@bytes " )
rate_period = XMLProperty ( " ./rate/@period " )
2013-09-18 17:29:28 +04:00
2017-03-09 01:48:26 +03:00
device = XMLProperty ( " ./backend[@model= ' random ' ] " )
2018-09-02 02:58:24 +03:00
##################
# Default config #
##################
def set_defaults ( self , guest ) :
if not self . model :
self . model = " virtio "