def run(self, **kwargs): consumer_id = kwargs[OPTION_CONSUMER_ID.keyword] strategy = kwargs[STRATEGY_OPTION.keyword] delta = { 'notes': { constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy } } if node_activated(self.context, consumer_id): msg = ALREADY_ACTIVATED_NOTHING_DONE % dict(n=CONSUMER) self.context.prompt.render_success_message(msg) return if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=CONSUMER, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): convert_boolean_arguments([AUTO_PUBLISH_OPTION.keyword], kwargs) repo_id = kwargs[OPTION_REPO_ID.keyword] auto_publish = kwargs[AUTO_PUBLISH_OPTION.keyword] binding = self.context.server.repo_distributor if repository_enabled(self.context, repo_id): msg = ALREADY_ENABLED self.context.prompt.render_success_message(msg) return try: binding.create( repo_id, constants.HTTP_DISTRIBUTOR, {}, auto_publish, constants.HTTP_DISTRIBUTOR) self.context.prompt.render_success_message(REPO_ENABLED) self.context.prompt.render_warning_message(ENABLE_WARNING % dict(r=repo_id)) if auto_publish: self.context.prompt.render_warning_message(AUTO_PUBLISH_WARNING) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repository': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): self.context.prompt.render_warning_message(CLI_DEPRECATION_WARNING) consumer_id = load_consumer_id(self.context) strategy = kwargs[STRATEGY_OPTION.keyword] delta = { 'notes': { constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy } } if node_activated(self.context, consumer_id): self.context.prompt.render_success_message( ALREADY_ACTIVATED_NOTHING_DONE) return if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': self.context.prompt.render_failure_message( NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = kwargs[OPTION_CONSUMER_ID.keyword] strategy = kwargs[STRATEGY_OPTION.keyword] delta = {'notes': {constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy}} if node_activated(self.context, consumer_id): msg = ALREADY_ACTIVATED_NOTHING_DONE % dict(n=CONSUMER) self.context.prompt.render_success_message(msg) return if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=CONSUMER, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): node_id = kwargs[NODE_ID_OPTION.keyword] max_bandwidth = kwargs[MAX_BANDWIDTH_OPTION.keyword] max_concurrency = kwargs[MAX_CONCURRENCY_OPTION.keyword] units = [dict(type_id='node', unit_key=None)] options = { constants.MAX_DOWNLOAD_BANDWIDTH_KEYWORD: max_bandwidth, constants.MAX_DOWNLOAD_CONCURRENCY_KEYWORD: max_concurrency, } if not node_activated(self.context, node_id): msg = NOT_ACTIVATED_ERROR % dict(t=CONSUMER, id=node_id) self.context.prompt.render_failure_message(msg) return os.EX_USAGE try: http = self.context.server.consumer_content.update(node_id, units=units, options=options) task = http.response_body self.poll([task], kwargs) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=NODE, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): convert_boolean_arguments([AUTO_PUBLISH_OPTION.keyword], kwargs) repo_id = kwargs[OPTION_REPO_ID.keyword] auto_publish = kwargs[AUTO_PUBLISH_OPTION.keyword] binding = self.context.server.repo_distributor if repository_enabled(self.context, repo_id): msg = ALREADY_ENABLED self.context.prompt.render_success_message(msg) return try: binding.create(repo_id, constants.HTTP_DISTRIBUTOR, {}, auto_publish, constants.HTTP_DISTRIBUTOR) self.context.prompt.render_success_message(REPO_ENABLED) self.context.prompt.render_warning_message(ENABLE_WARNING % dict(r=repo_id)) if auto_publish: self.context.prompt.render_warning_message( AUTO_PUBLISH_WARNING) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repository': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): self.context.prompt.render_warning_message(CLI_DEPRECATION_WARNING) consumer_id = load_consumer_id(self.context) strategy = kwargs[STRATEGY_OPTION.keyword] delta = {'notes': {constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy}} if node_activated(self.context, consumer_id): self.context.prompt.render_success_message(ALREADY_ACTIVATED_NOTHING_DONE) return if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): self.context.prompt.render_warning_message(CLI_DEPRECATION_WARNING) consumer_id = load_consumer_id(self.context) delta = { 'notes': { constants.NODE_NOTE_KEY: None, constants.STRATEGY_NOTE_KEY: None } } if not node_activated(self.context, consumer_id): self.context.prompt.render_success_message( NOT_ACTIVATED_NOTHING_DONE) return try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_DEACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': self.context.prompt.render_failure_message( NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = kwargs[NODE_ID_OPTION.keyword] delta = { 'notes': { constants.NODE_NOTE_KEY: None, constants.STRATEGY_NOTE_KEY: None } } if not node_activated(self.context, consumer_id): msg = NOT_ACTIVATED_NOTHING_DONE % dict(t=CONSUMER) self.context.prompt.render_success_message(msg) return try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_DEACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=CONSUMER, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): node_id = kwargs[NODE_ID_OPTION.keyword] strategy = kwargs[STRATEGY_OPTION.keyword] options = {constants.STRATEGY_KEYWORD: strategy} units = [dict(type_id='node', unit_key=None)] if not node_activated(self.context, node_id): msg = NOT_ACTIVATED_ERROR % dict(t=CONSUMER, id=node_id) self.context.prompt.render_failure_message(msg) return os.EX_USAGE if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: http = self.context.server.consumer_content.update(node_id, units=units, options=options) task = http.response_body self.poll([task]) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=NODE, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def missing_resources(self, prompt, exception): unhandled = [] for _id, _type in missing_resources(exception): if _type == 'consumer_id': msg = RESOURCE_MISSING_ERROR % dict(t=NODE, id=_id) prompt.render_failure_message(msg) continue if _type == 'repo_id': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) prompt.render_failure_message(msg) continue unhandled.append((_id, _type)) return unhandled
def run(self, **kwargs): consumer_id = load_consumer_id(self.context) delta = {'notes': ACTIVATED_NOTE} try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = kwargs[OPTION_CONSUMER_ID.keyword] delta = {'notes': ACTIVATED_NOTE} try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=CONSUMER, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): repo_id = kwargs[OPTION_REPO_ID.keyword] try: self.context.server.repo_distributor.delete(repo_id, constants.HTTP_DISTRIBUTOR) self.context.prompt.render_success_message(REPO_DISABLED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repository': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) continue if _type == 'distributor': msg = NOT_ENABLED_NOTHING_DONE % dict(t=REPOSITORY) self.context.prompt.render_failure_message(msg) continue raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = load_consumer_id(self.context) delta = {"notes": {constants.NODE_NOTE_KEY: None, constants.STRATEGY_NOTE_KEY: None}} if not node_activated(self.context, consumer_id): self.context.prompt.render_success_message(NOT_ACTIVATED_NOTHING_DONE) return try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_DEACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == "consumer": self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): repo_id = kwargs[OPTION_REPO_ID.keyword] if not repository_enabled(self.context, repo_id): msg = FAILED_NOT_ENABLED self.context.prompt.render_failure_message(msg) return try: http = self.context.server.repo_actions.publish(repo_id, constants.HTTP_DISTRIBUTOR, {}) task = http.response_body self.poll([task], kwargs) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repo_id': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): repo_id = kwargs[OPTION_REPO_ID.keyword] try: self.context.server.repo_distributor.delete( repo_id, constants.HTTP_DISTRIBUTOR) self.context.prompt.render_success_message(REPO_DISABLED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repository': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) continue if _type == 'distributor': msg = NOT_ENABLED_NOTHING_DONE % dict(t=REPOSITORY) self.context.prompt.render_success_message(msg) continue raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = load_consumer_id(self.context) strategy = kwargs[STRATEGY_OPTION.keyword] delta = {"notes": {constants.NODE_NOTE_KEY: True, constants.STRATEGY_NOTE_KEY: strategy}} if strategy not in constants.STRATEGIES: msg = STRATEGY_NOT_SUPPORTED % dict(n=strategy, s=constants.STRATEGIES) self.context.prompt.render_failure_message(msg) return os.EX_DATAERR try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_ACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == "consumer": self.context.prompt.render_failure_message(NOT_REGISTERED_MESSAGE) else: raise return os.EX_DATAERR
def run(self, **kwargs): repo_id = kwargs[OPTION_REPO_ID.keyword] if not repository_enabled(self.context, repo_id): msg = FAILED_NOT_ENABLED self.context.prompt.render_success_message(msg) return try: http = self.context.server.repo_actions.publish( repo_id, constants.HTTP_DISTRIBUTOR, {}) task = http.response_body self.poll([task], kwargs) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'repo_id': msg = RESOURCE_MISSING_ERROR % dict(t=REPOSITORY, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): node_id = kwargs[NODE_ID_OPTION.keyword] units = [dict(type_id='node', unit_key=None)] if not node_activated(self.context, node_id): msg = NOT_ACTIVATED_ERROR % dict(t=CONSUMER, id=node_id) self.context.prompt.render_failure_message(msg) return os.EX_USAGE try: http = self.context.server.consumer_content.update(node_id, units=units, options={}) task = http.response_body self.poll([task], kwargs) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=NODE, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR
def run(self, **kwargs): consumer_id = kwargs[NODE_ID_OPTION.keyword] delta = {'notes': {constants.NODE_NOTE_KEY: None, constants.STRATEGY_NOTE_KEY: None}} if not node_activated(self.context, consumer_id): msg = NOT_ACTIVATED_NOTHING_DONE % dict(t=CONSUMER) self.context.prompt.render_success_message(msg) return try: self.context.server.consumer.update(consumer_id, delta) self.context.prompt.render_success_message(NODE_DEACTIVATED) except NotFoundException, e: for _id, _type in missing_resources(e): if _type == 'consumer': msg = RESOURCE_MISSING_ERROR % dict(t=CONSUMER, id=_id) self.context.prompt.render_failure_message(msg) else: raise return os.EX_DATAERR