|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright © 2012 eNovance <licensing@enovance.com> |
| 5 | +# |
| 6 | +# Author: Julien Danjou <julien@danjou.info> |
| 7 | +# |
| 8 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | +# not use this file except in compliance with the License. You may obtain |
| 10 | +# a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 17 | +# License for the specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +import os |
| 21 | +import socket |
| 22 | + |
| 23 | +from billingstack.openstack.common import cfg |
| 24 | +from billingstack.openstack.common import rpc |
| 25 | +from billingstack.openstack.common import context |
| 26 | +from billingstack.openstack.common import log |
| 27 | +from billingstack.openstack.common.rpc import service as rpc_service |
| 28 | + |
| 29 | + |
| 30 | +cfg.CONF.register_opts([ |
| 31 | + cfg.IntOpt('periodic_interval', |
| 32 | + default=600, |
| 33 | + help='seconds between running periodic tasks'), |
| 34 | + cfg.StrOpt('host', |
| 35 | + default=socket.getfqdn(), |
| 36 | + help='Name of this node. This can be an opaque identifier. ' |
| 37 | + 'It is not necessarily a hostname, FQDN, or IP address. ' |
| 38 | + 'However, the node name must be valid within ' |
| 39 | + 'an AMQP key, and if using ZeroMQ, a valid ' |
| 40 | + 'hostname, FQDN, or IP address'), |
| 41 | +]) |
| 42 | + |
| 43 | + |
| 44 | +class PeriodicService(rpc_service.Service): |
| 45 | + |
| 46 | + def start(self): |
| 47 | + super(PeriodicService, self).start() |
| 48 | + admin_context = context.RequestContext('admin', 'admin', is_admin=True) |
| 49 | + self.tg.add_timer(cfg.CONF.periodic_interval, |
| 50 | + self.manager.periodic_tasks, |
| 51 | + context=admin_context) |
| 52 | + |
| 53 | + |
| 54 | +def _sanitize_cmd_line(argv): |
| 55 | + """Remove non-nova CLI options from argv.""" |
| 56 | + cli_opt_names = ['--%s' % o.name for o in CLI_OPTIONS] |
| 57 | + return [a for a in argv if a in cli_opt_names] |
| 58 | + |
| 59 | + |
| 60 | +def prepare_service(argv=[]): |
| 61 | + rpc.set_defaults(control_exchange='billingstack') |
| 62 | + cfg.CONF(argv[1:], project='billingstack') |
| 63 | + log.setup('billingstack') |
0 commit comments