summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2012-12-07 11:19:03 -0800
committerDan Smith <danms@us.ibm.com>2012-12-10 06:49:42 -0800
commit8e9bdd77c8986fa9a688bc263a71c72a0fddc77b (patch)
tree854058a6fa83c72f66ca5ff804e5adf58b8976b6 /nova
parentf6c394cce473f58da704bc1c5230c57ca80f299d (diff)
downloadnova-8e9bdd77c8986fa9a688bc263a71c72a0fddc77b.tar.gz
nova-8e9bdd77c8986fa9a688bc263a71c72a0fddc77b.tar.xz
nova-8e9bdd77c8986fa9a688bc263a71c72a0fddc77b.zip
Use conductor for bw_usage operations
This patch moves bw_usage operations from compute manager to conductor. In an effort to reduce the number of API points we're adding to the conductor RPC API, this patch actually only adds an update function, which also returns the current values. This is used by the public conductor API layer to provide both get and update calls through a single remote function. Discussion and comments on this approach are welcomed. Related to blueprint no-db-compute Change-Id: Iabe4cef2bccc8ffcf0ddc76bf7b328c2c4d87112
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/manager.py33
-rw-r--r--nova/conductor/api.py23
-rw-r--r--nova/conductor/manager.py11
-rw-r--r--nova/conductor/rpcapi.py12
4 files changed, 62 insertions, 17 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 9dc6f2c3b..ce2642b13 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -2950,20 +2950,19 @@ class ComputeManager(manager.SchedulerDependentManager):
bw_out = 0
last_ctr_in = None
last_ctr_out = None
- usage = self.db.bw_usage_get(context,
- bw_ctr['uuid'],
- start_time,
- bw_ctr['mac_address'])
+ usage = self.conductor_api.bw_usage_get(context,
+ bw_ctr['uuid'],
+ start_time,
+ bw_ctr['mac_address'])
if usage:
bw_in = usage['bw_in']
bw_out = usage['bw_out']
last_ctr_in = usage['last_ctr_in']
last_ctr_out = usage['last_ctr_out']
else:
- usage = self.db.bw_usage_get(context,
- bw_ctr['uuid'],
- prev_time,
- bw_ctr['mac_address'])
+ usage = self.conductor_api.bw_usage_get(
+ context, bw_ctr['uuid'], prev_time,
+ bw_ctr['mac_address'])
if usage:
last_ctr_in = usage['last_ctr_in']
last_ctr_out = usage['last_ctr_out']
@@ -2982,15 +2981,15 @@ class ComputeManager(manager.SchedulerDependentManager):
else:
bw_out += (bw_ctr['bw_out'] - last_ctr_out)
- self.db.bw_usage_update(context,
- bw_ctr['uuid'],
- bw_ctr['mac_address'],
- start_time,
- bw_in,
- bw_out,
- bw_ctr['bw_in'],
- bw_ctr['bw_out'],
- last_refreshed=refreshed)
+ self.conductor_api.bw_usage_update(context,
+ bw_ctr['uuid'],
+ bw_ctr['mac_address'],
+ start_time,
+ bw_in,
+ bw_out,
+ bw_ctr['bw_in'],
+ bw_ctr['bw_out'],
+ last_refreshed=refreshed)
def _get_host_volume_bdms(self, context, host):
"""Return all block device mappings on a compute host"""
diff --git a/nova/conductor/api.py b/nova/conductor/api.py
index 781a6ea90..a55618bd6 100644
--- a/nova/conductor/api.py
+++ b/nova/conductor/api.py
@@ -65,6 +65,17 @@ class LocalAPI(object):
def aggregate_host_delete(self, context, aggregate, host):
return self._manager.aggregate_host_delete(context, aggregate, host)
+ def bw_usage_get(self, context, uuid, start_period, mac):
+ return self._manager.bw_usage_update(context, uuid, start_period, mac)
+
+ def bw_usage_update(self, context, uuid, mac, start_period,
+ bw_in, bw_out, last_ctr_in, last_ctr_out,
+ last_refreshed=None):
+ return self._manager.bw_usage_update(context, uuid, mac, start_period,
+ bw_in, bw_out,
+ last_ctr_in, last_ctr_out,
+ last_refreshed)
+
class API(object):
"""Conductor API that does updates via RPC to the ConductorManager"""
@@ -98,3 +109,15 @@ class API(object):
def aggregate_host_delete(self, context, aggregate, host):
return self.conductor_rpcapi.aggregate_host_delete(context, aggregate,
host)
+
+ def bw_usage_get(self, context, uuid, start_period, mac):
+ return self.conductor_rpcapi.bw_usage_update(context, uuid, mac,
+ start_period)
+
+ def bw_usage_update(self, context, uuid, mac, start_period,
+ bw_in, bw_out, last_ctr_in, last_ctr_out,
+ last_refreshed=None):
+ return self.conductor_rpcapi.bw_usage_update(
+ context, uuid, mac, start_period,
+ bw_in, bw_out, last_ctr_in, last_ctr_out,
+ last_refreshed)
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index ce76fe02d..925edc29a 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -89,3 +89,14 @@ class ConductorManager(manager.SchedulerDependentManager):
def aggregate_host_delete(self, context, aggregate, host):
self.db.aggregate_host_delete(context.elevated(),
aggregate['id'], host)
+
+ def bw_usage_update(self, context, uuid, mac, start_period,
+ bw_in=None, bw_out=None,
+ last_ctr_in=None, last_ctr_out=None,
+ last_refreshed=None):
+ if all((None, bw_in, bw_out, last_ctr_in, last_ctr_out)):
+ self.db.bw_usage_update(context, uuid, mac, start_period,
+ bw_in, bw_out, last_ctr_in, last_ctr_out,
+ last_refreshed)
+ usage = self.db.bw_usage_get(context, uuid, start_period, mac)
+ return jsonutils.to_primitive(usage)
diff --git a/nova/conductor/rpcapi.py b/nova/conductor/rpcapi.py
index 0ca1269c4..e8a9a2fed 100644
--- a/nova/conductor/rpcapi.py
+++ b/nova/conductor/rpcapi.py
@@ -31,6 +31,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.2 - Added instance_get_by_uuid and instance_get_all_by_host
1.3 - Added aggregate_host_add and aggregate_host_delete
1.4 - Added migration_get
+ 1.5 - Added bw_usage_update
"""
BASE_RPC_API_VERSION = '1.0'
@@ -77,3 +78,14 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
msg = self.make_msg('aggregate_host_delete', aggregate=aggregate_p,
host=host)
return self.call(context, msg, version='1.3')
+
+ def bw_usage_update(self, context, uuid, mac, start_period,
+ bw_in=None, bw_out=None,
+ last_ctr_in=None, last_ctr_out=None,
+ last_refreshed=None):
+ msg = self.make_msg('bw_usage_update',
+ uuid=uuid, mac=mac, start_period=start_period,
+ bw_in=bw_in, bw_out=bw_out,
+ last_ctr_in=last_ctr_in, last_ctr_out=last_ctr_out,
+ last_refreshed=last_refreshed)
+ return self.call(context, msg, version='1.5')