Skip to content

Commit

Permalink
Merge pull request isard-vdi#157 from alarraz/feaure/rewrite_video_co…
Browse files Browse the repository at this point in the history
…pmresion

rewrite video copmresion
  • Loading branch information
jvinolas committed May 15, 2019
2 parents 19be13c + 3240673 commit 9b51f38
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 30 deletions.
6 changes: 3 additions & 3 deletions extras/app-devel/devel-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- "443:443"
networks:
- isard_network
image: isard/nginx:1.1
image: isard/nginx:1
restart: "no"
depends_on:
- isard-app
Expand All @@ -42,7 +42,7 @@ services:
- "55900-55949:55900-55949"
networks:
- isard_network
image: isard/hypervisor:1.1
image: isard/hypervisor:1
privileged: true
################ only for devel ###############
expose:
Expand Down Expand Up @@ -90,7 +90,7 @@ services:
- 3000:3000
networks:
- isard_network
image: isard/grafana:1.1
image: isard/grafana:1
restart: "no"
logging:
driver: none
Expand Down
47 changes: 38 additions & 9 deletions src/engine/models/domain_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from lxml import etree

from engine.services.db import get_dict_from_item_in_table, update_table_field, update_domain_dict_hardware
from engine.services.db import get_interface, get_domain, update_domain_viewer_started_values
from engine.services.db import get_interface, get_domain, update_domain_viewer_started_values, get_graphics_types
from engine.services.db.downloads import get_media
from engine.services.lib.functions import randomMAC
from engine.services.log import *
Expand Down Expand Up @@ -145,6 +145,7 @@ def __init__(self, xml):
self.index_disks['virtio'] = 0
self.index_disks['ide'] = 0
self.index_disks['sata'] = 0
self.d_graphics_types = None

# def update_xml(self,**kwargs):
# if kwargs.__contains__('vcpus'):
Expand Down Expand Up @@ -527,9 +528,6 @@ def set_cpu_host_model(self, cpu_host_model='host-model'):
xpath_next = '/domain/clock'
self.add_to_domain(xpath_same, cpu, xpath_next, xpath_previous)

def set_graphics_type(self, type_graphics):
self.tree.xpath('/domain/devices/graphics')[0].set('type', type_graphics)

def set_video_type(self, type_video):
self.tree.xpath('/domain/devices/video/model')[0].set('type', type_video)

Expand Down Expand Up @@ -557,6 +555,36 @@ def add_vlc_with_websockets(self):
vlc = etree.parse(StringIO(vlc_string_xml)).getroot()
self.add_to_domain(xpath_same, vlc, xpath_next, xpath_previous)

def set_spice_video_options(self,id_graphics='default'):
xpath_spice = '/domain/devices/graphics[@type="spice"]'

self.d_graphics_types = get_graphics_types(id_graphics)

if self.d_graphics_types is None:
d_spice_options = {
'image': {'compression': 'auto_glz'},
'jpeg': {'compression': 'always'},
'playback': {'compression': 'off'},
'streaming': {'mode': 'all'},
'zlib': {'compression': 'always'},
}
else:
d_spice_options = self.d_graphics_types['spice']['options']

# add spice graphics if not exists
if not self.tree.xpath(xpath_spice):
self.add_spice_graphics_if_not_exist()

# remove all options in spice
tree_spice = self.tree.xpath(xpath_spice)[0]
for i in tree_spice.getchildren():
tree_spice.remove(i)

# add all options in spice
for p,v in d_spice_options.items():
element = etree.Element(p, **v)
tree_spice.insert(-1,element)

def add_spice_graphics_if_not_exist(self,video_compression=None):
xpath_spice = '/domain/devices/graphics[@type="spice"]'

Expand Down Expand Up @@ -943,7 +971,6 @@ def update_xml_from_dict_domain(id_domain, xml=None):
model_type=d_interface['model'])

v.set_vcpu(hw['vcpus'])
v.set_graphics_type(hw['graphics']['type'])
v.set_video_type(hw['video']['type'])
# INFO TO DEVELOPER, falta hacer un v.set_network_id (para ver contra que red hace bridge o se conecta
# INFO TO DEVELOPER, falta hacer un v.set_netowk_type (para seleccionar si quiere virtio o realtek por ejemplo)
Expand Down Expand Up @@ -1060,9 +1087,10 @@ def create_dict_graphics_from_id(id, pool_id):
log.error('{} not defined as id in graphics table, value default is used'.format(id))
dict_graph = get_dict_from_item_in_table('graphics', 'default')

type = dict_graph['type']
# deprectaed
#type = dict_graph['type']
d = {}
d['type'] = type
#d['type'] = type
pool = get_dict_from_item_in_table('hypervisors_pools', pool_id)

