Пример #1
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1  # if assigned, we must tail the logfile

        fields = self.get_fields(object_type)
        if object_action in ["add", "edit", "copy", "rename", "find", "remove"]:
            utils.add_options_from_fields(object_type, self.parser, fields, object_action)
        elif object_action in ["list"]:
            pass
        elif object_action not in ("reload", "update"):
            self.parser.add_option("--name", dest="name", help="name of object")
        elif object_action == "reload":
            self.parser.add_option("--filename", dest="filename", help="filename to load data from")
        (options, args) = self.parser.parse_args()

        # the first three don't require a name
        if object_action == "report":
            if options.name is not None:
                report_item(self.remote, object_type, None, options.name)
            else:
                report_items(self.remote, object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(object_type, utils.strip_none(vars(options), omit_none=True), "name", False)
            for item in items:
                print item
        elif object_action in OBJECT_ACTIONS:
            if opt(options, "name") == "" and object_action not in ("reload", "update"):
                print "--name is required"
                sys.exit(1)
            if object_action in ["add", "edit", "copy", "rename", "remove"]:
                try:
                    if object_type == "setting":
                        settings = self.remote.get_settings()
                        if not settings.get("allow_dynamic_settings", False):
                            raise RuntimeError(
                                "Dynamic settings changes are not enabled. Change the allow_dynamic_settings to 1 and restart cobblerd to enable dynamic settings changes"
                            )
                        elif options.name == "allow_dynamic_settings":
                            raise RuntimeError("Cannot modify that setting live")
                        elif self.remote.modify_setting(options.name, options.value, self.token):
                            raise RuntimeError("Changing the setting failed")
                    else:
                        self.remote.xapi_object_edit(
                            object_type,
                            options.name,
                            object_action,
                            utils.strip_none(vars(options), omit_none=True),
                            self.token,
                        )
                except xmlrpclib.Fault, (err):
                    (etype, emsg) = err.faultString.split(":", 1)
                    print emsg[1:-1]  # don't print the wrapping quotes
                    sys.exit(1)
                except RuntimeError, (err):
                    print err.args[0]
                    sys.exit(1)
Пример #2
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1 # if assigned, we must tail the logfile
        
        fields = self.get_fields(object_type)
        if object_action in [ "add", "edit", "copy", "rename", "find" ]:
            utils.add_options_from_fields(object_type, self.parser, fields, object_action)
        elif object_action in [ "list" ]:
            pass
        else:
            self.parser.add_option("--name", dest="name", help="name of object")
        (options, args) = self.parser.parse_args()

        if object_action in [ "add", "edit", "copy", "rename", "remove" ]:
            if opt(options, "name") == "":
                print "--name is required"
                sys.exit(1)
            self.remote.xapi_object_edit(object_type, options.name, object_action, utils.strip_none(vars(options), omit_none=True), self.token)
        elif object_action == "getks":
            if object_type == "profile":
                data = self.remote.generate_kickstart(options.name,"")
            elif object_type == "system":
                data = self.remote.generate_kickstart("",options.name)
            print data
        elif object_action == "dumpvars":
            if object_type == "profile":
                data = self.remote.get_blended_data(options.name,"")
            elif object_type == "system":
                data = self.remote.get_blended_data("",options.name)
            # FIXME: pretty-printing and sorting here
            print data
        elif object_action in [ "poweron", "poweroff", "reboot" ]:
            power={}
            power["power"] = object_action.replace("power","")
            power["systems"] = [options.name]
            task_id = self.remote.background_power_system(power, self.token)
        elif object_action == "report":
            if options.name is not None:
                report_item(self.remote,object_type,None,options.name)
            else:
                report_items(self.remote,object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(object_type, utils.strip_none(vars(options), omit_none=True), "name", False)
            for item in items:
                print item
        else:
            raise exceptions.NotImplementedError() 
            
        # FIXME: add tail/polling code here
        if task_id != -1:
            self.print_task(task_id)
            self.follow_task(task_id)
                                                
        return True
Пример #3
0
    def search(cls, query_params):

        # NOTE: Params 'recursive' and 'with_responses' are currently not used by
        # either the 'search' or 'get_all' actions below.  Both already use
        # with_responses=False internally in the comment service, so no additional
        # optimization is required.
        params = {
            'page': 1,
            'per_page': 20,
            'course_id': query_params['course_id'],
        }
        params.update(utils.strip_blank(utils.strip_none(query_params)))

        if query_params.get('text'):
            url = cls.url(action='search')
        else:
            url = cls.url(action='get_all',
                          params=utils.extract(params, 'commentable_id'))
            if params.get('commentable_id'):
                del params['commentable_id']
        response = utils.perform_request(
            'get',
            url,
            params,
            metric_tags=[u'course_id:{}'.format(query_params['course_id'])],
            metric_action='thread.search',
            paged_results=True)
        if query_params.get('text'):
            search_query = query_params['text']
            course_id = query_params['course_id']
            group_id = query_params[
                'group_id'] if 'group_id' in query_params else None
            requested_page = params['page']
            total_results = response.get('total_results')
            corrected_text = response.get('corrected_text')
            # Record search result metric to allow search quality analysis.
            # course_id is already included in the context for the event tracker
            tracker.emit(
                'edx.forum.searched', {
                    'query': search_query,
                    'corrected_text': corrected_text,
                    'group_id': group_id,
                    'page': requested_page,
                    'total_results': total_results,
                })
            log.info(
                u'forum_text_search query="{search_query}" corrected_text="{corrected_text}" course_id={course_id} group_id={group_id} page={requested_page} total_results={total_results}'
                .format(search_query=search_query,
                        corrected_text=corrected_text,
                        course_id=course_id,
                        group_id=group_id,
                        requested_page=requested_page,
                        total_results=total_results))

        return utils.CommentClientPaginatedResult(
            collection=response.get('collection', []),
            page=response.get('page', 1),
            num_pages=response.get('num_pages', 1),
            thread_count=response.get('thread_count', 0),
            corrected_text=response.get('corrected_text', None))
Пример #4
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1 # if assigned, we must tail the logfile
        
        fields = self.get_fields(object_type)
        if object_action in [ "add", "edit", "copy", "rename", "find", "remove" ]:
            utils.add_options_from_fields(object_type, self.parser, fields, object_action)
        elif object_action in [ "list" ]:
            pass
        elif object_action not in ("reload","update"):
            self.parser.add_option("--name", dest="name", help="name of object")
        elif object_action == "reload":
            self.parser.add_option("--filename", dest="filename", help="filename to load data from")
        (options, args) = self.parser.parse_args()

        # the first three don't require a name
        if object_action == "report":
            if options.name is not None:
                report_item(self.remote,object_type,None,options.name)
            else:
                report_items(self.remote,object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(object_type, utils.strip_none(vars(options), omit_none=True), "name", False)
            for item in items:
                print item
        elif object_action in OBJECT_ACTIONS:
            if opt(options, "name") == "" and object_action not in ("reload","update"):
                print "--name is required"
                sys.exit(1)
            if object_action in [ "add", "edit", "copy", "rename", "remove" ]:
                try:
                    if object_type == "setting":        
                        settings = self.remote.get_settings()
                        if options.value == None:
                            raise RuntimeError("You must specify a --value when editing a setting")
                        elif not settings.get('allow_dynamic_settings',False):
                            raise RuntimeError("Dynamic settings changes are not enabled. Change the allow_dynamic_settings to 1 and restart cobblerd to enable dynamic settings changes")
                        elif options.name == 'allow_dynamic_settings':
                            raise RuntimeError("Cannot modify that setting live")
                        elif self.remote.modify_setting(options.name,options.value,self.token):
                            raise RuntimeError("Changing the setting failed")
                    else:
                        self.remote.xapi_object_edit(object_type, options.name, object_action, utils.strip_none(vars(options), omit_none=True), self.token)
                except xmlrpclib.Fault, (err):
                    (etype, emsg) = err.faultString.split(":",1)
                    print "exception on server: %s" % emsg
                    sys.exit(1)
                except RuntimeError, (err):
                    print err.args[0]
                    sys.exit(1)
Пример #5
0
    def _retrieve(self, *args, **kwargs):
        url = self.url(action='get', params=self.attributes)
        request_params = {
            'recursive': kwargs.get('recursive'),
            'with_responses': kwargs.get('with_responses', False),
            'user_id': kwargs.get('user_id'),
            'mark_as_read': kwargs.get('mark_as_read', True),
            'resp_skip': kwargs.get('response_skip'),
            'resp_limit': kwargs.get('response_limit'),
        }
        request_params = utils.strip_none(request_params)

        response = utils.perform_request('get',
                                         url,
                                         request_params,
                                         metric_action='model.retrieve',
                                         metric_tags=self._metric_tags)
        self._update_from_response(response)
Пример #6
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1  # if assigned, we must tail the logfile

        fields = self.get_fields(object_type)
        if object_action in ["add", "edit", "copy", "rename", "find"]:
            utils.add_options_from_fields(object_type, self.parser, fields,
                                          object_action)
        elif object_action in ["list"]:
            pass
        else:
            self.parser.add_option("--name",
                                   dest="name",
                                   help="name of object")
        (options, args) = self.parser.parse_args()

        if object_action in [
                "add", "edit", "copy", "rename", "remove", "reboot"
        ]:
            if opt(options, "name") == "":
                print "--name is required"
                sys.exit(1)
            self.remote.xapi_object_edit(
                object_type, options.name, object_action,
                utils.strip_none(vars(options), omit_none=True), self.token)
        elif object_action == "getks":
            if object_type == "profile":
                data = self.remote.generate_kickstart(options.name, "")
            elif object_type == "system":
                data = self.remote.generate_kickstart("", options.name)
            print data
        elif object_action == "dumpvars":
            if object_type == "profile":
                data = self.remote.get_blended_data(options.name, "")
            elif object_type == "system":
                data = self.remote.get_blended_data("", options.name)
            # FIXME: pretty-printing and sorting here
            keys = data.keys()
            keys.sort()
            for x in keys:
                print "%s : %s" % (x, data[x])
        elif object_action in ["poweron", "poweroff", "powerstatus", "reboot"]:
            power = {}
            power["power"] = object_action.replace("power", "")
            power["systems"] = [options.name]
            task_id = self.remote.background_power_system(power, self.token)
        elif object_action == "report":
            if options.name is not None:
                report_item(self.remote, object_type, None, options.name)
            else:
                report_items(self.remote, object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(
                object_type, utils.strip_none(vars(options), omit_none=True),
                "name", False)
            for item in items:
                print item
        else:
            raise exceptions.NotImplementedError()

        # FIXME: add tail/polling code here
        if task_id != -1:
            self.print_task(task_id)
            self.follow_task(task_id)

        return True
Пример #7
0
 def start_task(self, name, options):
     options = utils.strip_none(vars(options), omit_none=True)
     fn = getattr(self.remote, "background_%s" % name)
     return fn(options, self.token)
Пример #8
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1 # if assigned, we must tail the logfile
        
        fields = self.get_fields(object_type)
        if object_action in [ "add", "edit", "copy", "rename", "find" ]:
            utils.add_options_from_fields(object_type, self.parser, fields, object_action)
        elif object_action in [ "list" ]:
            pass
        else:
            self.parser.add_option("--name", dest="name", help="name of object")
        (options, args) = self.parser.parse_args()

        if object_action in [ "add", "edit", "copy", "rename", "remove", "reboot" ]:
            if opt(options, "name") == "":
                print "--name is required"
                sys.exit(1)
            try:
                self.remote.xapi_object_edit(object_type, options.name, object_action, utils.strip_none(vars(options), omit_none=True), self.token)
            except xmlrpclib.Fault, (err):
                (etype, emsg) = err.faultString.split(":",1)
                print emsg[1:-1] # don't print the wrapping quotes
                sys.exit(1)
Пример #9
0
 def start_task(self, name, options):
     options = utils.strip_none(vars(options), omit_none=True)
     fn = getattr(self.remote, "background_%s" % name)
     return fn(options, self.token)
Пример #10
0
            for x in keys:
               print "%s : %s" % (x, data[x])
        elif object_action in [ "poweron", "poweroff", "powerstatus", "reboot" ]:
            power={}
            power["power"] = object_action.replace("power","")
            power["systems"] = [options.name]
            task_id = self.remote.background_power_system(power, self.token)
        elif object_action == "report":
            if options.name is not None:
                report_item(self.remote,object_type,None,options.name)
            else:
                report_items(self.remote,object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(object_type, utils.strip_none(vars(options), omit_none=True), "name", False)
            for item in items:
                print item
        else:
            raise exceptions.NotImplementedError() 
            
        # FIXME: add tail/polling code here
        if task_id != -1:
            self.print_task(task_id)
            self.follow_task(task_id)
                                                
        return True

    # BOOKMARK
    def direct_command(self, action_name):
        """
Пример #11
0
                # FIXME: pretty-printing and sorting here
                keys = data.keys()
                keys.sort()
                for x in keys:
                    print "%s : %s" % (x, data[x])
            elif object_action in [
                    "poweron", "poweroff", "powerstatus", "reboot"
            ]:
                power = {}
                power["power"] = object_action.replace("power", "")
                power["systems"] = [options.name]
                task_id = self.remote.background_power_system(
                    power, self.token)
            elif object_action == "update":
                task_id = self.remote.background_signature_update(
                    utils.strip_none(vars(options), omit_none=True),
                    self.token)
            elif object_action == "reload":
                filename = opt(options, "filename",
                               "/var/lib/cobbler/distro_signatures.json")
                if not utils.load_signatures(filename, cache=True):
                    print "There was an error loading the signature data in %s." % filename
                    print "Please check the JSON file or run 'cobbler signature update'."
                    return False
                else:
                    print "Signatures were successfully loaded"
            else:
                raise exceptions.NotImplementedError()
        else:
            raise exceptions.NotImplementedError()
Пример #12
0
         if object_type == "profile":
             data = self.remote.get_blended_data(options.name,"")
         elif object_type == "system":
             data = self.remote.get_blended_data("",options.name)
         # FIXME: pretty-printing and sorting here
         keys = data.keys()
         keys.sort()
         for x in keys:
            print "%s : %s" % (x, data[x])
     elif object_action in [ "poweron", "poweroff", "powerstatus", "reboot" ]:
         power={}
         power["power"] = object_action.replace("power","")
         power["systems"] = [options.name]
         task_id = self.remote.background_power_system(power, self.token)
     elif object_action == "update":
         task_id = self.remote.background_signature_update(utils.strip_none(vars(options),omit_none=True), self.token)
     elif object_action == "reload":
         filename = opt(options,"filename","/var/lib/cobbler/distro_signatures.json")
         if not utils.load_signatures(filename,cache=True):
             print "There was an error loading the signature data in %s." % filename
             print "Please check the JSON file or run 'cobbler signature update'."
             return False
         else:
             print "Signatures were successfully loaded"
     else:
         raise exceptions.NotImplementedError()
 else:
     raise exceptions.NotImplementedError() 
     
 # FIXME: add tail/polling code here
 if task_id != -1:
Пример #13
0
                    data = self.remote.get_blended_data(options.name, "")
                elif object_type == "system":
                    data = self.remote.get_blended_data("", options.name)
                # FIXME: pretty-printing and sorting here
                keys = data.keys()
                keys.sort()
                for x in keys:
                    print "%s : %s" % (x, data[x])
            elif object_action in ["poweron", "poweroff", "powerstatus", "reboot"]:
                power = {}
                power["power"] = object_action.replace("power", "")
                power["systems"] = [options.name]
                task_id = self.remote.background_power_system(power, self.token)
            elif object_action == "update":
                task_id = self.remote.background_signature_update(
                    utils.strip_none(vars(options), omit_none=True), self.token
                )
            elif object_action == "reload":
                filename = opt(options, "filename", "/var/lib/cobbler/distro_signatures.json")
                if not utils.load_signatures(filename, cache=True):
                    print "There was an error loading the signature data in %s." % filename
                    print "Please check the JSON file or run 'cobbler signature update'."
                    return False
                else:
                    print "Signatures were successfully loaded"
            else:
                raise exceptions.NotImplementedError()
        else:
            raise exceptions.NotImplementedError()

        # FIXME: add tail/polling code here
Пример #14
0
    def object_command(self, object_type, object_action):
        """
        Process object-based commands such as "distro add" or "profile rename"
        """
        task_id = -1 # if assigned, we must tail the logfile
        
        fields = self.get_fields(object_type)
        if object_action in [ "add", "edit", "copy", "rename", "find" ]:
            utils.add_options_from_fields(object_type, self.parser, fields, object_action)
        elif object_action in [ "list" ]:
            pass
        else:
            self.parser.add_option("--name", dest="name", help="name of object")
        (options, args) = self.parser.parse_args()

        # the first three don't require a name
        if object_action == "report":
            if options.name is not None:
                report_item(self.remote,object_type,None,options.name)
            else:
                report_items(self.remote,object_type)
        elif object_action == "list":
            list_items(self.remote, object_type)
        elif object_action == "find":
            items = self.remote.find_items(object_type, utils.strip_none(vars(options), omit_none=True), "name", False)
            for item in items:
                print item
        elif object_action in OBJECT_ACTIONS:
            if opt(options, "name") == "":
                print "--name is required"
                sys.exit(1)
            if object_action in [ "add", "edit", "copy", "rename", "remove" ]:
                try:
                    self.remote.xapi_object_edit(object_type, options.name, object_action, utils.strip_none(vars(options), omit_none=True), self.token)
                except xmlrpclib.Fault, (err):
                    (etype, emsg) = err.faultString.split(":",1)
                    print emsg[1:-1] # don't print the wrapping quotes
                    sys.exit(1)
            elif object_action == "getks":
                if object_type == "profile":
                    data = self.remote.generate_kickstart(options.name,"")
                elif object_type == "system":
                    data = self.remote.generate_kickstart("",options.name)
                print data
            elif object_action == "dumpvars":
                if object_type == "profile":
                    data = self.remote.get_blended_data(options.name,"")
                elif object_type == "system":
                    data = self.remote.get_blended_data("",options.name)
                # FIXME: pretty-printing and sorting here
                keys = data.keys()
                keys.sort()
                for x in keys:
                   print "%s : %s" % (x, data[x])
            elif object_action in [ "poweron", "poweroff", "powerstatus", "reboot" ]:
                power={}
                power["power"] = object_action.replace("power","")
                power["systems"] = [options.name]
                task_id = self.remote.background_power_system(power, self.token)
            else:
                raise exceptions.NotImplementedError()