Exemple #1
0
def main():
    objects.register_all()
    CONF(sys.argv[1:], project='sgservice',
         version=version.version_string())
    logging.setup(CONF, "sgservice")
    server = service.Service.create(binary='sgservice-controller')
    service.serve(server)
    service.wait()
Exemple #2
0
def main():
    objects.register_all()
    CONF(sys.argv[1:], project='sgservice', version=version.version_string())
    logging.setup(CONF, "sgservice")

    rpc.init(CONF)
    launcher = service.process_launcher()
    server = service.WSGIService('osapi_sgservice')
    launcher.launch_service(server, workers=server.workers)
    launcher.wait()
Exemple #3
0
def main():
    """Parse options and call the appropriate class/method."""
    objects.register_all()
    CONF.register_cli_opt(category_opt)
    script_name = sys.argv[0]
    if len(sys.argv) < 2:
        print(
            _("\nHuawei Stroage Gateway Service 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='sgservice',
             version=version.version_string())
        logging.setup(CONF, "sgservice")
    except cfg.ConfigDirNotFoundError as details:
        print(_("Invalid directory: %s") % details)
        sys.exit(2)
    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, Please try running this"
                  "command again as root/Administrator privilege"
                  "using 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 sgservice-manage as root.'))
        sys.exit(2)

    fn = CONF.category.action_fn
    fn_args = fetch_func_args(fn)
    fn(*fn_args)
Exemple #4
0
    def test_main(self, log_setup, rpc_init, process_launcher, wsgi_service):
        launcher = process_launcher.return_value
        server = wsgi_service.return_value
        server.workers = mock.sentinel.worker_count

        karbor_api.main()

        self.assertEqual('sgservice', CONF.project)
        self.assertEqual(CONF.version, version.version_string())
        log_setup.assert_called_once_with(CONF, "sgservice")
        rpc_init.assert_called_once_with(CONF)
        process_launcher.assert_called_once_with()
        wsgi_service.assert_called_once_with('osapi_sgservice')
        launcher.launch_service.assert_called_once_with(server,
                                                        workers=server.workers)
        launcher.wait.assert_called_once_with()
Exemple #5
0
    def start(self):
        version_string = version.version_string()
        LOG.info(_LI('Starting %(topic)s node (version %(version_string)s)'),
                 {'topic': self.topic, 'version_string': version_string})
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt,
                                                 self.host,
                                                 self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        self.manager.init_host(service_id=self.service_id)

        LOG.debug("Creating RPC server for service %s", self.topic)

        target = messaging.Target(topic=self.topic, server=self.host)
        endpoints = [self.manager]
        endpoints.extend(self.manager.additional_endpoints)
        serializer = objects_base.SGServiceObjectSerializer()
        self.rpcserver = rpc.get_server(target, endpoints, serializer)
        self.rpcserver.start()

        self.manager.init_host_with_rpc()

        if self.report_interval:
            pulse = loopingcall.FixedIntervalLoopingCall(
                self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = loopingcall.FixedIntervalLoopingCall(
                self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
Exemple #6
0
 def service_version(self):
     return version.version_string()
Exemple #7
0
 def setUp(self):
     super(TestSGServiceApiCmd, self).setUp()
     sys.argv = ['sgservice-api']
     CONF(sys.argv[1:],
          project='sgservice',
          version=version.version_string())
Exemple #8
0
 def list(self):
     print(version.version_string())