Skip to content

Commit

Permalink
Fix dough billing network driver
Browse files Browse the repository at this point in the history
Use instance uuid for metering lookup
  • Loading branch information
=Cheng Hui committed May 31, 2012
1 parent 1de11c7 commit 1140920
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
14 changes: 7 additions & 7 deletions dough/api.py
Expand Up @@ -111,18 +111,18 @@ def query_item_products(context, region=None, item=None, **kwargs):
filters['item_id'] = db.item_get_by_name(context, item)['id']
products = db.product_get_all(context, filters=filters)
for product in products:
item_type_name = products['item_type']['name']
payment_type_name = products['payment_type']['name']
order_unit = products['order_unit']
order_size = products['order_size']
price = products['price']
currency = products['currency']
item_type_name = product['item_type']['name']
payment_type_name = product['payment_type']['name']
order_unit = product['order_unit']
order_size = product['order_size']
price = product['price']
currency = product['currency']
item_type_info = product_info.setdefault(item_type_name, dict())
item_type_info[payment_type_name] = {
'order_unit': order_unit,
'order_size': order_size,
'price': price,
'currency': order_unit,
'currency': currency,
}
return {'data': product_info}

Expand Down
18 changes: 1 addition & 17 deletions dough/billing/driver/network.py
Expand Up @@ -16,8 +16,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import MySQLdb
import MySQLdb.cursors
import zmq

from nova import flags
Expand All @@ -33,13 +31,6 @@
FLAGS.keystone_auth_url,
service_type="compute")

MYSQL_CLIENT = MySQLdb.connect(host=FLAGS.mysql_host,
port=FLAGS.mysql_port,
user=FLAGS.mysql_user,
passwd=FLAGS.mysql_pwd,
db=FLAGS.nova_schema,
cursorclass=MySQLdb.cursors.DictCursor)


class Client():

Expand Down Expand Up @@ -95,16 +86,9 @@ def is_terminated(instance_uuid):


def get_usage(instance_uuid, datetime_from, datetime_to, order_size):
cur = MYSQL_CLIENT.cursor()
cur.execute("SELECT id FROM instances WHERE uuid=%s", instance_uuid)
result = cur.fetchone()
cur.close()
if result is None:
raise Exception()
instance_id = result['id']
data = KANYUN_CLIENT.send({'method': 'query_usage_report',
'args': {
'id': 'instance-%08x' % instance_id,
'id': instance_uuid,
'metric': 'vmnetwork',
'metric_param': 'vnet0',
'statistic': 'sum',
Expand Down

0 comments on commit 1140920

Please sign in to comment.