Commit 20d6fe4b authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

wip

parent f24a2ecc
...@@ -120,8 +120,8 @@ def _replaceParameterValue(original_content, to_replace): ...@@ -120,8 +120,8 @@ def _replaceParameterValue(original_content, to_replace):
to_replace by their value. to_replace by their value.
""" """
for key, value in to_replace: for key, value in to_replace:
original_content = re.sub('%s\s+=.*' % key, '%s = %s' % (key, value), original_content = re.sub(b'%s\s+=.*' % key, b'%s = %s' % (key, value),
str(original_content)) original_content)
return original_content return original_content
def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args): def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
......
...@@ -43,7 +43,7 @@ from slapos.collect.reporter import RawCSVDumper, \ ...@@ -43,7 +43,7 @@ from slapos.collect.reporter import RawCSVDumper, \
compressLogFolder, \ compressLogFolder, \
ConsumptionReport ConsumptionReport
from entity import get_user_list, Computer from .entity import get_user_list, Computer
def _get_time(): def _get_time():
return strftime("%Y-%m-%d -- %H:%M:%S").split(" -- ") return strftime("%Y-%m-%d -- %H:%M:%S").split(" -- ")
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# #
############################################################################## ##############################################################################
from six.moves import zip
from lxml import etree as ElementTree from lxml import etree as ElementTree
from slapos.util import mkdir_p from slapos.util import mkdir_p
...@@ -139,7 +141,7 @@ class ConsumptionReportBase(object): ...@@ -139,7 +141,7 @@ class ConsumptionReportBase(object):
columns="SUM(cpu_percent)", columns="SUM(cpu_percent)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
cpu_percent_sum = zip(*query_result_cursor) cpu_percent_sum = list(zip(*query_result_cursor))
if len(cpu_percent_sum) and cpu_percent_sum[0][0] is None: if len(cpu_percent_sum) and cpu_percent_sum[0][0] is None:
return return
...@@ -147,7 +149,7 @@ class ConsumptionReportBase(object): ...@@ -147,7 +149,7 @@ class ConsumptionReportBase(object):
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
sample_amount = zip(*query_result_cursor) sample_amount = list(zip(*query_result_cursor))
self.db.close() self.db.close()
if len(sample_amount) and len(cpu_percent_sum): if len(sample_amount) and len(cpu_percent_sum):
...@@ -159,7 +161,7 @@ class ConsumptionReportBase(object): ...@@ -159,7 +161,7 @@ class ConsumptionReportBase(object):
columns="SUM(memory_rss)", columns="SUM(memory_rss)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
memory_sum = zip(*query_result_cursor) memory_sum = list(zip(*query_result_cursor))
if len(memory_sum) and memory_sum[0][0] is None: if len(memory_sum) and memory_sum[0][0] is None:
return return
...@@ -167,7 +169,7 @@ class ConsumptionReportBase(object): ...@@ -167,7 +169,7 @@ class ConsumptionReportBase(object):
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
sample_amount = zip(*query_result_cursor) sample_amount = list(zip(*query_result_cursor))
self.db.close() self.db.close()
if len(sample_amount) and len(memory_sum): if len(sample_amount) and len(memory_sum):
...@@ -179,14 +181,14 @@ class ConsumptionReportBase(object): ...@@ -179,14 +181,14 @@ class ConsumptionReportBase(object):
columns="SUM(disk_used)", columns="SUM(disk_used)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
disk_used_sum = zip(*query_result_cursor) disk_used_sum = list(zip(*query_result_cursor))
if len(disk_used_sum) and disk_used_sum[0][0] is None: if len(disk_used_sum) and disk_used_sum[0][0] is None:
return return
query_result_cursor = self.db.select("folder", date_scope, query_result_cursor = self.db.select("folder", date_scope,
columns="COUNT(DISTINCT time)", columns="COUNT(DISTINCT time)",
where="partition = '%s'" % partition_id) where="partition = '%s'" % partition_id)
collect_amount = zip(*query_result_cursor) collect_amount = list(zip(*query_result_cursor))
self.db.close() self.db.close()
if len(collect_amount) and len(disk_used_sum): if len(collect_amount) and len(disk_used_sum):
...@@ -301,7 +303,7 @@ class ConsumptionReport(ConsumptionReportBase): ...@@ -301,7 +303,7 @@ class ConsumptionReport(ConsumptionReportBase):
query_result_cursor = self.db.select("system", date_scope, query_result_cursor = self.db.select("system", date_scope,
columns="SUM(cpu_percent)/COUNT(cpu_percent)") columns="SUM(cpu_percent)/COUNT(cpu_percent)")
cpu_load_percent_list = zip(*query_result_cursor) cpu_load_percent_list = list(zip(*query_result_cursor))
self.db.close() self.db.close()
if len(cpu_load_percent_list): if len(cpu_load_percent_list):
return cpu_load_percent_list[0][0] return cpu_load_percent_list[0][0]
...@@ -311,7 +313,7 @@ class ConsumptionReport(ConsumptionReportBase): ...@@ -311,7 +313,7 @@ class ConsumptionReport(ConsumptionReportBase):
query_result_cursor = self.db.select("system", date_scope, query_result_cursor = self.db.select("system", date_scope,
columns="SUM(memory_used)/COUNT(memory_used)") columns="SUM(memory_used)/COUNT(memory_used)")
memory_used_list = zip(*query_result_cursor) memory_used_list = list(zip(*query_result_cursor))
self.db.close() self.db.close()
if len(memory_used_list): if len(memory_used_list):
return memory_used_list[0][0] return memory_used_list[0][0]
......
...@@ -31,10 +31,10 @@ from __future__ import print_function ...@@ -31,10 +31,10 @@ from __future__ import print_function
import psutil import psutil
import os import os
import subprocess import subprocess
from temperature import collectComputerTemperature, \ from .temperature import collectComputerTemperature, \
launchTemperatureTest launchTemperatureTest
from temperature.heating import get_contribution_ratio from .temperature.heating import get_contribution_ratio
MEASURE_INTERVAL = 5 MEASURE_INTERVAL = 5
......
from __future__ import print_function
from multiprocessing import Process, active_children, cpu_count, Pipe from multiprocessing import Process, active_children, cpu_count, Pipe
import subprocess import subprocess
...@@ -120,7 +121,7 @@ def launchTemperatureTest(sensor_id, sensor_bin="sensors", timeout=600, interval ...@@ -120,7 +121,7 @@ def launchTemperatureTest(sensor_id, sensor_bin="sensors", timeout=600, interval
for connection in process_connection_list: for connection in process_connection_list:
try: try:
print connection.recv() print(connection.recv())
except EOFError: except EOFError:
continue continue
......
...@@ -3,4 +3,7 @@ ...@@ -3,4 +3,7 @@
import pkg_resources import pkg_resources
DB_VERSION = pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline().strip().split(b':')[1] DB_VERSION = pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline().strip().split(b':')[1]
import six
if six.PY3:
DB_VERSION = DB_VERSION.decode('utf-8')
...@@ -44,6 +44,7 @@ import xml_marshaller ...@@ -44,6 +44,7 @@ import xml_marshaller
from xml_marshaller.xml_marshaller import loads from xml_marshaller.xml_marshaller import loads
from xml_marshaller.xml_marshaller import dumps from xml_marshaller.xml_marshaller import dumps
import six
from six.moves import range from six.moves import range
app = Flask(__name__) app = Flask(__name__)
...@@ -81,7 +82,7 @@ def xml2dict(xml): ...@@ -81,7 +82,7 @@ def xml2dict(xml):
def dict2xml(dictionary): def dict2xml(dictionary):
instance = etree.Element('instance') instance = etree.Element('instance')
for parameter_id, parameter_value in dictionary.iteritems(): for parameter_id, parameter_value in six.iteritems(dictionary):
# cast everything to string # cast everything to string
parameter_value = unicode(parameter_value) parameter_value = unicode(parameter_value)
etree.SubElement(instance, "parameter", etree.SubElement(instance, "parameter",
...@@ -93,7 +94,7 @@ def dict2xml(dictionary): ...@@ -93,7 +94,7 @@ def dict2xml(dictionary):
def partitiondict2partition(partition): def partitiondict2partition(partition):
for key, value in partition.iteritems(): for key, value in six.iteritems(partition):
if type(value) is unicode: if type(value) is unicode:
partition[key] = value.encode() partition[key] = value.encode()
slap_partition = ComputerPartition(partition['computer_reference'], slap_partition = ComputerPartition(partition['computer_reference'],
...@@ -188,7 +189,7 @@ def _upgradeDatabaseIfNeeded(): ...@@ -188,7 +189,7 @@ def _upgradeDatabaseIfNeeded():
if current_schema_version == DB_VERSION: if current_schema_version == DB_VERSION:
return return
schema = app.open_resource('schema.sql') schema = app.open_resource('schema.sql', 'r')
schema = schema.read() % dict(version=DB_VERSION, computer=app.config['computer_id']) schema = schema.read() % dict(version=DB_VERSION, computer=app.config['computer_id'])
g.db.cursor().executescript(schema) g.db.cursor().executescript(schema)
g.db.commit() g.db.commit()
...@@ -308,7 +309,7 @@ def useComputer(): ...@@ -308,7 +309,7 @@ def useComputer():
@app.route('/loadComputerConfigurationFromXML', methods=['POST']) @app.route('/loadComputerConfigurationFromXML', methods=['POST'])
def loadComputerConfigurationFromXML(): def loadComputerConfigurationFromXML():
xml = request.form['xml'] xml = request.form['xml']
computer_dict = xml_marshaller.xml_marshaller.loads(str(xml)) computer_dict = xml_marshaller.xml_marshaller.loads(str(xml).encode('utf-8'))
execute_db('computer', 'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)', execute_db('computer', 'INSERT OR REPLACE INTO %s values(:reference, :address, :netmask)',
computer_dict) computer_dict)
for partition in computer_dict['partition_list']: for partition in computer_dict['partition_list']:
...@@ -473,7 +474,7 @@ def isRequestToBeForwardedToExternalMaster(parsed_request_dict): ...@@ -473,7 +474,7 @@ def isRequestToBeForwardedToExternalMaster(parsed_request_dict):
return master_url return master_url
software_release = parsed_request_dict['software_release'] software_release = parsed_request_dict['software_release']
for mutimaster_url, mutimaster_entry in app.config.get('multimaster').iteritems(): for mutimaster_url, mutimaster_entry in six.iteritems(app.config.get('multimaster')):
if software_release in mutimaster_entry['software_release_list']: if software_release in mutimaster_entry['software_release_list']:
# Don't allocate the instance locally, but forward to specified master # Don't allocate the instance locally, but forward to specified master
return mutimaster_url return mutimaster_url
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment