Exemple #1
0
def process_objects(objects, name):
    """
      returns the report of a specific name in 'objects', objects defined in SUPPORTED_OBJECTS
      e.g. http://host:port/cm/v1/cobbler/distros/test-x86_64
    """
    if objects not in SUPPORTED_OBJECTS:
        return not_supported_objects(objects)
    item = objects[:-1]  # value of objects does NOT contain the last 's'
    cp = CobblerProvision()
    method = request.method
    if method == "GET":
        # MUST know how to get user token, empty token ONLY for debug
        kwargs = {"user_token": ""}
        func = getattr(cp, "get_{0}_report".format(item))
        return func(name, **kwargs)

    data = request.json
    if method == "POST":
        if item == "distro":
            return cp.import_distro(name, **data)
        if item == "profile":
            kickstart_file = data.get("kickstart", None)
            if kickstart_file:
                if not kickstart_file.startswith("/"):
                    data[
                        "kickstart"] = "{0}/{1}".format(KICKSTART_LOCATION, kickstart_file)
            return cp.add_profile(name, **data)
        if item == "system":
            return cp.add_system(name, **data)
        if item == "kickstart":
            lines = data.get("contents", [])
            return cp.update_kickstart(name, lines, **data)
    if method == "PUT":
        if item == "distro":
            return cp.update_distro(name, **data)
        if item == "profile":
            kickstart_file = data.get("kickstart", None)
            if kickstart_file:
                if not kickstart_file.startswith("/"):
                    data[
                        "kickstart"] = "{0}/{1}".format(KICKSTART_LOCATION, kickstart_file)
            return cp.update_profile(name, **data)
        if item == "system":
            return cp.update_system(name, **data)
        if item == "kickstart":
            lines = data.get("contents", [])
            return cp.update_kickstart(name, lines, **data)
    if method == "DELETE":
        func = getattr(cp, "remove_{0}".format(item))
        return func(name, **data)
def baremetal_system(system):
    cp = CobblerProvision()
    # monitor system
    if request.method == "GET":
        # MUST know how to get user token, empty token ONLY for debug
        kwargs = {"user_token": ""}
        return cp.monitor_system(system, **kwargs)
    data = request.json
    # deploy system
    if request.method == "POST":
        return cp.deploy_system(system, **data)
    # power system
    if request.method == "PUT":
        return cp.power_system(system, **data)
Exemple #3
0
def baremetal_system(system):
    cp = CobblerProvision()
    # monitor system
    if request.method == "GET":
        # MUST know how to get user token, empty token ONLY for debug
        kwargs = {"user_token": ""}
        return cp.monitor_system(system, **kwargs)
    data = request.json
    # deploy system
    if request.method == "POST":
        return cp.deploy_system(system, **data)
    # power system
    if request.method == "PUT":
        return cp.power_system(system, **data)
Exemple #4
0
def list_objects(objects):
    """
      returns the names of all possible 'objects', objects defined in SUPPORTED_OBJECTS or "isos" means distribution iso file
      e.g. http://host:port/cm/v1/cobbler/distros
    """
    if objects not in SUPPORTED_OBJECTS and objects not in ["isos"]:
        return not_supported_objects(objects)
    # MUST know how to get user token, empty token ONLY for debug
    kwargs = {"user_token": ""}
    item = objects[:-1]  # value of objects does NOT contain the last 's'
    cp = CobblerProvision()
    func = getattr(cp, "list_{0}_names".format(item))
    return func(**kwargs)
Exemple #5
0
def list_kickstart_profiles(name):
    """
      returns the list of profile name matching the name of kickstart file
      e.g. http://host:port/cm/v1/cobbler/kickstarts/default.ks/profile
    """
    cp = CobblerProvision()
    method = request.method
    if method == "GET":
        # MUST know how to get user token, empty token ONLY for debug
        kwargs = {"user_token": ""}
        func = getattr(cp, "get_profile_match_kickstart")
        return func(name)
    return None
Exemple #6
0
def list_child_objects(objects, name):
    """
      returns the child list of a specific name in 'objects', objects defined in SUPPORTED_OBJECTS
      e.g. http://host:port/cm/v1/cobbler/distros/test-x86_64/child
    """
    if objects not in SUPPORTED_OBJECTS:
        return not_supported_objects(objects)
    item = objects[:-1]  # value of objects does NOT contain the last 's'
    cp = CobblerProvision()
    method = request.method
    if method == "GET":
        # MUST know how to get user token, empty token ONLY for debug
        kwargs = {"user_token": ""}
        func = getattr(cp, "get_object_child_list")
        return func(item, name)
    return None
Exemple #7
0
def process_system_interfaces(system_name, if_name):
    cp = CobblerProvision()
    data = request.json
    func = getattr(cp, "remove_{0}".format("system_interface"))
    return func(system_name, if_name, **data)