[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:
parent
84de5791b3
commit
e66c35175f
|
@ -17,6 +17,7 @@
|
|||
#daemon = true
|
||||
#user = libra
|
||||
#group = libra
|
||||
#billing_enable = False
|
||||
|
||||
# Other logging options
|
||||
#syslog = false
|
||||
|
@ -134,7 +135,6 @@ pid = /var/run/libra/libra_admin_api.pid
|
|||
#stats_offline_ping_limit = 10
|
||||
#stats_poll_timeout = 5
|
||||
#stats_poll_timeout_retry = 30
|
||||
#billing_enable = False
|
||||
#exists_freq = 60
|
||||
#usage_freq = 60
|
||||
#stats_freq = 5
|
||||
|
|
|
@ -86,9 +86,6 @@ cfg.CONF.register_opts(
|
|||
cfg.IntOpt('vip_pool_size',
|
||||
default=10,
|
||||
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',
|
||||
default=False,
|
||||
help='Enable / Disable usage statistics gathering'),
|
||||
|
|
|
@ -119,7 +119,7 @@ class MaintThreads(object):
|
|||
usage = UsageStats(self.drivers)
|
||||
self.classes.append(usage)
|
||||
|
||||
if CONF['admin_api'].billing_enable:
|
||||
if CONF['billing_enable']:
|
||||
billing = BillingStats(self.drivers)
|
||||
self.classes.append(billing)
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ class UsageStats(object):
|
|||
self.server_id = cfg.CONF['admin_api']['server_id']
|
||||
self.number_of_servers = cfg.CONF['admin_api']['number_of_servers']
|
||||
self.stats_freq = cfg.CONF['admin_api'].stats_freq
|
||||
self.billing_enable = cfg.CONF['admin_api'].billing_enable
|
||||
|
||||
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 LBRespNode
|
||||
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.library.exp import OverLimit, IPOutOfRange, NotFound
|
||||
from libra.api.library.exp import ImmutableEntity, ImmutableStates
|
||||
|
@ -470,9 +469,6 @@ class LoadBalancersController(RestController):
|
|||
'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
|
||||
|
||||
@wsme_pecan.wsexpose(None, body=LBPut, status_code=202)
|
||||
|
@ -584,8 +580,6 @@ class LoadBalancersController(RestController):
|
|||
'DELETE', device.name, device.id, lb.id
|
||||
)
|
||||
|
||||
#Notify billing of the LB deletion
|
||||
update_mnb('lbaas.instance.delete', lb.id, tenant_id)
|
||||
return None
|
||||
|
||||
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 HealthMonitor
|
||||
from libra.common.api.lbaas import loadbalancers_devices
|
||||
from libra.common.api.mnb import update_mnb
|
||||
from libra.openstack.common import log
|
||||
from pecan import conf
|
||||
|
||||
|
@ -77,7 +78,7 @@ def client_job(job_type, host, data, lbid):
|
|||
.format(data)
|
||||
)
|
||||
return
|
||||
|
||||
mnb_data = {}
|
||||
if not status:
|
||||
LOG.error(
|
||||
"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').\
|
||||
all()
|
||||
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'
|
||||
device.status = 'ONLINE'
|
||||
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':
|
||||
client.send_remove(data)
|
||||
return
|
||||
|
@ -286,6 +299,8 @@ class GearmanClientThread(object):
|
|||
)
|
||||
self._set_error(data, response, session)
|
||||
lb.status = 'DELETED'
|
||||
tenant_id = lb.tenantid
|
||||
|
||||
if count == 0:
|
||||
# Device should never be used again
|
||||
device = session.query(Device).\
|
||||
|
@ -301,6 +316,9 @@ class GearmanClientThread(object):
|
|||
filter(HealthMonitor.lbid == lb.id).delete()
|
||||
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):
|
||||
lbs = session.query(
|
||||
LoadBalancer
|
||||
|
@ -426,6 +444,7 @@ class GearmanClientThread(object):
|
|||
job_data['loadBalancers'].append(lb_data)
|
||||
|
||||
# Update the worker
|
||||
mnb_data = {}
|
||||
status, response = self._send_message(job_data, 'hpcs_response')
|
||||
if not status:
|
||||
self._set_error(data, response, session)
|
||||
|
@ -443,6 +462,13 @@ class GearmanClientThread(object):
|
|||
# floating IP assign finishes
|
||||
if len(lbs) > 1:
|
||||
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:
|
||||
lb.status = 'ACTIVE'
|
||||
lb.errmsg = None
|
||||
|
@ -463,6 +489,12 @@ class GearmanClientThread(object):
|
|||
'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):
|
||||
job_status = self.gearman_client.submit_job(
|
||||
self.host, message, background=False, wait_until_complete=True,
|
||||
|
|
|
@ -16,7 +16,7 @@ import datetime
|
|||
import eventlet
|
||||
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 Stats
|
||||
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):
|
||||
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):
|
||||
|
@ -56,7 +57,7 @@ def client_job(event_type, lbid, tenant_id):
|
|||
|
||||
|
||||
def _notify(service, event_type, payload):
|
||||
priority = cfg.CONF.default_notification_level
|
||||
priority = CONF['default_notification_level']
|
||||
publisher_id = notifier_api.publisher_id(service)
|
||||
notifier_api.notify(None, publisher_id, event_type, priority, payload)
|
||||
|
||||
|
@ -143,7 +144,7 @@ def _send_exists(event_type):
|
|||
return
|
||||
|
||||
# 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)
|
||||
audit_period_ending = timeutils.utcnow()
|
||||
audit_period_beginning = audit_period_ending - interval
|
||||
|
@ -172,7 +173,7 @@ def _send_exists(event_type):
|
|||
def _send_usage(event_type, start, stop):
|
||||
|
||||
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:
|
||||
|
||||
|
@ -283,8 +284,8 @@ def _send_usage(event_type, start, stop):
|
|||
count += 1
|
||||
|
||||
# Purge old stats
|
||||
if cfg.CONF['admin_api'].stats_purge_enable:
|
||||
hours = cfg.CONF['admin_api'].stats_purge_days * 24
|
||||
if CONF['admin_api']['stats_purge_enable']:
|
||||
hours = CONF['admin_api']['stats_purge_days'] * 24
|
||||
delta = datetime.timedelta(hours=hours)
|
||||
exp = timeutils.utcnow() - delta
|
||||
exp_time = exp.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
|
|
@ -25,7 +25,10 @@ common_cli_opts = [
|
|||
cfg.StrOpt('group',
|
||||
help='Group to use for daemon mode'),
|
||||
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 = [
|
||||
|
|
Loading…
Reference in New Issue