build.tracing.trace_msg.TraceMsg.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 2
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
""" This module creates the TraceID message to be used as the
2
Ethernet payload of the PacketOut. This msg is important to
3
differentiate parallel traces.
4
"""
5
6
7 1
class TraceMsg(object):
8
    """ This class will be used to create, retrieve and update the
9
    payload message sent through the trace process
10
11
    Basically the msg is a dictionary:
12
13
    {"trace": {
14
            "request_id": "number to identify this trace"
15
        }
16
    }
17
    """
18
19 1
    def __init__(self, r_id='0'):
20 1
        self._request_id = None
21 1
        self._instantiate_vars(r_id)
22
23 1
    def _instantiate_vars(self, r_id):
24
        """ Attributes in the TraceMsg are processed as
25
        Getter and Setters.
26
27
        Args:
28
            r_id: request ID
29
        """
30 1
        self.request_id = r_id
31
32 1
    @property
33 1
    def request_id(self):
34
        """ Getter: Request ID """
35 1
        return self._request_id
36
37 1
    @request_id.setter
38 1
    def request_id(self, r_id):
39
        """ Setter: Request ID """
40 1
        try:
41 1
            if isinstance(r_id, int):
42 1
                self._request_id = r_id
43
            else:
44 1
                self._request_id = int(r_id)
45
        except ValueError:
46
            raise ValueError("Invalid ID provided: %s" % r_id)
47