aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Bailey <josh@vandervecken.com>2020-05-12 09:22:26 +1200
committerJosh Bailey <josh@vandervecken.com>2020-05-12 09:22:26 +1200
commit023c482df878989bea5aa9cc9e7c9cef713b4145 (patch)
treeab8230d8d2f1554203e31b423aace15c2092108c
parent34b3c7ee69c6c205f8b356357eac48e9324ef22e (diff)
downloadfaucet-023c482df878989bea5aa9cc9e7c9cef713b4145.tar.gz
faucet-023c482df878989bea5aa9cc9e7c9cef713b4145.tar.bz2
faucet-023c482df878989bea5aa9cc9e7c9cef713b4145.zip
minor prom var refactoring.
-rw-r--r--faucet/valve.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/faucet/valve.py b/faucet/valve.py
index 1e00c0f2..8a106965 100644
--- a/faucet/valve.py
+++ b/faucet/valve.py
@@ -36,7 +36,6 @@ from faucet.valve_coprocessor import CoprocessorManager
from faucet.valve_lldp import ValveLLDPManager
from faucet.valve_outonly import OutputOnlyManager
from faucet.valve_switch_stack import ValveSwitchStackManagerBase
-from faucet.vlan import NullVLAN
# TODO: has to be here to avoid eventlet monkey patch in faucet_dot1x.
@@ -165,6 +164,9 @@ class Valve:
metrics_var = getattr(self.metrics, var)
metrics_var.labels(**labels).set(val)
+ def _set_port_var(self, var, val, port):
+ self._set_var(var, val, labels=self.dp.port_labels(port.number))
+
def _remove_var(self, var, labels=None):
if labels is None:
labels = self.dp.base_prom_labels()
@@ -450,8 +452,7 @@ class Valve:
port = self.dp.ports.get(port_no, None)
if port is None:
return
- port_labels = self.dp.port_labels(port.number)
- self._set_var('port_status', port_status, labels=port_labels)
+ self._set_port_var('port_status', port_status, port)
port.dyn_update_time = now
def port_status_handler(self, port_no, reason, state, _other_valves, now):
@@ -632,10 +633,7 @@ class Valve:
next_state = self._next_stack_link_state(port, now)
if next_state is not None:
next_state()
- self._set_var(
- 'port_stack_state',
- port.dyn_stack_current_state,
- labels=self.dp.port_labels(port.number))
+ self._set_port_var('port_stack_state', port.dyn_stack_current_state, port)
self.notify({'STACK_STATE': {
'port': port.number,
'state': port.dyn_stack_current_state
@@ -735,10 +733,7 @@ class Valve:
return self._update_stack_link_state(self.dp.stack_ports, now, other_valves)
def _reset_dp_status(self):
- if self.dp.dyn_running:
- self._set_var('dp_status', 1)
- else:
- self._set_var('dp_status', 0)
+ self._set_var('dp_status', int(self.dp.dyn_running))
def datapath_connect(self, now, discovered_up_ports):
"""Handle Ryu datapath connection event and provision pipeline.
@@ -834,8 +829,7 @@ class Valve:
ofmsgs.extend(self.lacp_update(port, False))
if port.lacp_active:
ofmsgs.extend(self._lacp_actions(port.dyn_last_lacp_pkt, port))
- self._set_var('lacp_port_id',
- port.lacp_port_id, labels=self.dp.port_labels(port.number))
+ self._set_port_var('lacp_port_id', port.lacp_port_id, port)
if port.stack:
port_vlans = self.dp.vlans.values()
@@ -901,7 +895,7 @@ class Valve:
def _reset_lacp_status(self, port):
lacp_state = port.actor_state()
lacp_role = port.lacp_port_state()
- self._set_var('port_lacp_state', lacp_state, labels=self.dp.port_labels(port.number))
+ self._set_port_var('port_lacp_state', lacp_state, port)
self.notify(
{'LAG_CHANGE': {'port_no': port.number, 'state': lacp_state, 'role': lacp_role}})
@@ -964,7 +958,7 @@ class Valve:
self.logger.info('LAG %u %s %s (previous state %s)' % (
port.lacp, port, port.port_role_name(new_state),
port.port_role_name(prev_state)))
- self._set_var('port_lacp_role', new_state, labels=self.dp.port_labels(port.number))
+ self._set_port_var('port_lacp_role', new_state, port)
return new_state != prev_state
def lacp_update_actor_state(self, port, lacp_up, now=None, lacp_pkt=None, cold_start=False):
@@ -1457,11 +1451,10 @@ class Valve:
return True
def _update_port(vlan, port):
- port_labels = self.dp.port_labels(port.number)
port_vlan_labels = self._port_vlan_labels(port, vlan)
port_vlan_hosts_learned = port.hosts_count(vlans=[vlan])
- self._set_var(
- 'port_learn_bans', port.dyn_learn_ban_count, labels=port_labels)
+ self._set_port_var(
+ 'port_learn_bans', port.dyn_learn_ban_count, port)
self._set_var(
'port_vlan_hosts_learned', port_vlan_hosts_learned, labels=port_vlan_labels)
highwater = self._port_highwater[vlan.vid][port.number]