예제 #1
0
def main():
    """Parse options and call the appropriate class/method."""
    CONF.register_cli_opt(category_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(
            _("\nOpenStack Cinder version: %(version)s\n") %
            {'version': version.version_string()})
        print(script_name + " category action [<args>]")
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        CONF(sys.argv[1:], project='cinder', version=version.version_string())
        logging.setup("cinder")
    except cfg.ConfigFilesNotFoundError:
        cfgfile = CONF.config_file[-1] if CONF.config_file else None
        if cfgfile and not os.access(cfgfile, os.R_OK):
            st = os.stat(cfgfile)
            print(_("Could not read %s. Re-running with sudo") % cfgfile)
            try:
                os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv)
            except Exception:
                print(_('sudo failed, continuing as if nothing happened'))

        print(_('Please re-run cinder-manage as root.'))
        sys.exit(2)

    fn = CONF.category.action_fn
    fn_args = fetch_func_args(fn)
    fn(*fn_args)
예제 #2
0
파일: runner.py 프로젝트: StackOps/cinder
def run():
    # This is a fix to allow the --hide-elapsed flag while accepting
    # arbitrary nosetest flags as well
    argv = [x for x in sys.argv if x != '--hide-elapsed']
    hide_elapsed = argv != sys.argv
    logging.setup("cinder")

    # If any argument looks like a test name but doesn't have "cinder.tests" in
    # front of it, automatically add that so we don't have to type as much
    for i, arg in enumerate(argv):
        if arg.startswith('test_'):
            argv[i] = 'cinder.tests.%s' % arg

    testdir = os.path.abspath(os.path.join("cinder", "tests"))
    c = config.Config(stream=sys.stdout,
                      env=os.environ,
                      verbosity=3,
                      workingDir=testdir,
                      plugins=core.DefaultPluginManager())

    runner = CinderTestRunner(stream=c.stream,
                              verbosity=c.verbosity,
                              config=c,
                              show_elapsed=not hide_elapsed)
    sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
