コード例 #1
0
ファイル: collection.py プロジェクト: vzhestkov/cobbler
 def collection_types() -> str:
     """
     Returns the string key for the plural name of the collection (used by serializer)
     """
     raise NotImplementedException(
         "Please implement the method \"collection_types\" in your Collection!"
     )
コード例 #2
0
    def factory_produce(self, collection_mgr, seed_data):
        """
        Must override in subclass. Factory_produce returns an Item object from dict.

        :param collection_mgr: The collection manager to resolve all information with.
        :param seed_data: Unused Parameter in the base collection.
        """
        raise NotImplementedException()
コード例 #3
0
    def remove(self, name, with_delete=True, with_sync=True, with_triggers=True, recursive=False, logger=None):
        """
        Remove an item from collection. This method must be overriden in any subclass.

        @param: str name (item name)
        @param: bool with_delete (sync and run triggers)
        @param: bool with_sync (sync to server file system)
        @param: bool with_triggers (run "on delete" triggers)
        @param: bool recursive (recursively delete children)
        @param: clogger logger (logger object)
        @returns: NotImplementedException
        """
        raise NotImplementedException()
コード例 #4
0
    def remove(self, name: str, with_delete: bool = True, with_sync: bool = True, with_triggers: bool = True,
               recursive: bool = False, logger=None):
        """
        Remove an item from collection. This method must be overriden in any subclass.

        :param name: Item Name
        :param with_delete: sync and run triggers
        :param with_sync: sync to server file system
        :param with_triggers: run "on delete" triggers
        :param recursive: recursively delete children
        :param logger: logger object
        :returns: NotImplementedException
        """
        raise NotImplementedException("Please implement this in a child class of this class.")
コード例 #5
0
    def remove(self, name, with_delete=True, with_sync=True, with_triggers=True, recursive=False, logger=None):
        """
        Remove an item from collection. This method must be overriden in any subclass.

        :param name: (item name)
        :type name: str
        :param with_delete: (sync and run triggers)
        :type with_delete: bool
        :param with_sync: (sync to server file system)
        :type with_sync: bool
        :param with_triggers: (run "on delete" triggers)
        :type with_triggers: bool
        :param recursive: (recursively delete children)
        :type recursive: bool
        :param logger: (logger object)
        :returns: NotImplementedException
        """
        raise NotImplementedException()
コード例 #6
0
ファイル: item.py プロジェクト: y2kenny/cobbler
 def make_clone(self):
     """
     Must be defined in any subclass
     """
     raise NotImplementedException()
コード例 #7
0
ファイル: item.py プロジェクト: y2kenny/cobbler
 def get_fields(self):
     """
     Get serializable fields
     Must be defined in any subclass
     """
     raise NotImplementedException()
コード例 #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
        settings = self.remote.get_settings()

        fields = self.get_fields(object_type)
        network_interface_fields = None
        if object_type == "system":
            network_interface_fields = system.NETWORK_INTERFACE_FIELDS
        if object_action in ["add", "edit", "copy", "rename", "find", "remove"]:
            add_options_from_fields(object_type, self.parser, fields,
                                    network_interface_fields, settings, 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 is 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 xmlrpc.client.Fault as xxx_todo_changeme:
                    (err) = xxx_todo_changeme
                    (etype, emsg) = err.faultString.split(":", 1)
                    print("exception on server: %s" % emsg)
                    sys.exit(1)
                except RuntimeError as xxx_todo_changeme1:
                    (err) = xxx_todo_changeme1
                    print(err.args[0])
                    sys.exit(1)
            elif object_action == "get-autoinstall":
                if object_type == "profile":
                    data = self.remote.generate_profile_autoinstall(options.name)
                elif object_type == "system":
                    data = self.remote.generate_system_autoinstall(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 = list(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")
                try:
                    utils.load_signatures(filename, cache=True)
                except:
                    print("There was an error loading the signature data in %s." % filename)
                    print("Please check the JSON file or run 'cobbler signature update'.")
                    return
                else:
                    print("Signatures were successfully loaded")
            else:
                raise NotImplementedException()
        else:
            raise NotImplementedException()

        # FIXME: add tail/polling code here
        if task_id != -1:
            self.print_task(task_id)
            self.follow_task(task_id)
コード例 #9
0
 def factory_produce(self, collection_mgr, seed_data):
     """
     Must override in subclass.  Factory_produce returns an Item object
     from dict
     """
     raise NotImplementedException()
コード例 #10
0
 def collection_type(self):
     """
     Returns the string key for the name of the collection (for use in messages for humans)
     """
     return NotImplementedException()
コード例 #11
0
 def collection_types() -> str:
     """
     Returns the string key for the plural name of the collection (used by serializer)
     """
     return NotImplementedException()
コード例 #12
0
ファイル: item.py プロジェクト: vzhestkov/cobbler
 def make_clone(self):
     """
     Must be defined in any subclass
     """
     raise NotImplementedException("Must be implemented in a specific Item")