if pool['viewer']['defaultMode'] == 'Insecure':
Expand Down Expand Up @@ -1091,10 +1119,11 @@ def recreate_xml_to_start(id, ssl=True, cpu_host_model=False):
if dict_domain.get('not_change_cpu_section',False) is False:
x.set_cpu_host_model(cpu_host_model)

# spice video compression
#x.add_spice_graphics_if_not_exist()
x.set_spice_video_options()

# spice password
x.add_spice_graphics_if_not_exist()

if ssl is True:
#recreate random password in x.viewer_passwd
x.reset_viewer_passwd()
Expand Down
19 changes: 18 additions & 1 deletion src/engine/services/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,21 @@ def get_media_with_status(status):
# if results is None:
close_rethink_connection(r_conn)
return []
return [d['id'] for d in results]
return [d['id'] for d in results]

def get_graphics_types(id_graphics='default'):
"""
get spice graphics options like compression, audio...
:param id_graphics:
:return:
"""
r_conn = new_rethink_connection()
rtable = r.table('graphics')
try:
types = rtable.get(id_graphics).pluck('types').run(r_conn)
d_types = types['types']
except:
d_types = None
close_rethink_connection(r_conn)

return d_types
30 changes: 16 additions & 14 deletions src/webapp/config/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,26 +419,28 @@ def graphics(self):
if not r.table_list().contains('graphics').run():
log.info("Table graphics not found, creating and populating default network...")
r.table_create('graphics', primary_key="id").run()
self.result(r.table('graphics').insert([{'id': 'default',
self.result(r.table('graphics').insert([
{'id': 'default',
'name': 'Default',
'description': 'Spice viewer',
'type':'spice',
'description': 'Spice viewer with compression and vlc',
'allowed': {
'roles': [],
'categories': [],
'groups': [],
'users': []},
},
{'id': 'vnc',
'name': 'VNC',
'description': 'Not functional',
'type':'vnc',
'allowed': {
'roles': ['admin'],
'categories': False,
'groups': False,
'users': False}
}]).run())
'types': {'spice': {
'options': {
'image': {'compression': 'auto_glz'},
'jpeg': {'compression': 'always'},
'playback': {'compression': 'off'},
'streaming': {'mode': 'all'},
'zlib': {'compression': 'always'}},
},
'vlc':{
'options':{}}
},
}
]).run())
return True

'''
Expand Down
69 changes: 66 additions & 3 deletions src/webapp/config/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
'''
Update to new database release version when new code version release
'''
release_version = 6
tables=['config','hypervisors','hypervisors_pools','domains','media']
release_version = 7
tables=['config','hypervisors','hypervisors_pools','domains','media','graphics']


class Upgrade(object):
Expand Down Expand Up @@ -400,7 +400,36 @@ def domains(self,version):
# ~ except Exception as e:
# ~ log.error('Could not update table '+table+' remove fields for db version '+version+'!')
# ~ log.error('Error detail: '+str(e))

if version == 7:
for d in data:
id = d['id']
d.pop('id', None)

''' CONVERSION FIELDS PRE CHECKS '''
# ~ try:
# ~ if not self.check_done( d,
# ~ [],
# ~ []):
##### CONVERSION FIELDS
# ~ cfg['field']={}
# ~ r.table(table).update(cfg).run()
# ~ except Exception as e:
# ~ log.error('Could not update table '+table+' remove fields for db version '+version+'!')
# ~ log.error('Error detail: '+str(e))

''' NEW FIELDS PRE CHECKS '''
try:
if not self.check_done(d,
['preferences'],
[]):
##### NEW FIELDS
self.add_keys(table,
[{'options': {'viewers': {'id_graphics': 'default'}}}],
id=id)
except Exception as e:
log.error('Could not update table ' + table + ' add fields for db version ' + version + '!')
log.error('Error detail: ' + str(e))

return True

'''
Expand Down Expand Up @@ -454,6 +483,40 @@ def media(self,version):
# ~ log.error('Error detail: '+str(e))

return True

'''
DOMAINS TABLE GRAPHICS
'''
def graphics(self,version):
table='graphics'
log.info('UPGRADING '+table+' VERSION '+str(version))
#~ data=list(r.table(table).run())
if version == 7:
r.table(table).delete().run()
r.table('graphics').insert([
{'id': 'default',
'name': 'Default',
'description': 'Spice viewer with compression and vlc',
'allowed': {
'roles': [],
'categories': [],
'groups': [],
'users': []},
'types': {'spice': {
'options': {
'image': {'compression': 'auto_glz'},
'jpeg': {'compression': 'always'},
'playback': {'compression': 'off'},
'streaming': {'mode': 'all'},
'zlib': {'compression': 'always'}},
},
'vlc': {
'options': {}}
},
}
]).run()

return True

'''
Upgrade general actions
Expand Down

0 comments on commit 9b51f38

Please sign in to comment.