Move the io bandwidth fields from PIF onto a new PIF_metrics class.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
Ewan Mellor committed 2007-01-29 19:00:48 +00:00
1 parent 32890a0e31
commit bc1f80dd2c
11 files changed
+749 -118

No files matched your search

+38 -9
View File
@@ -12,7 +12,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2006 XenSource Ltd.
# Copyright (C) 2006-2007 XenSource Ltd.
#============================================================================
import inspect
@@ -261,6 +261,17 @@ def valid_pif(func):
_check_ref(lambda r: r in XendNode.instance().pifs,
'PIF_HANDLE_INVALID', func, *args, **kwargs)
def valid_pif_metrics(func):
"""Decorator to verify if pif_metrics_ref is valid before calling
method.
@param func: function with params: (self, session, pif_metrics_ref)
@rtype: callable object
"""
return lambda *args, **kwargs: \
_check_ref(lambda r: r in XendNode.instance().pif_metrics,
'PIF_METRICS_HANDLE_INVALID', func, *args, **kwargs)
def valid_task(func):
"""Decorator to verify if task_ref is valid before calling
method.
@@ -361,6 +372,7 @@ class XendAPI(object):
'console' : valid_console,
'SR' : valid_sr,
'PIF' : valid_pif,
'PIF_metrics': valid_pif_metrics,
'task' : valid_task,
'debug' : valid_debug,
}
@@ -738,8 +750,7 @@ class XendAPI(object):
# Xen API: Class PIF
# ----------------------------------------------------------------
PIF_attr_ro = ['io_read_kbs',
'io_write_kbs']
PIF_attr_ro = ['metrics']
PIF_attr_rw = ['device',
'network',
'host',
@@ -767,6 +778,9 @@ class XendAPI(object):
def PIF_get_all(self, _):
return xen_api_success(XendNode.instance().pifs.keys())
def PIF_get_metrics(self, _, ref):
return xen_api_success(self._get_PIF(ref).metrics.uuid)
def PIF_get_device(self, _, ref):
return xen_api_success(self._get_PIF(ref).device)
@@ -785,12 +799,6 @@ class XendAPI(object):
def PIF_get_VLAN(self, _, ref):
return xen_api_success(self._get_PIF(ref).vlan)
def PIF_get_io_read_kbs(self, _, ref):
return xen_api_success(self._get_PIF(ref).get_io_read_kbs())
def PIF_get_io_write_kbs(self, _, ref):
return xen_api_success(self._get_PIF(ref).get_io_write_kbs())
def PIF_set_device(self, _, ref, device):
return xen_api_success(self._get_PIF(ref).set_device(device))
@@ -821,6 +829,27 @@ class XendAPI(object):
return xen_api_error(['VLAN_TAG_INVALID', vlan])
# Xen API: Class PIF_metrics
# ----------------------------------------------------------------
PIF_metrics_attr_ro = ['io_read_kbs',
'io_write_kbs']
PIF_metrics_attr_rw = []
PIF_methods = []
def _PIF_metrics_get(self, ref):
return XendNode.instance().pif_metrics[ref]
def PIF_metrics_get_record(self, _, ref):
return xen_api_success(self._PIF_metrics_get(ref).get_record())
def PIF_metrics_get_io_read_kbs(self, _, ref):
return xen_api_success(self._PIF_metrics_get(ref).get_io_read_kbs())
def PIF_metrics_get_io_write_kbs(self, _, ref):
return xen_api_success(self._PIF_metrics_get(ref).get_io_write_kbs())
# Xen API: Class VM
# ----------------------------------------------------------------
+21 -13
View File
@@ -13,7 +13,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
# Copyright (c) 2006 Xensource Inc.
# Copyright (c) 2006, 2007 Xensource Inc.
#============================================================================
import os
@@ -29,6 +29,7 @@ from xen.xend.XendQCoWStorageRepo import XendQCoWStorageRepo
from xen.xend.XendLocalStorageRepo import XendLocalStorageRepo
from xen.xend.XendLogging import log
from xen.xend.XendPIF import *
from xen.xend.XendPIFMetrics import XendPIFMetrics
from xen.xend.XendNetwork import *
from xen.xend.XendStateStore import XendStateStore
from xen.xend.XendMonitor import XendMonitor
@@ -88,6 +89,7 @@ class XendNode:
self.cpus[cpu_uuid] = cpu_info
self.pifs = {}
self.pif_metrics = {}
self.networks = {}
self.srs = {}
@@ -114,10 +116,14 @@ class XendNode:
if 'device' not in pif and 'name' in pif:
# Compatibility hack, can go pretty soon.
pif['device'] = pif['name']
if 'metrics' not in pif:
# Compatibility hack, can go pretty soon.
pif['metrics'] = uuid.createString()
self._PIF_create(pif['device'], pif['MTU'],
int(pif['VLAN']),
pif['MAC'], network, False, pif_uuid)
pif['MAC'], network, False, pif_uuid,
pif['metrics'])
except NetworkAlreadyConnected, exn:
log.error('Cannot load saved PIF %s, as network %s ' +
'is already connected to PIF %s',
@@ -167,15 +173,23 @@ class XendNode:
def _PIF_create(self, name, mtu, vlan, mac, network, persist = True,
pif_uuid = None):
pif_uuid = None, metrics_uuid = None):
for pif in self.pifs.values():
if pif.network == network:
raise NetworkAlreadyConnected(pif.uuid)
if pif_uuid is None:
pif_uuid = uuid.createString()
self.pifs[pif_uuid] = XendPIF(pif_uuid, name, mtu, vlan, mac, network,
self)
if metrics_uuid is None:
metrics_uuid = uuid.createString()
metrics = XendPIFMetrics(metrics_uuid)
pif = XendPIF(pif_uuid, metrics, name, mtu, vlan, mac, network, self)
metrics.set_PIF(pif)
self.pif_metrics[metrics_uuid] = metrics
self.pifs[pif_uuid] = pif
if persist:
self.save_PIFs()
self.refreshBridges()
@@ -212,7 +226,7 @@ class XendNode:
self.save_SRs()
def save_PIFs(self):
pif_records = dict([(k, v.get_record(transient = False))
pif_records = dict([(k, v.get_record())
for k, v in self.pifs.items()])
self.state_store.save_state('pif', pif_records)
@@ -495,12 +509,6 @@ class XendNode:
return vbd_loads[domid].get(vbdid, (0.0, 0.0))
return (0.0, 0.0)
def get_pif_util(self, pifname):
pifs_util = self.monitor.get_pifs_util()
if pifname in pifs_util:
return pifs_util[pifname]
return (0.0, 0.0)
# dictionary version of *info() functions to get rid of
# SXPisms.
def nodeinfo_dict(self):
+11 -21
View File
@@ -90,8 +90,10 @@ def linux_set_mtu(iface, mtu):
class XendPIF:
"""Representation of a Physical Network Interface."""
def __init__(self, uuid, device, mtu, vlan, mac, network, host):
def __init__(self, uuid, metrics, device, mtu, vlan, mac, network,
host):
self.uuid = uuid
self.metrics = metrics
self.device = device
self.mac = mac
self.mtu = mtu
@@ -114,26 +116,14 @@ class XendPIF:
self.mtu = new_mtu
return success
def get_io_read_kbs(self):
from xen.xend.XendNode import instance as xennode
return xennode().get_pif_util(self.device)[0]
def get_io_write_kbs(self):
from xen.xend.XendNode import instance as xennode
return xennode().get_pif_util(self.device)[1]
def get_record(self, transient = True):
result = {'device': self.device,
'MAC': self.mac,
'MTU': self.mtu,
'VLAN': self.vlan,
'host': self.host.uuid,
'network': self.network.uuid}
if transient:
result['io_read_kbs'] = self.get_io_read_kbs()
result['io_write_kbs'] = self.get_io_write_kbs()
return result
def get_record(self):
return {'device': self.device,
'MAC': self.mac,
'MTU': self.mtu,
'VLAN': self.vlan,
'host': self.host.uuid,
'network': self.network.uuid,
'metrics': self.metrics.uuid}
def refresh(self, bridges):
ifname = self.interface_name()
+46
View File
@@ -0,0 +1,46 @@
#============================================================================
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (c) 2006-2007 Xensource Inc.
#============================================================================
class XendPIFMetrics:
"""PIF Metrics."""
def __init__(self, uuid):
self.uuid = uuid
def set_PIF(self, pif):
self.pif = pif
def get_io_read_kbs(self):
return self._get_stat(0)
def get_io_write_kbs(self):
return self._get_stat(1)
def _get_stat(self, n):
from xen.xend.XendNode import instance as xennode
pifname = self.pif.device
pifs_util = xennode().monitor.get_pifs_util()
if pifname in pifs_util:
return pifs_util[pifname][n]
return 0.0
def get_record(self):
return {'PIF' : self.pif.uuid,
'io_read_kbs' : self.get_io_read_kbs(),
'io_write_kbs' : self.get_io_write_kbs()
}
+7 -1
View File
@@ -19,7 +19,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Xen-xm 3.0\n"
"PO-Revision-Date: 2007-01-28 21:58+0000\n"
"PO-Revision-Date: 2007-01-29 18:50+0000\n"
"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
"MIME-Version: 1.0\n"
@@ -47,6 +47,12 @@ msgstr "The host_cpu handle %(1)s is invalid."
msgid "HOST_HANDLE_INVALID"
msgstr "The host handle %(1)s is invalid."
msgid "PIF_HANDLE_INVALID"
msgstr "The PIF handle %(1)s is invalid."
msgid "PIF_METRICS_HANDLE_INVALID"
msgstr "The PIF_METRICS handle %(1)s is invalid."
msgid "SR_HANDLE_INVALID"
msgstr "The SR handle %(1)s is invalid."
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.