Skip to content
3 changes: 2 additions & 1 deletion backend_core/tomato/host/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def synchronize(self):
if (not self.topologyElement and not self.topologyConnection) or (self.host is None):
self.remove()
return
self.updateInfo()
self.modify(timeout=time.time() + settings.get_host_connections_settings()['component-timeout'])
except error.UserError, err:
if err.code == error.UserError.ENTITY_DOES_NOT_EXIST:
Expand All @@ -144,6 +145,6 @@ def synchronize(id_):
try:
HostElement.objects.get(id=id_).synchronize()
except DoesNotExist:
pass # nothong to synchronize
pass # nothing to synchronize

scheduler.scheduleMaintenance(min(3600, settings.get_host_connections_settings()['component-timeout']), list, synchronize)
4 changes: 2 additions & 2 deletions hostmanager/tomato/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class UsageStatistics(BaseDocument):
ATTRIBUTES = {
"id": IdAttribute(),
"begin": Attribute(field=begin, schema=schema.Number()),
"element": Attribute(get=lambda self: self.element.id if self.element else None),
"connection": Attribute(get=lambda self: self.connection.id if self.element else None)
"element": Attribute(get=lambda self: self.element.getId() if self.element else None),
"connection": Attribute(get=lambda self: self.connection.getId() if self.connection else None)
}

meta = {
Expand Down
4 changes: 2 additions & 2 deletions hostmanager/tomato/api/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def accounting_statistics(type=None, after=None, before=None): #@ReservedAssignm
are the connection ids (as strings) and the values are the usage
statistics.
"""
elSt = dict([(str(el.id), el.getUsageStatistics().info(type, after, before)) for el in elements.getAll(owner=currentUser())])
conSt = dict([(str(con.id), con.getUsageStatistics().info(type, after, before)) for con in connections.getAll(owner=currentUser())])
elSt = dict([(str(el.getId()), el.getUsageStatistics().info(type, after, before)) for el in elements.getAll(owner=currentUser())])
conSt = dict([(str(con.getId()), con.getUsageStatistics().info(type, after, before)) for con in connections.getAll(owner=currentUser())])
return {"elements": elSt, "connections": conSt}

def accounting_element_statistics(id, type=None, after=None, before=None): #@ReservedAssignment
Expand Down
8 changes: 8 additions & 0 deletions hostmanager/tomato/api/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

def _getConnection(id_):
import sys
try:
id_ = str(id_)
if sys.getsizeof(id_) < 60:
oldId=int(str(id_))
id_ = "{0:0{1}x}".format(oldId, 24)
except:
pass
con = connections.get(id_, owner=currentUser())
UserError.check(con, UserError.ENTITY_DOES_NOT_EXIST, "No such connection", data={"id": id_})
return con
Expand Down
8 changes: 8 additions & 0 deletions hostmanager/tomato/api/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

def _getElement(id_):
import sys
try:
id_ = str(id_)
if sys.getsizeof(id_) < 60:
oldId=int(str(id_))
id_ = "{0:0{1}x}".format(oldId, 24)
except:
pass
el = elements.get(id_, owner=currentUser())
UserError.check(el, UserError.ENTITY_DOES_NOT_EXIST, "No such element", data={"id": id_})
return el
Expand Down
8 changes: 8 additions & 0 deletions hostmanager/tomato/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

def _getResource(id_):
import sys
try:
id_ = str(id_)
if sys.getsizeof(id_) < 60:
oldId=int(str(id_))
id_ = "{0:0{1}x}".format(oldId, 24)
except:
pass
res = resources.get(id_)
UserError.check(res, UserError.ENTITY_DOES_NOT_EXIST, "No such resource", data={"id": id_})
return res
Expand Down
18 changes: 16 additions & 2 deletions hostmanager/tomato/connections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ class that it possesses. Due to a limitation of the database backend,
pass
raise InternalError(message="Failed to cast connection", code=InternalError.UPCAST, data={"id": str(self.id), "type": self.type})

def getId(self):
"""
Returns the element id, converts automatically back to old postgres IDs if possible
:return: String
"""
id_ = str(self.id)
try:
#As we converted old ids by adding zeros to the left, we can check if the first 12 characters are zeros
if id_[0:12] == "000000000000":
id_ = int(id_, 16)
except:
pass
return id_

def dataPath(self, filename=""):
"""
This method can be used to create filenames relative to a directory
Expand All @@ -170,7 +184,7 @@ def dataPath(self, filename=""):
@param filename: a filename relative to the data path
@type filename: str
"""
return os.path.join(config.DATA_DIR, self.TYPE, str(self.id), filename)
return os.path.join(config.DATA_DIR, self.TYPE, str(self.getId()), filename)

@classmethod
def determineConcept(cls, el1, el2):
Expand Down Expand Up @@ -274,7 +288,7 @@ def getElements(self):
def info(self):
els = [str(el.id) for el in self.elements]
return {
"id": str(self.id),
"id": str(self.getId()),
"type": self.type,
"state": self.state,
"attrs": Entity.info(self),
Expand Down
4 changes: 3 additions & 1 deletion hostmanager/tomato/connections/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def type(self):
def init(self, *args, **kwargs):
self.state = StateName.CREATED
connections.Connection.init(self, *args, **kwargs) #no id and no attrs before this line
self.bridge = "br%s" % str(self.id)[13:24]
self.bridge = "br%s" % (str(self.getId())[13:24] if isinstance(self.getId(),type(str())) else str(self.getId()))
self.capture_port = self.getResource("port")
self.update_or_save(bridge=self.bridge, capture_port=self.capture_port)

def _startCapturing(self):
if not self.capturing or self.state == StateName.CREATED:
Expand Down Expand Up @@ -245,6 +246,7 @@ def action_stop(self):
if net.bridgeExists(self.bridge):
net.ifDown(self.bridge)
net.bridgeRemove(self.bridge)
self.update_or_save(bridge=self.bridge, capture_port=self.capture_port)
self.setState(StateName.CREATED)

def remove(self):
Expand Down
Loading