[ADMIN_API] Move MnB create/delete msgs
MnB create and deletes have been moved out of the API calls to the gearman client, after the creates / deletes have completed. Also had to move billing_enable to the defaul config group. Change-Id: I289e84d96d72a1fd493231938360f482c7820d41
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#daemon = true
|
#daemon = true
|
||||||
#user = libra
|
#user = libra
|
||||||
#group = libra
|
#group = libra
|
||||||
|
#billing_enable = False
|
||||||
|
|
||||||
# Other logging options
|
# Other logging options
|
||||||
#syslog = false
|
#syslog = false
|
||||||
@@ -134,7 +135,6 @@ pid = /var/run/libra/libra_admin_api.pid
|
|||||||
#stats_offline_ping_limit = 10
|
#stats_offline_ping_limit = 10
|
||||||
#stats_poll_timeout = 5
|
#stats_poll_timeout = 5
|
||||||
#stats_poll_timeout_retry = 30
|
#stats_poll_timeout_retry = 30
|
||||||
#billing_enable = False
|
|
||||||
#exists_freq = 60
|
#exists_freq = 60
|
||||||
#usage_freq = 60
|
#usage_freq = 60
|
||||||
#stats_freq = 5
|
#stats_freq = 5
|
||||||
|
@@ -86,9 +86,6 @@ cfg.CONF.register_opts(
|
|||||||
cfg.IntOpt('vip_pool_size',
|
cfg.IntOpt('vip_pool_size',
|
||||||
default=10,
|
default=10,
|
||||||
help='Number of hot spare vips to keep in the pool'),
|
help='Number of hot spare vips to keep in the pool'),
|
||||||
cfg.BoolOpt('billing_enable',
|
|
||||||
default=False,
|
|
||||||
help='Enable / Disable billing notifications'),
|
|
||||||
cfg.BoolOpt('stats_enable',
|
cfg.BoolOpt('stats_enable',
|
||||||
default=False,
|
default=False,
|
||||||
help='Enable / Disable usage statistics gathering'),
|
help='Enable / Disable usage statistics gathering'),
|
||||||
|
@@ -119,7 +119,7 @@ class MaintThreads(object):
|
|||||||
usage = UsageStats(self.drivers)
|
usage = UsageStats(self.drivers)
|
||||||
self.classes.append(usage)
|
self.classes.append(usage)
|
||||||
|
|
||||||
if CONF['admin_api'].billing_enable:
|
if CONF['billing_enable']:
|
||||||
billing = BillingStats(self.drivers)
|
billing = BillingStats(self.drivers)
|
||||||
self.classes.append(billing)
|
self.classes.append(billing)
|
||||||
|
|
||||||
|
@@ -37,7 +37,6 @@ class UsageStats(object):
|
|||||||
self.server_id = cfg.CONF['admin_api']['server_id']
|
self.server_id = cfg.CONF['admin_api']['server_id']
|
||||||
self.number_of_servers = cfg.CONF['admin_api']['number_of_servers']
|
self.number_of_servers = cfg.CONF['admin_api']['number_of_servers']
|
||||||
self.stats_freq = cfg.CONF['admin_api'].stats_freq
|
self.stats_freq = cfg.CONF['admin_api'].stats_freq
|
||||||
self.billing_enable = cfg.CONF['admin_api'].billing_enable
|
|
||||||
|
|
||||||
self.start_stats_sched()
|
self.start_stats_sched()
|
||||||
|
|
||||||
|
@@ -33,7 +33,6 @@ from libra.common.exc import ExhaustedError
|
|||||||
from libra.api.model.validators import LBPut, LBPost, LBResp, LBVipResp
|
from libra.api.model.validators import LBPut, LBPost, LBResp, LBVipResp
|
||||||
from libra.api.model.validators import LBRespNode
|
from libra.api.model.validators import LBRespNode
|
||||||
from libra.common.api.gearman_client import submit_job
|
from libra.common.api.gearman_client import submit_job
|
||||||
from libra.common.api.mnb import update_mnb
|
|
||||||
from libra.api.acl import get_limited_to_project
|
from libra.api.acl import get_limited_to_project
|
||||||
from libra.api.library.exp import OverLimit, IPOutOfRange, NotFound
|
from libra.api.library.exp import OverLimit, IPOutOfRange, NotFound
|
||||||
from libra.api.library.exp import ImmutableEntity, ImmutableStates
|
from libra.api.library.exp import ImmutableEntity, ImmutableStates
|
||||||
@@ -470,9 +469,6 @@ class LoadBalancersController(RestController):
|
|||||||
'UPDATE', device.name, device.id, lb.id
|
'UPDATE', device.name, device.id, lb.id
|
||||||
)
|
)
|
||||||
|
|
||||||
#Notify billing of the LB creation
|
|
||||||
update_mnb('lbaas.instance.create', lb.id, tenant_id)
|
|
||||||
|
|
||||||
return return_data
|
return return_data
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, body=LBPut, status_code=202)
|
@wsme_pecan.wsexpose(None, body=LBPut, status_code=202)
|
||||||
@@ -584,8 +580,6 @@ class LoadBalancersController(RestController):
|
|||||||
'DELETE', device.name, device.id, lb.id
|
'DELETE', device.name, device.id, lb.id
|
||||||
)
|
)
|
||||||
|
|
||||||
#Notify billing of the LB deletion
|
|
||||||
update_mnb('lbaas.instance.delete', lb.id, tenant_id)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def usage(self, load_balancer_id):
|
def usage(self, load_balancer_id):
|
||||||
|
@@ -19,6 +19,7 @@ from libra.common.json_gearman import JSONGearmanClient
|
|||||||
from libra.common.api.lbaas import LoadBalancer, db_session, Device, Node, Vip
|
from libra.common.api.lbaas import LoadBalancer, db_session, Device, Node, Vip
|
||||||
from libra.common.api.lbaas import HealthMonitor
|
from libra.common.api.lbaas import HealthMonitor
|
||||||
from libra.common.api.lbaas import loadbalancers_devices
|
from libra.common.api.lbaas import loadbalancers_devices
|
||||||
|
from libra.common.api.mnb import update_mnb
|
||||||
from libra.openstack.common import log
|
from libra.openstack.common import log
|
||||||
from pecan import conf
|
from pecan import conf
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ def client_job(job_type, host, data, lbid):
|
|||||||
.format(data)
|
.format(data)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
mnb_data = {}
|
||||||
if not status:
|
if not status:
|
||||||
LOG.error(
|
LOG.error(
|
||||||
"Giving up vip assign for device {0}".format(data)
|
"Giving up vip assign for device {0}".format(data)
|
||||||
@@ -93,10 +94,22 @@ def client_job(job_type, host, data, lbid):
|
|||||||
filter(LoadBalancer.status != 'DELETED').\
|
filter(LoadBalancer.status != 'DELETED').\
|
||||||
all()
|
all()
|
||||||
for lb in lbs:
|
for lb in lbs:
|
||||||
|
if lb.status == 'BUILD':
|
||||||
|
# Only send a create message to MnB if we
|
||||||
|
# are going from BUILD to ACTIVE. After the
|
||||||
|
# DB is updated.
|
||||||
|
mnb_data["lbid"] = lb.id
|
||||||
|
mnb_data["tenantid"] = lb.tenantid
|
||||||
lb.status = 'ACTIVE'
|
lb.status = 'ACTIVE'
|
||||||
device.status = 'ONLINE'
|
device.status = 'ONLINE'
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
# Send the MnB create if needed
|
||||||
|
if "lbid" in mnb_data:
|
||||||
|
update_mnb('lbaas.instance.create',
|
||||||
|
mnb_data["lbid"],
|
||||||
|
mnb_data["tenantid"])
|
||||||
|
|
||||||
if job_type == 'REMOVE':
|
if job_type == 'REMOVE':
|
||||||
client.send_remove(data)
|
client.send_remove(data)
|
||||||
return
|
return
|
||||||
@@ -286,6 +299,8 @@ class GearmanClientThread(object):
|
|||||||
)
|
)
|
||||||
self._set_error(data, response, session)
|
self._set_error(data, response, session)
|
||||||
lb.status = 'DELETED'
|
lb.status = 'DELETED'
|
||||||
|
tenant_id = lb.tenantid
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
# Device should never be used again
|
# Device should never be used again
|
||||||
device = session.query(Device).\
|
device = session.query(Device).\
|
||||||
@@ -301,6 +316,9 @@ class GearmanClientThread(object):
|
|||||||
filter(HealthMonitor.lbid == lb.id).delete()
|
filter(HealthMonitor.lbid == lb.id).delete()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
#Notify billing of the LB deletion
|
||||||
|
update_mnb('lbaas.instance.delete', self.lbid, tenant_id)
|
||||||
|
|
||||||
def _set_error(self, device_id, errmsg, session):
|
def _set_error(self, device_id, errmsg, session):
|
||||||
lbs = session.query(
|
lbs = session.query(
|
||||||
LoadBalancer
|
LoadBalancer
|
||||||
@@ -426,6 +444,7 @@ class GearmanClientThread(object):
|
|||||||
job_data['loadBalancers'].append(lb_data)
|
job_data['loadBalancers'].append(lb_data)
|
||||||
|
|
||||||
# Update the worker
|
# Update the worker
|
||||||
|
mnb_data = {}
|
||||||
status, response = self._send_message(job_data, 'hpcs_response')
|
status, response = self._send_message(job_data, 'hpcs_response')
|
||||||
if not status:
|
if not status:
|
||||||
self._set_error(data, response, session)
|
self._set_error(data, response, session)
|
||||||
@@ -443,6 +462,13 @@ class GearmanClientThread(object):
|
|||||||
# floating IP assign finishes
|
# floating IP assign finishes
|
||||||
if len(lbs) > 1:
|
if len(lbs) > 1:
|
||||||
lb.status = 'ACTIVE'
|
lb.status = 'ACTIVE'
|
||||||
|
if lb.id == self.lbid:
|
||||||
|
# This is the new LB being added to a device.
|
||||||
|
# We don't have to assign a vip so we can
|
||||||
|
# notify billing of the LB creation (once the
|
||||||
|
# DB is updated)
|
||||||
|
mnb_data["lbid"] = lb.id
|
||||||
|
mnb_data["tenantid"] = lb.tenantid
|
||||||
else:
|
else:
|
||||||
lb.status = 'ACTIVE'
|
lb.status = 'ACTIVE'
|
||||||
lb.errmsg = None
|
lb.errmsg = None
|
||||||
@@ -463,6 +489,12 @@ class GearmanClientThread(object):
|
|||||||
'ASSIGN', device_name, None
|
'ASSIGN', device_name, None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Send the MnB create if needed
|
||||||
|
if "lbid" in mnb_data:
|
||||||
|
update_mnb('lbaas.instance.create',
|
||||||
|
mnb_data["lbid"],
|
||||||
|
mnb_data["tenantid"])
|
||||||
|
|
||||||
def _send_message(self, message, response_name):
|
def _send_message(self, message, response_name):
|
||||||
job_status = self.gearman_client.submit_job(
|
job_status = self.gearman_client.submit_job(
|
||||||
self.host, message, background=False, wait_until_complete=True,
|
self.host, message, background=False, wait_until_complete=True,
|
||||||
|
@@ -16,7 +16,7 @@ import datetime
|
|||||||
import eventlet
|
import eventlet
|
||||||
eventlet.monkey_patch()
|
eventlet.monkey_patch()
|
||||||
|
|
||||||
from oslo.config import cfg
|
from libra.common.options import CONF
|
||||||
from libra.common.api.lbaas import LoadBalancer, db_session
|
from libra.common.api.lbaas import LoadBalancer, db_session
|
||||||
from libra.common.api.lbaas import Stats
|
from libra.common.api.lbaas import Stats
|
||||||
from libra.openstack.common.notifier import api as notifier_api
|
from libra.openstack.common.notifier import api as notifier_api
|
||||||
@@ -31,7 +31,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def update_mnb(event_type, lbid, tenant_id):
|
def update_mnb(event_type, lbid, tenant_id):
|
||||||
eventlet.spawn_n(client_job, event_type, lbid, tenant_id)
|
if CONF['billing_enable']:
|
||||||
|
eventlet.spawn_n(client_job, event_type, lbid, tenant_id)
|
||||||
|
|
||||||
|
|
||||||
def client_job(event_type, lbid, tenant_id):
|
def client_job(event_type, lbid, tenant_id):
|
||||||
@@ -56,7 +57,7 @@ def client_job(event_type, lbid, tenant_id):
|
|||||||
|
|
||||||
|
|
||||||
def _notify(service, event_type, payload):
|
def _notify(service, event_type, payload):
|
||||||
priority = cfg.CONF.default_notification_level
|
priority = CONF['default_notification_level']
|
||||||
publisher_id = notifier_api.publisher_id(service)
|
publisher_id = notifier_api.publisher_id(service)
|
||||||
notifier_api.notify(None, publisher_id, event_type, priority, payload)
|
notifier_api.notify(None, publisher_id, event_type, priority, payload)
|
||||||
|
|
||||||
@@ -143,7 +144,7 @@ def _send_exists(event_type):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Figure out our audit period beging/ending
|
# Figure out our audit period beging/ending
|
||||||
seconds = (cfg.CONF['admin_api'].exists_freq * 60)
|
seconds = (CONF['admin_api']['exists_freq'] * 60)
|
||||||
interval = datetime.timedelta(seconds=seconds)
|
interval = datetime.timedelta(seconds=seconds)
|
||||||
audit_period_ending = timeutils.utcnow()
|
audit_period_ending = timeutils.utcnow()
|
||||||
audit_period_beginning = audit_period_ending - interval
|
audit_period_beginning = audit_period_ending - interval
|
||||||
@@ -172,7 +173,7 @@ def _send_exists(event_type):
|
|||||||
def _send_usage(event_type, start, stop):
|
def _send_usage(event_type, start, stop):
|
||||||
|
|
||||||
LOG.info("Sending MnB {0} notifications to MnB".format(event_type))
|
LOG.info("Sending MnB {0} notifications to MnB".format(event_type))
|
||||||
N = cfg.CONF['admin_api'].usage_freq
|
N = CONF['admin_api']['usage_freq']
|
||||||
|
|
||||||
with db_session() as session:
|
with db_session() as session:
|
||||||
|
|
||||||
@@ -283,8 +284,8 @@ def _send_usage(event_type, start, stop):
|
|||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
# Purge old stats
|
# Purge old stats
|
||||||
if cfg.CONF['admin_api'].stats_purge_enable:
|
if CONF['admin_api']['stats_purge_enable']:
|
||||||
hours = cfg.CONF['admin_api'].stats_purge_days * 24
|
hours = CONF['admin_api']['stats_purge_days'] * 24
|
||||||
delta = datetime.timedelta(hours=hours)
|
delta = datetime.timedelta(hours=hours)
|
||||||
exp = timeutils.utcnow() - delta
|
exp = timeutils.utcnow() - delta
|
||||||
exp_time = exp.strftime('%Y-%m-%d %H:%M:%S')
|
exp_time = exp.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
@@ -25,7 +25,10 @@ common_cli_opts = [
|
|||||||
cfg.StrOpt('group',
|
cfg.StrOpt('group',
|
||||||
help='Group to use for daemon mode'),
|
help='Group to use for daemon mode'),
|
||||||
cfg.StrOpt('user',
|
cfg.StrOpt('user',
|
||||||
help='User to use for daemon mode')
|
help='User to use for daemon mode'),
|
||||||
|
cfg.BoolOpt('billing_enable',
|
||||||
|
default=False,
|
||||||
|
help='Enable or disable MnB notifictions')
|
||||||
]
|
]
|
||||||
|
|
||||||
gearman_opts = [
|
gearman_opts = [
|
||||||
|
Reference in New Issue
Block a user