示例#1
0
def serialize_item(collection, item):
    """
    Save a collection item to file system

    :param collection: collection
    :param item: collection item
    """

    if not item.name:
        raise CX("name unset for item!")

    collection_types = collection.collection_types()
    filename = os.path.join(libpath, collection_types, item.name + ".json")

    _dict = item.to_dict()

    if capi.CobblerAPI().settings().serializer_pretty_json:
        sort_keys = True
        indent = 4
    else:
        sort_keys = False
        indent = None

    filename += ".json"
    _dict = item.to_dict()
    fd = open(filename, "w+")
    data = simplejson.dumps(_dict, encoding="utf-8", sort_keys=sort_keys, indent=indent)
    fd.write(data)

    fd.close()
示例#2
0
def serialize_item(collection, item):
    """
    Save a collection item to file system

    :param collection: collection
    :param item: collection item
    """

    if not item.name:
        raise CX("name unset for item!")

    collection_types = collection.collection_types()
    filename = os.path.join(libpath, collection_types, item.name + ".json")
    __find_double_json_files(filename)

    if capi.CobblerAPI().settings().serializer_pretty_json:
        sort_keys = True
        indent = 4
    else:
        sort_keys = False
        indent = None

    _dict = item.serialize()
    with open(filename, "w+") as file_descriptor:
        data = json.dumps(_dict, sort_keys=sort_keys, indent=indent)
        file_descriptor.write(data)
示例#3
0
def serialize_item(collection, item):
    """
    Save a collection item to file system

    @param collection name
    @param item dictionary
    """

    filename = "/var/lib/cobbler/collections/%s/%s" % (collection,
                                                       item['name'])

    if capi.CobblerAPI().settings().serializer_pretty_json:
        sort_keys = True
        indent = 4
    else:
        sort_keys = False
        indent = None

    filename += ".json"
    fd = open(filename, "w+")
    data = simplejson.dumps(item,
                            encoding="utf-8",
                            sort_keys=sort_keys,
                            indent=indent)
    fd.write(data)

    fd.close()
示例#4
0
def serialize_item(collection, item):
    """
    Save a collection item to file system

    @param Collection collection collection
    @param Item item collection item
    """

    if item.name is None or item.name == "":
        raise exceptions.RuntimeError("name unset for item!")

    # FIXME: Need a better way to support collections/items
    # appending an 's' does not work in all cases
    if collection.collection_type() in ['mgmtclass']:
        filename = "/var/lib/cobbler/collections/%ses/%s" % (collection.collection_type(), item.name)
    else:
        filename = "/var/lib/cobbler/collections/%ss/%s" % (collection.collection_type(), item.name)

    _dict = item.to_dict()

    if capi.CobblerAPI().settings().serializer_pretty_json:
        sort_keys = True
        indent = 4
    else:
        sort_keys = False
        indent = None

    filename += ".json"
    _dict = item.to_dict()
    fd = open(filename, "w+")
    data = simplejson.dumps(_dict, encoding="utf-8", sort_keys=sort_keys, indent=indent)
    fd.write(data)

    fd.close()
示例#5
0
 def __init__(self, hostname):
     """Constructor. Requires a Cobbler API handle."""
     self.hostname = hostname
     self.handle = capi.CobblerAPI()
     self.system = self.handle.find_system(hostname=self.hostname)
     self.host_vars = self.get_cobbler_resource('autoinstall_meta')
     self.logger = clogger.Logger("/var/log/cobbler/cobbler.log")
     self.mgmtclasses = self.get_cobbler_resource('mgmt_classes')
示例#6
0
def test_settings_list(login_web):
    client, response = login_web( reverse('setting_list') )

    assert response.status_code == 200
    assert 'settings.tmpl' in (t.name for t in response.templates)

    # ensure all settings are listed
    api = cobbler_api.CobblerAPI()
    settings = api.settings().to_dict()
    for k in settings.keys():
        assert k.encode('utf-8') in response.content
示例#7
0
    def __init__(self, hostname):
        """
        Constructor. Requires a Cobbler API handle.

        :param hostname: The hostname to run config-generation for.
        """
        self.hostname = hostname
        self.handle = capi.CobblerAPI()
        self.system = self.handle.find_system(hostname=self.hostname)
        self.host_vars = self.get_cobbler_resource('autoinstall_meta')
        self.logger = clogger.Logger()
        self.mgmtclasses = self.get_cobbler_resource('mgmt_classes')
示例#8
0
文件: ldap.py 项目: y2kenny/cobbler
        except:
            traceback.print_exc()
            return False

    # perform a subtree search in basedn to find the full dn of the user
    # TODO: what if username is a CN?  maybe it goes into the config file as well?
    filter = prefix + username
    result = dir.search_s(basedn, ldap.SCOPE_SUBTREE, filter, [])
    if result:
        for dn, entry in result:
            # username _should_ be unique so we should only have one result ignore entry; we don't need it
            pass
    else:
        return False

    try:
        # attempt to bind as the user
        dir.simple_bind_s(dn, password)
        dir.unbind()
        return True
    except:
        # traceback.print_exc()
        return False
    # catch-all
    return False


if __name__ == "__main__":
    api_handle = cobbler_api.CobblerAPI()
    print((authenticate(api_handle, "guest", "guest")))
示例#9
0
def log(logger, msg):
    if logger is not None:
        logger.info(msg)
    else:
        print(msg, file=sys.stderr)


def do_xmlrpc_rw(cobbler_api, settings, port):

    xinterface = remote.ProxiedXMLRPCInterface(cobbler_api,
                                               remote.CobblerXMLRPCInterface)
    server = remote.CobblerXMLRPCServer(('127.0.0.1', port))
    server.logRequests = 0  # don't print stuff
    xinterface.logger.debug("XMLRPC running on %s" % port)
    server.register_instance(xinterface)

    while True:
        try:
            print("SERVING!")
            server.serve_forever()
        except IOError:
            # interrupted? try to serve again
            time.sleep(0.5)


if __name__ == "__main__":
    cobbler_api = cobbler_api.CobblerAPI()
    settings = cobbler_api.settings()
    regen_ss_file()
    do_xmlrpc_rw(cobbler_api, settings, 25151)