def __init__(self, context, name='list', description=DESC_LIST, method=None, repos_title=None, other_repos_title=None, include_all_flag=True): self.context = context self.prompt = context.prompt if method is None: method = self.run self.repos_title = repos_title if self.repos_title is None: self.repos_title = _('Repositories') self.other_repos_title = other_repos_title if self.other_repos_title is None: self.other_repos_title = _('Other Pulp Repositories') super(ListRepositoriesCommand, self).__init__(name, description, method) d = _('if specified, a condensed view with just the repository ID and name is displayed') self.add_option(PulpCliFlag('--summary', d, aliases=['-s'])) d = _('if specified, detailed configuration information is displayed for each repository') self.add_option(PulpCliFlag('--details', d)) d = _('comma-separated list of repository fields; if specified, only the given fields will displayed') self.add_option(PulpCliOption('--fields', d, required=False)) self.supports_all = include_all_flag if self.supports_all: d = _('if specified, information on all Pulp repositories, regardless of type, will be displayed') self.add_option(PulpCliFlag('--all', d, aliases=['-a']))
def __init__(self, context, name='list', description=DESC_LIST, method=None): self.context = context self.prompt = context.prompt if method is None: method = self.run super(ListRepositoryGroupsCommand, self).__init__(name, description, method) self.add_option( PulpCliFlag( '--details', _('if specified, all the repo group information ' 'is displayed'))) self.add_option( PulpCliOption('--fields', _('comma-separated list of repo group fields; ' 'Example: "id,description". If specified, ' 'only the given fields will be displayed.'), required=False))
def __init__(self, context): PulpCliSection.__init__(self, 'role', 'manage user roles') self.context = context self.prompt = context.prompt # for easier access # Common Options id_option = PulpCliOption('--role-id', 'uniquely identifies the role; only alphanumeric, -, and _ allowed', required=True, validate_func=validators.id_validator) # Create command create_command = PulpCliCommand('create', 'creates a role', self.create) create_command.add_option(id_option) create_command.add_option(PulpCliOption('--display-name', 'user-friendly name for the role', required=False)) create_command.add_option(PulpCliOption('--description', 'user-friendly text describing the role', required=False)) self.add_command(create_command) # Update command update_command = PulpCliCommand('update', 'updates a role', self.update) update_command.add_option(PulpCliOption('--role-id', 'identifies the role to be updated', required=True)) update_command.add_option(PulpCliOption('--display-name', 'user-friendly name for the role', required=False)) update_command.add_option(PulpCliOption('--description', 'user-friendly text describing the role', required=False)) self.add_command(update_command) # Delete Command delete_command = PulpCliCommand('delete', 'deletes a role', self.delete) delete_command.add_option(PulpCliOption('--role-id', 'identifies the role to be deleted', required=True)) self.add_command(delete_command) # List Command list_command = PulpCliCommand('list', 'lists summary of roles on the Pulp server', self.list) list_command.add_option(PulpCliFlag('--details', 'if specified, all the role information is displayed')) list_command.add_option(PulpCliOption('--fields', 'comma-separated list of role fields; if specified, only the given fields will displayed', required=False)) self.add_command(list_command)
def __init__(self, context): m = _( 'list bindings with consumer actions with a status of pending or failed' ) CriteriaCommand.__init__(self, self.run, 'unconfirmed', m, filtering=False) self.add_flag( PulpCliFlag( '--bind', _('limit search to bindings with unconfirmed bind actions'))) self.add_flag( PulpCliFlag( '--unbind', _('limit search to bindings with unconfirmed unbind actions'))) self.context = context
def __init__(self, context, name, description): PulpCliCommand.__init__(self, name, description, self.unbind) self.context = context self.prompt = context.prompt self.add_option( PulpCliOption('--repo-id', 'repository id', required=True)) self.add_option( PulpCliFlag( '--force', 'delete the binding immediately and discontinue ' 'tracking consumer actions'))
def __init__(self, context): self.context = context self.prompt = context.prompt m = _('remove one or more orphaned units') super(OrphanUnitRemoveCommand, self).__init__('remove', m, self.run) self.add_option(OPTION_TYPE) self.add_option(OPTION_UNIT_ID) m = _('remove all orphaned units, ignoring other options') self.add_flag(PulpCliFlag('--all', m))
def __init__(self, context): self.context = context self.prompt = context.prompt m = _('display a list of orphaned units') super(OrphanUnitListCommand, self).__init__('list', m, self.run) self.add_option(OPTION_TYPE) m = _('include a detailed list of the individual orphaned units, ignored when content ' 'type is not specified') details_flag = PulpCliFlag('--details', m) self.add_flag(details_flag)
def __init__(self, context): PulpCliSection.__init__(self, 'user', 'manage users') self.context = context self.prompt = context.prompt # for easier access # Common Options login_option = PulpCliOption('--login', 'uniquely identifies the user; only alphanumeric, -, ., and _ allowed', required=True, validate_func=validators.id_validator_allow_dots) name_option = PulpCliOption('--name', 'user-readable full name of the user', required=False) # Create command create_command = PulpCliCommand('create', 'creates a user', self.create) create_command.add_option(login_option) create_command.add_option(PulpCliOption('--password', 'password for the new user, if you do not want to be prompted for one', required=False)) create_command.add_option(name_option) self.add_command(create_command) # Update Command update_command = PulpCliCommand('update', 'changes metadata of an existing user', self.update) update_command.add_option(PulpCliOption('--login', 'identifies the user to be updated', required=True)) update_command.add_option(name_option) update_command.add_option(PulpCliOption('--password', 'new password for the user, use -p if you want to be prompted for the password', required=False)) update_command.add_option(PulpCliFlag('-p', 'if specified, you will be prompted to enter new password for the user')) self.add_command(update_command) # Delete Command delete_command = PulpCliCommand('delete', 'deletes a user', self.delete) delete_command.add_option(PulpCliOption('--login', 'identifies the user to be deleted', required=True)) self.add_command(delete_command) # List Command list_command = PulpCliCommand('list', 'lists summary of users registered to the Pulp server', self.list) list_command.add_option(PulpCliFlag('--details', 'if specified, all the user information is displayed')) list_command.add_option(PulpCliOption('--fields', 'comma-separated list of user fields; if specified, only the given fields will displayed', required=False)) self.add_command(list_command) # Search Command self.add_command(CriteriaCommand(self.search, include_search=True))
class DisplayUnitAssociationsCommand(UnitAssociationCriteriaCommand): """ Provides the full suite of unit association criteria flags along with extra flags to control the output of what will be displayed about the associations. The typical usage of this command is when searching or displaying unit associations to the user. """ ASSOCIATION_FLAG = PulpCliFlag('--details', _('show association details'), aliases=['-d']) def __init__(self, method, *args, **kwargs): super(DisplayUnitAssociationsCommand, self).__init__(method, *args, **kwargs) # If we support more than just the details flag in the future, those # options will be added here self.add_flag(self.ASSOCIATION_FLAG)
'be automatically disabled') OPT_FAILURE_THRESHOLD = PulpCliOption( '--failure-threshold', DESC_FAILURE_THRESHOLD, aliases=['-f'], required=False, parse_func=parsers.pulp_parse_optional_positive_int) DESC_ENABLED = _( 'if "false", the schedule will exist but will not trigger any ' 'executions; defaults to true') OPT_ENABLED = PulpCliOption('--enabled', DESC_ENABLED, required=False) DESC_DETAILS = _('if specified, extra information (including its ID) ' 'about the schedule is displayed') FLAG_DETAILS = PulpCliFlag('--details', DESC_DETAILS) DESC_QUIET = _('only output the next time without verbiage around it') FLAG_QUIET = PulpCliFlag('--quiet', DESC_QUIET, aliases=['-q']) _logger = logging.getLogger(__name__) class ListScheduleCommand(PulpCliCommand): """ Displays the schedules returned from the supplied strategy instance. """ def __init__(self, context, strategy, name=NAME_LIST,
from pulp.bindings.responses import Task # Returned from the poll command if one or more of the tasks in the given list # was rejected RESULT_REJECTED = 'rejected' # Returned from the poll command if the user gracefully aborts the polling RESULT_ABORTED = 'aborted' # Returned from the poll command if the user elects to not poll the task RESULT_BACKGROUND = 'background' DESC_BACKGROUND = _('if specified, the client process will end immediately (the task will ' 'continue to run on the server)') FLAG_BACKGROUND = PulpCliFlag('--bg', DESC_BACKGROUND) class PollingCommand(PulpCliCommand): """ Base class for commands that wish to track a task executed on the server. Subclasses should override the rendering methods as appropriate to display custom messages based on the task state or progress. If the poll_frequency_in_seconds is not specified, it will be loaded from the configuration under output -> poll_frequency_in_seconds. :ivar context: the client context :type context: pulp.client.extensions.core.ClientContext """
COLOR_RUNNING = COLOR_GREEN COLOR_PAUSED = COLOR_YELLOW # Command Default Descriptions DESC_UPLOAD = _('uploads one or more units into a repository') DESC_RESUME = _('resume a paused upload request') DESC_LIST = _('lists in-progress and paused uploads') DESC_CANCEL = _('cancels an outstanding upload request') # Options DESC_FORCE = _( 'removes the client-side tracking file for the upload regardless of ' 'whether or not it was able to be deleted on the server; this should ' 'only be used in the event that the server\'s knowledge of an upload ' 'has been removed') FLAG_FORCE = PulpCliFlag('--force', DESC_FORCE) DESC_FILE = _('full path to a file to upload; may be specified multiple times ' 'for multiple files') OPTION_FILE = PulpCliOption('--file', DESC_FILE, aliases=['-f'], allow_multiple=True, required=False) DESC_DIR = _('full path to a directory containing files to upload; ' 'may be specified multiple times for multiple directories') OPTION_DIR = PulpCliOption('--dir', DESC_DIR, aliases=['-d'], allow_multiple=True,
# Command Descriptions DESC_SYNC_RUN = _('triggers an immediate sync of a repository') DESC_SYNC_STATUS = _('displays the status of a repository\'s sync tasks') DESC_PUBLISH_RUN = _('triggers an immediate publish of a repository') DESC_PUBLISH_STATUS = _('displays the status of a repository\'s publish tasks') DESC_DOWNLOAD = _( 'queues a full download of all missing units in a repository ' 'that is using a "background" or "on_demand" download policy.') DESC_VERIFY_ALL_FLAG = _('check all units in the repository for corrupted or ' 'missing files and re-download files as necessary ' 'rather than just downloading files that are known ' 'to be missing.') FLAG_VERIFY_ALL = PulpCliFlag('--verify-all', DESC_VERIFY_ALL_FLAG, aliases=['-a']) class StatusRenderer(object): def __init__(self, context): self.context = context self.prompt = context.prompt def display_report(self, progress_report): raise NotImplementedError() class SyncPublishCommand(polling.PollingCommand): """ This class contains common behaviors found in the sync and publish commands in this module.
'request that no filters be applied.') # -- common options ----------------------------------------------------------- # General Resource OPTION_NAME = PulpCliOption('--display-name', DESC_NAME, required=False) OPTION_DESCRIPTION = PulpCliOption('--description', DESC_DESCRIPTION, required=False) OPTION_NOTES = PulpCliOption('--note', DESC_NOTE, required=False, allow_multiple=True, parse_func=parsers.parse_notes) # IDs OPTION_REPO_ID = PulpCliOption('--repo-id', DESC_ID, required=True, validate_func=validators.id_validator) OPTION_GROUP_ID = PulpCliOption('--group-id', DESC_ID, required=True, validate_func=validators.id_validator) OPTION_CONSUMER_ID = PulpCliOption('--consumer-id', DESC_ID, required=True, validate_func=validators.id_validator) FLAG_ALL = PulpCliFlag('--all', DESC_ALL)
SECTION_ROOT = 'ostree' DESC_ROOT = _('manage ostree repositories') SECTION_REPO = 'repo' DESC_REPO = _('repository lifecycle commands') SECTION_PUBLISH = 'publish' DESC_PUBLISH = _('publish an ostree repository') SECTION_SYNC = 'sync' DESC_SYNC = _('sync a ostree repository from an upstream repository') OPT_REPAIR = PulpCliFlag( '--repair', _("repair a corrupted local repository"), aliases=['-r']) @priority() def initialize(context): """ Create the ostree CLI section and add it to the root :param context: the CLI context. :type context: pulp.client.extensions.core.ClientContext """ root_section = context.cli.create_section(SECTION_ROOT, DESC_ROOT) repo_section = add_repo_section(context, root_section) add_publish_section(context, repo_section) add_sync_section(context, repo_section)
DESC_PUBLISH_STATUS = _('displays the status of a repository\'s publish tasks') DESC_DOWNLOAD = _( 'queues a full download of all missing units in a repository ' 'that is using a "background" or "on_demand" download policy.') DESC_VERIFY_ALL_FLAG = _('check all units in the repository for corrupted or ' 'missing files and re-download files as necessary ' 'rather than just downloading files that are known ' 'to be missing.') DESC_FORCE_FULL_FLAG_PUBLISH = _( 'forces to publish from scratch, even if no changes were ' 'introduced since last publish') DESC_FORCE_FULL_FLAG_SYNC = _( 'forces full re-sync, where all steps are performed.') FLAG_VERIFY_ALL = PulpCliFlag('--verify-all', DESC_VERIFY_ALL_FLAG, aliases=['-a']) FLAG_FORCE_FULL_PUBLISH = PulpCliFlag('--force-full', DESC_FORCE_FULL_FLAG_PUBLISH) FLAG_FORCE_FULL_SYNC = PulpCliFlag('--force-full', DESC_FORCE_FULL_FLAG_SYNC) class StatusRenderer(object): def __init__(self, context): self.context = context self.prompt = context.prompt def display_report(self, progress_report): raise NotImplementedError()
# see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt from gettext import gettext as _ from pulp.client.commands.options import DESC_ID, OPTION_CONSUMER_ID, OPTION_REPO_ID from pulp.client.commands.polling import PollingCommand from pulp.client.consumer_utils import load_consumer_id from pulp.client.extensions.extensions import PulpCliFlag, PulpCliOption from pulp.common import tags OPTION_DISTRIBUTOR_ID = PulpCliOption('--distributor-id', DESC_ID, required=True) FLAG_FORCE = PulpCliFlag( '--force', _('delete the binding immediately without tracking the progress')) # consumer bindings management commands ---------------------------------------- class ConsumerBindCommand(PollingCommand): """ Base class that binds a consumer to a repository and an arbitrary distributor. """ def __init__(self, context, name=None, description=None): name = name or 'bind' description = description or _('binds a consumer to a repository') PollingCommand.__init__(self, name, description, self.run, context)
NAME_RPM = 'rpm' DESC_RPM = _('uploads one or more RPMs into a repository') SUFFIX_RPM = '.rpm' NAME_SRPM = 'srpm' DESC_SRPM = _('uploads one or more SRPMs into a repository') SUFFIX_SRPM = '.src.rpm' NAME_DRPM = 'drpm' DESC_DRPM = _('uploads one or more DRPMs into a repository') SUFFIX_DRPM = '.drpm' DESC_SKIP_EXISTING = _( 'if specified, RPMs that already exist on the server will not be uploaded') FLAG_SKIP_EXISTING = PulpCliFlag('--skip-existing', DESC_SKIP_EXISTING) RPMTAG_NOSOURCE = 1051 CHECKSUM_READ_BUFFER_SIZE = 65536 class _CreatePackageCommand(UploadCommand): """ Base command for uploading RPMs, SRPMs and DRPMs. This shouldn't be instantiated directly outside of this module in favor of one of the type-specific subclasses. """ def __init__(self, context, upload_manager, type_id, suffix, name, description): super(_CreatePackageCommand, self).__init__(context, upload_manager, name=name,
' (must be greater than zero)'), required=False, parse_func=parse_positive_int) OPTION_SORT = PulpCliOption( '--sort', _('indicates the sort direction ("ascending" or "descending") ' 'based on the entry\'s timestamp'), required=False) OPTION_START_DATE = PulpCliOption( '--start-date', _('only return entries that occur on or after the given date in' ' iso8601 format (yyyy-mm-ddThh:mm:ssZ)'), required=False, validate_func=iso8601_datetime_validator) OPTION_END_DATE = PulpCliOption( '--end-date', _('only return entries that occur on or before the given date in ' 'iso8601 format (yyyy-mm-ddThh:mm:ssZ)'), required=False, validate_func=iso8601_datetime_validator) FLAG_DETAILS = PulpCliFlag( '--details', _('if specified, all of the consumer information is displayed')) FLAG_BINDINGS = PulpCliFlag( '--bindings', _('if specified, the bindings information is displayed'))
d = _( 'path to a CSV file containing package list information. ' 'Format for each entry is: "name,version,release,epoch,arch,filename,checksum,' 'checksum_type,sourceurl"') OPT_PKG_LIST = PulpCliOption('--pkglist-csv', d, aliases=['-p'], required=True) d = _( 'erratum issuer, used in the \'from_str\' for the erratum; typically an email address' ) OPT_FROM = PulpCliOption('--from', d, required=True) d = _('pushcount for the erratum; an integer, defaults to 1 if unspecified') OPT_PUSHCOUNT = PulpCliOption('--pushcount', d, required=False, default=1) d = _('if specified, the erratum will be marked as \'reboot-suggested\'') OPT_REBOOT = PulpCliFlag('--reboot-suggested', d) d = _('if specified, the erratum will be marked as \'restart-suggested\'') OPT_RESTART = PulpCliFlag('--restart-suggested', d) d = _('if specified, the erratum will be marked as \'relogin-suggested\'') OPT_RELOGIN = PulpCliFlag('--relogin-suggested', d) d = _('severity of the erratum') OPT_SEVERITY = PulpCliOption('--severity', d, required=False) d = _('rights for the erratum') OPT_RIGHTS = PulpCliOption('--rights', d, required=False) d = _('summary for the erratum') OPT_SUMMARY = PulpCliOption('--summary', d, required=False)
required=False, validate_func=validators.iso8601_datetime_validator) OPTION_END_DATE = PulpCliOption( '--end-date', DESC_END_DATE, required=False, validate_func=validators.iso8601_datetime_validator) OPTION_EXPORT_DIR = PulpCliOption('--export-dir', DESC_EXPORT_DIR, required=False) OPTION_ISO_SIZE = PulpCliOption('--iso-size', DESC_ISO_SIZE, required=False, parse_func=parsers.parse_optional_positive_int) FLAG_MANIFEST = PulpCliFlag('--' + constants.CREATE_PULP_MANIFEST, DESC_MANIFEST, ['-m']) class RpmExportCommand(RunPublishRepositoryCommand): """ The 'pulp-admin rpm repo export run' command """ def __init__(self, context, renderer): """ The constructor for RpmExportCommand :param context: The client context to use for this command :type context: pulp.client.extensions.core.ClientContext """ override_config_options = [ OPTION_EXPORT_DIR, OPTION_ISO_PREFIX, OPTION_ISO_SIZE,
d = _( 'path to a CSV file containing package list information. ' 'Format for each entry is: "name,version,release,epoch,arch,filename,checksum,' 'checksum_type,sourceurl"') OPT_PKG_LIST = PulpCliOption('--pkglist-csv', d, aliases=['-p'], required=True) d = _( 'erratum issuer, used in the \'from_str\' for the erratum; typically an email address' ) OPT_FROM = PulpCliOption('--from', d, required=True) d = _('pushcount for the erratum; an integer, defaults to 1 if unspecified') OPT_PUSHCOUNT = PulpCliOption('--pushcount', d, required=False, default=1) d = _('if specified, the erratum will be marked as \'reboot-suggested\'') OPT_REBOOT = PulpCliFlag('--reboot-suggested', d) d = _('severity of the erratum') OPT_SEVERITY = PulpCliOption('--severity', d, required=False) d = _('rights for the erratum') OPT_RIGHTS = PulpCliOption('--rights', d, required=False) d = _('summary for the erratum') OPT_SUMMARY = PulpCliOption('--summary', d, required=False) d = _('solution for the erratum') OPT_SOLUTION = PulpCliOption('--solution', d, required=False) class CreateErratumCommand(UploadCommand):
DESC_LIMIT, required=False, validate_func=validators.positive_int_validator) OPTION_SORT = PulpCliOption('--sort', DESC_SORT, required=False) OPTION_DISTRIBUTOR_ID = PulpCliOption('--distributor-id', DESC_DISTRIBUTOR_ID, required=True, validate_func=validators.id_validator) OPTION_START_DATE = PulpCliOption( '--start-date', DESC_START_DATE, required=False, validate_func=validators.iso8601_datetime_validator) # Flags FLAG_DETAILS = PulpCliFlag('--details', DESC_DETAILS, aliases='-d') # -- commands ----------------------------------------------------------------- class SyncHistoryCommand(PulpCliCommand): """ Displays the sync history of a given repository """ def __init__(self, context, name='sync', description=DESC_SYNC_HISTORY): """ :param context: The client context used to interact with the client framework and server :type context: pulp.client.extensions.core.ClientContext :param name: The name of the command in the history section :type name: str
class AllTasksSection(BaseTasksSection): FIELDS = ('tags', 'task_id', 'state', 'start_time', 'finish_time') # Flags for purge command purge_all = PulpCliFlag('--all', _('if specified, all tasks in "successful, ' 'skipped and failed" states will be purged'), aliases=['-a']) purge_state = PulpCliOption('--state', _('comma-separated list of tasks states desired to be ' 'purged. Example: "successful,failed". Do not include spaces.'), aliases=['-s'], required=False, parse_func=parsers.csv) def __init__(self, context, name, description): BaseTasksSection.__init__(self, context, name, description) self.list_command.add_option(self.all_flag) self.list_command.add_option(self.state_option) self.purge_command = self.create_command('purge', _( 'purge tasks in one or more completed states'), self.purge) self.purge_command.add_option(self.purge_all) self.purge_command.add_option(self.purge_state) def retrieve_tasks(self, **kwargs): """ :return: list of pulp.bindings.responses.Task instances :rtype: list """ if kwargs.get(self.all_flag.keyword): tasks = self.context.server.tasks_search.search(fields=self.FIELDS) elif kwargs.get(self.state_option.keyword): states = kwargs[self.state_option.keyword] # This is a temorary fix(because of backward incompatible reasons) # until #1028 and #1041 are fixed. self.translate_state_discrepancy(states) tasks = self.context.server.tasks_search.search( filters={'state': {'$in': states}}, fields=self.FIELDS) else: tasks = self.context.server.tasks_search.search( filters={'state': {'$in': ['running', 'waiting']}}, fields=self.FIELDS) return tasks def purge(self, **kwargs): """ Attempts to purge completed tasks with states successful, failed and/or skipped. If a state does not support purging, message will be raised from the server. Otherwise a success message is displayed and nothing is returned from the server. If no valid flag is mentioned, it raises the CommandUsage Exception. :raises CommandUsage Exception when incorrect arguments given to command line """ self.context.prompt.render_title('Purge Completed Tasks') if kwargs.get(self.purge_all.keyword) and kwargs.get(self.purge_state.keyword): msg = _('These arguments cannot be used together') self.context.prompt.render_failure_message(msg) return if kwargs.get(self.purge_state.keyword): states = kwargs[self.purge_state.keyword] elif kwargs.get(self.purge_all.keyword): states = VALID_STATES else: raise CommandUsage states = self.translate_state_discrepancy(states) self.context.server.tasks.purge_tasks(states=states) self.context.prompt.render_success_message(_('Task purging is successfully initiated.')) @staticmethod def translate_state_discrepancy(states): """ Translates task state names that have discrepancy in cli and server mode. :param states: task state to parse :type states: list :return: translated task states :rtype: list """ states_map = {'successful': 'finished', 'failed': 'error'} for state_name in states_map.keys(): if state_name in states: del states[states.index(state_name)] states.append(states_map[state_name]) return states
# -- constants ---------------------------------------------------------------- DESC_RPM = _('copy RPMs from one repository to another') DESC_SRPM = _('copy SRPMs from one repository to another') DESC_DRPM = _('copy DRPMs from one repository to another') DESC_ERRATA = _('copy errata from one repository to another') DESC_DISTRIBUTION = _('copy distributions from one repository to another') DESC_PKG_GROUP = _('copy package groups from one repository to another') DESC_PKG_CATEGORY = _('copy package categories from one repository to another') DESC_PKG_ENVIRONMENT = _('copy package environment from one repository to another') DESC_ALL = _('copy all content units from one repository to another') DESC_RECURSIVE = _( 'if specified, any dependencies of units being copied that are in the source repo ' 'will be copied as well') FLAG_RECURSIVE = PulpCliFlag('--recursive', DESC_RECURSIVE) # -- commands ----------------------------------------------------------------- class NonRecursiveCopyCommand(UnitCopyCommand): """ Base class for all copy commands in this module that need not support specifying a recursive option to the plugin. """ def __init__(self, context, name, description, type_id, unit_threshold=DISPLAY_UNITS_THRESHOLD): super(NonRecursiveCopyCommand, self).__init__(context, name=name, description=description, type_id=type_id) self.unit_threshold = unit_threshold
class BaseTasksSection(PulpCliSection): """ Base class for handling tasks in the Pulp server. This should be subclassed to provide consistent functionality for a subset of tasks. """ all_flag = PulpCliFlag('--all', _('if specified, all tasks in all states are shown'), aliases=['-a']) state_option = PulpCliOption('--state', _('comma-separated list of tasks states desired to be ' 'shown. Example: "running,waiting,canceled,successful,failed". ' 'Do not include spaces.'), aliases=['-s'], required=False, parse_func=parsers.csv) def __init__(self, context, name, description): PulpCliSection.__init__(self, name, description) self.context = context # Store the command instances as instance variables so the subclasses # can manipulate them if necessary self.list_command = self.create_command( 'list', _('lists tasks queued (waiting) or running on the server'), self.list ) self.cancel_command = self.create_command('cancel', _('cancel one or more tasks'), self.cancel) self.cancel_command.create_option('--task-id', _('identifies the task to cancel'), required=True) self.details_command = self.create_command('details', _( 'displays more detailed information about a specific task'), self.details ) self.details_command.create_option('--task-id', _('identifies the task'), required=True) def list(self, **kwargs): """ Displays a list of tasks. The list of tasks is driven by the retrieve_tasks method which should be overridden to provide the correct behavior. """ self.context.prompt.render_title('Tasks') if kwargs.get(self.all_flag.keyword) and kwargs.get(self.state_option.keyword): msg = _('These arguments cannot be used together') self.context.prompt.render_failure_message(msg) return task_objects = self.retrieve_tasks(**kwargs) # Easy out clause if len(task_objects) is 0: self.context.prompt.render_paragraph('No tasks found') return # Parse each task object into a document to be displayed using the # prompt utilities task_documents = [] for task in task_objects: # Interpret task values state, start_time, finish_time, result = self.parse_state(task) actions, resources = self.parse_tags(task) task_doc = { 'operations': ', '.join(actions), 'resources': ', '.join(resources), 'task_id': task.task_id, 'state': state, 'start_time': start_time, 'finish_time': finish_time, } task_documents.append(task_doc) self.context.prompt.render_document_list(task_documents, order=TASK_LIST_DOC_ORDER) def details(self, **kwargs): """ Displays detailed information about a single task. The task ID must be in kwargs under "task-id". """ self.context.prompt.render_title('Task Details') task_id = kwargs['task-id'] response = self.context.server.tasks.get_task(task_id) task = response.response_body # Interpret task values state, start_time, finish_time, result = self.parse_state(task) actions, resources = self.parse_tags(task) # Assemble document to be displayed task_doc = { 'operations': ', '.join(actions), 'resources': ', '.join(resources), 'task_id': task.task_id, 'state': state, 'start_time': start_time, 'finish_time': finish_time, 'result': result, 'progress_report': task.progress_report, } if task.exception: task_doc['exception'] = task.exception if task.traceback: task_doc['traceback'] = task.traceback self.context.prompt.render_document(task_doc, order=TASK_DETAILS_DOC_ORDER) def cancel(self, **kwargs): """ Attempts to cancel a task. Only unstarted tasks and those that support cancellation (sync, publish) can be canceled. If a task does not support cancelling, a not implemented error (501) will be raised from the server. We should handle that gracefully to explain to the user what happend. Otherwise, all other errors should bubble up to the exception middleware as usual. """ task_id = kwargs['task-id'] try: self.context.server.tasks.cancel_task(task_id) self.context.prompt.render_success_message(_('Task cancel is successfully initiated.')) except PulpServerException, e: # A 501 has a bit of a special meaning here that's not used in the # exception middleware, so handle it here. if e.http_status == 501: msg = _('The requested task does not support cancellation.') self.context.prompt.render_failure_message(msg) return else: raise
from gettext import gettext as _ from M2Crypto import RSA from M2Crypto.util import no_passphrase_callback from M2Crypto.X509 import X509Error from pulp.bindings.exceptions import NotFoundException from pulp.client.arg_utils import args_to_notes_dict from pulp.client.consumer_utils import load_consumer_id from pulp.client.extensions.decorator import priority from pulp.client.extensions.extensions import PulpCliCommand, PulpCliOption, PulpCliFlag from pulp.client.extensions import exceptions from pulp.client import validators OPTION_EXCHANGE_KEYS = PulpCliFlag('--keys', _('exchange public keys with the server')) # -- framework hook ----------------------------------------------------------- @priority() def initialize(context): # Common Options d = 'uniquely identifies the consumer; only alphanumeric, ., -, and _ allowed' id_option = PulpCliOption('--consumer-id', _(d), required=True, validate_func=validators.id_validator_allow_dots) d = 'user-readable display name for the consumer'
from gettext import gettext as _ from pulp.client.extensions.extensions import PulpCliFlag FLAG_NO_COMMIT = PulpCliFlag('--no-commit', _('test the transaction without committing it')) FLAG_REBOOT = PulpCliFlag('--reboot', _('reboot after a successful transaction')) FLAG_IMPORT_KEYS = PulpCliFlag('--import-keys', _('import GPG keys as needed')) FLAG_ALL_CONTENT = PulpCliFlag('--all', _('update all content units'), ['-a'])