def main(args=None): """ Main entry point for the ``ceph-volume-systemd`` executable. ``args`` are optional for easier testing of arguments. Expected input is similar to:: ['/path/to/ceph-volume-systemd', '<type>-<extra metadata>'] For example:: [ '/usr/bin/ceph-volume-systemd', 'lvm-0-8715BEB4-15C5-49DE-BA6F-401086EC7B41' ] The first part of the argument is the only interesting bit, which contains the metadata needed to proxy the call to ``ceph-volume`` itself. Reusing the example, the proxy call to ``ceph-volume`` would look like:: ceph-volume lvm trigger 0-8715BEB4-15C5-49DE-BA6F-401086EC7B41 That means that ``lvm`` is used as the subcommand and it is **expected** that a ``trigger`` sub-commmand will be present to make sense of the extra piece of the string. """ log.setup(name='ceph-volume-systemd.log', log_path='/var/log/ceph/ceph-volume-systemd.log') logger = logging.getLogger('systemd') args = args if args is not None else sys.argv try: suffix = args[-1] except IndexError: raise RuntimeError('no arguments supplied') sub_command = parse_subcommand(suffix) extra_data = parse_extra_data(suffix) logger.info('raw systemd input received: %s', suffix) logger.info('parsed sub-command: %s, extra data: %s', sub_command, extra_data) command = ['ceph-volume', sub_command, 'trigger', extra_data] tries = int(os.environ.get('CEPH_VOLUME_SYSTEMD_TRIES', 30)) interval = int(os.environ.get('CEPH_VOLUME_SYSTEMD_INTERVAL', 5)) while tries > 0: try: # don't log any output to the terminal, just rely on stderr/stdout # going to logging process.run(command, terminal_logging=False) logger.info('successfully triggered activation for: %s', extra_data) break except RuntimeError as error: logger.warning(error) logger.warning('failed activating OSD, retries left: %s', tries) tries -= 1 time.sleep(interval)
def main(args=None): """ Main entry point for the ``ceph-volume-systemd`` executable. ``args`` are optional for easier testing of arguments. Expected input is similar to:: ['/path/to/ceph-volume-systemd', '<osd id>-<osd uuid>-<device type>'] ['/path/to/ceph-volume-systemd', '<type>-<extra metadata>'] For example:: [ '/usr/bin/ceph-volume-systemd', 'lvm-0-8715BEB4-15C5-49DE-BA6F-401086EC7B41' ] The first part of the argument is the only interesting bit, which contains the metadata needed to proxy the call to ``ceph-volume`` itself. Reusing the example, the proxy call to ``ceph-volume`` would look like:: ceph-volume lvm trigger 0-8715BEB4-15C5-49DE-BA6F-401086EC7B41 That means that ``lvm`` is used as the subcommand and it is **expected** that a ``trigger`` sub-commmand will be present to make sense of the extra piece of the string. """ log.setup(name='ceph-volume-systemd.log', log_path='/var/log/ceph/ceph-volume-systemd.log') logger = logging.getLogger('systemd') args = args if args is not None else sys.argv try: suffix = args[-1] except IndexError: raise RuntimeError('no arguments supplied') sub_command = parse_subcommand(suffix) extra_data = parse_extra_data(suffix) logger.info('raw systemd input received: %s', suffix) logger.info('parsed sub-command: %s, extra data: %s', sub_command, extra_data) command = ['ceph-volume', sub_command, 'trigger', extra_data] tries = os.environ.get('CEPH_VOLUME_SYSTEMD_TRIES', 30) interval = os.environ.get('CEPH_VOLUME_SYSTEMD_INTERVAL', 5) while tries > 0: try: # don't log any output to the terminal, just rely on stderr/stdout # going to logging process.run(command, terminal_logging=False) logger.info('successfully trggered activation for: %s', extra_data) break except RuntimeError as error: logger.warning(error) logger.warning('failed activating OSD, retries left: %s', tries) tries -= 1 time.sleep(interval)
def main(self, argv): # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() self.enable_plugins() main_args, subcommand_args = self._get_split_args() # no flags where passed in, return the help menu instead of waiting for # argparse which will end up complaning that there are no args if len(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume.log') log.setup() logger = logging.getLogger(__name__) logger.info("Running command: ceph-volume %s %s", " ".join(main_args), " ".join(subcommand_args)) # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) try: conf.ceph = configuration.load(conf.path) except exceptions.ConfigurationError as error: is_help = "-h" in subcommand_args or "--help" in subcommand_args if " ".join(subcommand_args[:2]) in IGNORE_CEPH_CONFIG_COMMANDS or is_help: # we warn only here, because it is possible that the configuration # file is not needed, or that it will be loaded by some other means # (like reading from lvm tags) logger.exception('ignoring inability to load ceph.conf') terminal.red(error) else: terminal.red(error) raise # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)
def main(self, argv): self.load_ceph_conf_path() # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() main_args, subcommand_args = self._get_split_args() # no flags where passed in, return the help menu instead of waiting for # argparse which will end up complaning that there are no args if len(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume-zfs', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume-zfs.log') log.setup() logger = logging.getLogger(__name__) logger.info("Running command: ceph-volume-zfs %s %s", " ".join(main_args), " ".join(subcommand_args)) # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) try: conf.ceph = configuration.load(conf.path) except exceptions.ConfigurationError as error: # we warn only here, because it is possible that the configuration # file is not needed, or that it will be loaded by some other means # (like reading from zfs tags) logger.exception('ignoring inability to load ceph.conf') terminal.red(error) # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)
def main(self, argv): # these need to be available for the help, which gets parsed super # early self.load_ceph_conf_path() self.load_log_path() self.enable_plugins() main_args, subcommand_args = self._get_split_args() # no flags where passed in, return the help menu instead of waiting for # argparse which will end up complaning that there are no args if len(argv) <= 1: print(self.help(warning=True)) return parser = argparse.ArgumentParser( prog='ceph-volume', formatter_class=argparse.RawDescriptionHelpFormatter, description=self.help(), ) parser.add_argument( '--cluster', default='ceph', help='Cluster name (defaults to "ceph")', ) parser.add_argument( '--log-level', default='debug', help='Change the file log level (defaults to debug)', ) parser.add_argument( '--log-path', default='/var/log/ceph/', help='Change the log path (defaults to /var/log/ceph)', ) args = parser.parse_args(main_args) conf.log_path = args.log_path if os.path.isdir(conf.log_path): conf.log_path = os.path.join(args.log_path, 'ceph-volume.log') log.setup() # set all variables from args and load everything needed according to # them self.load_ceph_conf_path(cluster_name=args.cluster) conf.ceph = configuration.load(conf.path) # dispatch to sub-commands terminal.dispatch(self.mapper, subcommand_args)