예제 #3
0
def main():
    CONF(sys.argv[1:], project='cinder', version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()
    server = service.Service.create(binary='cinder-scheduler')
    service.serve(server)
    service.wait()
예제 #4
0
파일: manage.py 프로젝트: NeCTAR-RC/cinder
def main():
    """Parse options and call the appropriate class/method."""
    CONF.register_cli_opt(category_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(_("\nOpenStack Cinder version: %(version)s\n") % {"version": version.version_string()})
        print(script_name + " category action [<args>]")
        print(_("Available categories:"))
        for category in CATEGORIES:
            print(_("\t%s") % category)
        sys.exit(2)

    try:
        CONF(sys.argv[1:], project="cinder", version=version.version_string())
        logging.setup("cinder")
    except cfg.ConfigFilesNotFoundError:
        cfgfile = CONF.config_file[-1] if CONF.config_file else None
        if cfgfile and not os.access(cfgfile, os.R_OK):
            st = os.stat(cfgfile)
            print(_("Could not read %s. Re-running with sudo") % cfgfile)
            try:
                os.execvp("sudo", ["sudo", "-u", "#%s" % st.st_uid] + sys.argv)
            except Exception:
                print(_("sudo failed, continuing as if nothing happened"))

        print(_("Please re-run cinder-manage as root."))
        sys.exit(2)

    fn = CONF.category.action_fn
    fn_args = fetch_func_args(fn)
    fn(*fn_args)
예제 #5
0
def main():
    CONF(sys.argv[1:], project='oslo')
    logging.setup("oslo")

    with contextlib.closing(impl_zmq.ZmqProxy(CONF)) as reactor:
        reactor.consume_in_thread()
        reactor.wait()
예제 #6
0
def main():
    CONF(sys.argv[1:], project="cinder", version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()
    server = service.Service.create(binary="cinder-backup")
    service.serve(server)
    service.wait()
예제 #7
0
파일: runner.py 프로젝트: tizzybec/cinder
def run():
    # This is a fix to allow the --hide-elapsed flag while accepting
    # arbitrary nosetest flags as well
    argv = [x for x in sys.argv if x != '--hide-elapsed']
    hide_elapsed = argv != sys.argv
    logging.setup("cinder")

    # If any argument looks like a test name but doesn't have "cinder.tests" in
    # front of it, automatically add that so we don't have to type as much
    for i, arg in enumerate(argv):
        if arg.startswith('test_'):
            argv[i] = 'cinder.tests.%s' % arg

    testdir = os.path.abspath(os.path.join("cinder", "tests"))
    c = config.Config(stream=sys.stdout,
                      env=os.environ,
                      verbosity=3,
                      workingDir=testdir,
                      plugins=core.DefaultPluginManager())

    runner = CinderTestRunner(stream=c.stream,
                              verbosity=c.verbosity,
                              config=c,
                              show_elapsed=not hide_elapsed)
    sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
예제 #8
0
def main():
    CONF(sys.argv[1:], project='cinder', version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()

    rpc.init(CONF)
    launcher = service.process_launcher()
    server = service.WSGIService('osapi_volume')
    launcher.launch_service(server, workers=server.workers)
    launcher.wait()
예제 #9
0
파일: api.py 프로젝트: NxtCloud/cinder
def main():
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()

    rpc.init(CONF)
    launcher = service.process_launcher()
    server = service.WSGIService('osapi_volume')
    launcher.launch_service(server, workers=server.workers)
    launcher.wait()
예제 #10
0
파일: volume.py 프로젝트: sasimpson/cinder
def main():
    CONF(sys.argv[1:], project='cinder', version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()
    launcher = service.get_launcher()
    if CONF.enabled_backends:
        for backend in CONF.enabled_backends:
            CONF.register_opt(host_opt, group=backend)
            backend_host = getattr(CONF, backend).backend_host
            host = "%s@%s" % (backend_host or CONF.host, backend)
            server = service.Service.create(host=host,
                                            service_name=backend,
                                            binary='cinder-volume')
            launcher.launch_service(server)
    else:
        server = service.Service.create(binary='cinder-volume')
        launcher.launch_service(server)
    launcher.wait()
예제 #11
0
    def test_error_notification(self):
        self.stubs.Set(cinder.flags.FLAGS, 'notification_driver',
            'cinder.notifier.rabbit_notifier')
        self.stubs.Set(cinder.flags.FLAGS, 'publish_errors', True)
        LOG = logging.getLogger('cinder')
        logging.setup("cinder")
        msgs = []

        def mock_notify(context, topic, data):
            msgs.append(data)

        self.stubs.Set(cinder.openstack.common.rpc, 'notify', mock_notify)
        LOG.error('foo')
        self.assertEqual(1, len(msgs))
        msg = msgs[0]
        self.assertEqual(msg['event_type'], 'error_notification')
        self.assertEqual(msg['priority'], 'ERROR')
        self.assertEqual(msg['payload']['error'], 'foo')
예제 #12
0
파일: volume.py 프로젝트: Qeas/cinder
def main():
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup("cinder")
    utils.monkey_patch()
    launcher = service.get_launcher()
    if CONF.enabled_backends:
        for backend in CONF.enabled_backends:
            CONF.register_opt(host_opt, group=backend)
            backend_host = getattr(CONF, backend).backend_host
            host = "%s@%s" % (backend_host or CONF.host, backend)
            server = service.Service.create(host=host,
                                            service_name=backend,
                                            binary='cinder-volume')
            launcher.launch_service(server)
    else:
        server = service.Service.create(binary='cinder-volume')
        launcher.launch_service(server)
    launcher.wait()
예제 #13
0
파일: all.py 프로젝트: sasimpson/cinder
def main():
    CONF(sys.argv[1:], project='cinder', version=version.version_string())
    logging.setup("cinder")
    LOG = logging.getLogger('cinder.all')

    utils.monkey_patch()
    launcher = service.process_launcher()
    # cinder-api
    try:
        server = service.WSGIService('osapi_volume')
        launcher.launch_service(server, workers=server.workers or 1)
    except (Exception, SystemExit):
        LOG.exception(_LE('Failed to load osapi_volume'))

    for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
        try:
            launcher.launch_service(service.Service.create(binary=binary))
        except (Exception, SystemExit):
            LOG.exception(_LE('Failed to load %s'), binary)
    launcher.wait()
예제 #14
0
파일: all.py 프로젝트: Qeas/cinder
def main():
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup("cinder")
    LOG = logging.getLogger('cinder.all')

    utils.monkey_patch()
    launcher = service.process_launcher()
    # cinder-api
    try:
        server = service.WSGIService('osapi_volume')
        launcher.launch_service(server, workers=server.workers or 1)
    except (Exception, SystemExit):
        LOG.exception(_LE('Failed to load osapi_volume'))

    for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
        try:
            launcher.launch_service(service.Service.create(binary=binary))
        except (Exception, SystemExit):
            LOG.exception(_LE('Failed to load %s'), binary)
    launcher.wait()
예제 #15
0
import sys
from cinder.openstack.common import log as logging
from paste import deploy
from cinder import flags

flags.parse_args(sys.argv)
logging.setup("cinder")

conf = '/etc/cinder/api-paste.ini'
name = "osapi_volume"

application = deploy.loadapp('config:%s' % conf, name=name)
예제 #16
0
def main():
    admin_context = context.get_admin_context()
    CONF(sys.argv[1:], project='cinder',
         version=version.version_string())
    logging.setup("cinder")
    LOG = logging.getLogger("cinder")
    rpc.init(CONF)
    begin, end = utils.last_completed_audit_period()
    if CONF.start_time:
        begin = datetime.strptime(CONF.start_time, "%Y-%m-%d %H:%M:%S")
    if CONF.end_time:
        end = datetime.strptime(CONF.end_time, "%Y-%m-%d %H:%M:%S")
    if not end > begin:
        msg = _("The end time (%(end)s) must be after the start "
                "time (%(start)s).") % {'start': begin,
                                        'end': end}
        print(msg)
        LOG.error(msg)
        sys.exit(-1)
    print(_("Starting volume usage audit"))
    msg = _("Creating usages for %(begin_period)s until %(end_period)s")
    print(msg % {"begin_period": str(begin), "end_period": str(end)})

    extra_info = {
        'audit_period_beginning': str(begin),
        'audit_period_ending': str(end),
    }

    volumes = db.volume_get_active_by_window(admin_context,
                                             begin,
                                             end)
    print(_("Found %d volumes") % len(volumes))
    for volume_ref in volumes:
        try:
            LOG.debug("Send exists notification for <volume_id: "
                      "%(volume_id)s> <project_id %(project_id)s> "
                      "<%(extra_info)s>" %
                      {'volume_id': volume_ref.id,
                       'project_id': volume_ref.project_id,
                       'extra_info': extra_info})
            cinder.volume.utils.notify_about_volume_usage(
                admin_context,
                volume_ref,
                'exists', extra_usage_info=extra_info)
        except Exception as e:
            LOG.error(_LE("Failed to send exists notification"
                          " for volume %s.") %
                      volume_ref.id)
            print(traceback.format_exc(e))

        if (CONF.send_actions and
                volume_ref.created_at > begin and
                volume_ref.created_at < end):
            try:
                local_extra_info = {
                    'audit_period_beginning': str(volume_ref.created_at),
                    'audit_period_ending': str(volume_ref.created_at),
                }
                LOG.debug("Send create notification for "
                          "<volume_id: %(volume_id)s> "
                          "<project_id %(project_id)s> <%(extra_info)s>" %
                          {'volume_id': volume_ref.id,
                           'project_id': volume_ref.project_id,
                           'extra_info': local_extra_info})
                cinder.volume.utils.notify_about_volume_usage(
                    admin_context,
                    volume_ref,
                    'create.start', extra_usage_info=local_extra_info)
                cinder.volume.utils.notify_about_volume_usage(
                    admin_context,
                    volume_ref,
                    'create.end', extra_usage_info=local_extra_info)
            except Exception as e:
                LOG.error(_LE("Failed to send create notification for "
                              "volume %s.") % volume_ref.id)
                print(traceback.format_exc(e))

        if (CONF.send_actions and volume_ref.deleted_at and
                volume_ref.deleted_at > begin and
                volume_ref.deleted_at < end):
            try:
                local_extra_info = {
                    'audit_period_beginning': str(volume_ref.deleted_at),
                    'audit_period_ending': str(volume_ref.deleted_at),
                }
                LOG.debug("Send delete notification for "
                          "<volume_id: %(volume_id)s> "
                          "<project_id %(project_id)s> <%(extra_info)s>" %
                          {'volume_id': volume_ref.id,
                           'project_id': volume_ref.project_id,
                           'extra_info': local_extra_info})
                cinder.volume.utils.notify_about_volume_usage(
                    admin_context,
                    volume_ref,
                    'delete.start', extra_usage_info=local_extra_info)
                cinder.volume.utils.notify_about_volume_usage(
                    admin_context,
                    volume_ref,
                    'delete.end', extra_usage_info=local_extra_info)
            except Exception as e:
                LOG.error(_LE("Failed to send delete notification for volume "
                              "%s.") % volume_ref.id)
                print(traceback.format_exc(e))

    snapshots = db.snapshot_get_active_by_window(admin_context,
                                                 begin,
                                                 end)
    print(_("Found %d snapshots") % len(snapshots))
    for snapshot_ref in snapshots:
        try:
            LOG.debug("Send notification for <snapshot_id: %(snapshot_id)s> "
                      "<project_id %(project_id)s> <%(extra_info)s>" %
                      {'snapshot_id': snapshot_ref.id,
                       'project_id': snapshot_ref.project_id,
                       'extra_info': extra_info})
            cinder.volume.utils.notify_about_snapshot_usage(admin_context,
                                                            snapshot_ref,
                                                            'exists',
                                                            extra_info)
        except Exception as e:
            LOG.error(_LE("Failed to send exists notification "
                          "for snapshot %s.")
                      % snapshot_ref.id)
            print(traceback.format_exc(e))

        if (CONF.send_actions and
                snapshot_ref.created_at > begin and
                snapshot_ref.created_at < end):
            try:
                local_extra_info = {
                    'audit_period_beginning': str(snapshot_ref.created_at),
                    'audit_period_ending': str(snapshot_ref.created_at),
                }
                LOG.debug("Send create notification for "
                          "<snapshot_id: %(snapshot_id)s> "
                          "<project_id %(project_id)s> <%(extra_info)s>" %
                          {'snapshot_id': snapshot_ref.id,
                           'project_id': snapshot_ref.project_id,
                           'extra_info': local_extra_info})
                cinder.volume.utils.notify_about_snapshot_usage(
                    admin_context,
                    snapshot_ref,
                    'create.start', extra_usage_info=local_extra_info)
                cinder.volume.utils.notify_about_snapshot_usage(
                    admin_context,
                    snapshot_ref,
                    'create.end', extra_usage_info=local_extra_info)
            except Exception as e:
                LOG.error(_LE("Failed to send create notification for snapshot"
                              "%s.") % snapshot_ref.id)
                print(traceback.format_exc(e))

        if (CONF.send_actions and snapshot_ref.deleted_at and
                snapshot_ref.deleted_at > begin and
                snapshot_ref.deleted_at < end):
            try:
                local_extra_info = {
                    'audit_period_beginning': str(snapshot_ref.deleted_at),
                    'audit_period_ending': str(snapshot_ref.deleted_at),
                }
                LOG.debug("Send delete notification for "
                          "<snapshot_id: %(snapshot_id)s> "
                          "<project_id %(project_id)s> <%(extra_info)s>" %
                          {'snapshot_id': snapshot_ref.id,
                           'project_id': snapshot_ref.project_id,
                           'extra_info': local_extra_info})
                cinder.volume.utils.notify_about_snapshot_usage(
                    admin_context,
                    snapshot_ref,
                    'delete.start', extra_usage_info=local_extra_info)
                cinder.volume.utils.notify_about_snapshot_usage(
                    admin_context,
                    snapshot_ref,
                    'delete.end', extra_usage_info=local_extra_info)
            except Exception as e:
                LOG.error(_LE("Failed to send delete notification for snapshot"
                              "%s.") % snapshot_ref.id)
                print(traceback.format_exc(e))

    print(_("Volume usage audit completed"))