Beispiel #1
0
def dc2_configuration_defaultclasses_update(defclass_rec=None):
    if defclass_rec is not None and type(defclass_rec) is types.DictType:
        if (check_record(defclass_rec, DEFCLASSES_RECORD) and
            '_id' in defclass_rec and
            tbl_server.find_one(
                {"_id": defclass_rec["_id"]}) is not None):
            #
            # Get record of old defaultclasses
            #
            old_record = tbl_server.find_one({"_id": defclass_rec["_id"]})
            doc_id = tbl_server.save(defclass_rec)
            #
            # Check if we are updating
            #
            if doc_id == old_record["_id"]:
                #
                # Get hostlist
                #
                hostlist = tbl_hosts.find()
                for host in hostlist:
                    if 'hostclasses' in host:
                        if old_record["classname"] in host["hostclasses"]:
                            #
                            # Replace old classname in host records with new
                            # defaultclass name
                            #
                            host["hostclasses"][host["hostclasses"].index(
                                old_record["classname"]
                                )] = defclass_rec["classname"]
                            tbl_hosts.save(host)
            return doc_id
    return xmlrpclib.Fault(-32502, "Record couldn't be updated")
Beispiel #2
0
Datei: host.py Projekt: sadig/DC2
def dc2_deployment_hosts_update(record=None):
    if record is not None and type(record) is types.DictType:
        if check_record(record, HOST_RECORD):
            doc_id = None
            old_host_record = tbl_host.find_one({"_id": record["_id"]})
            if (old_host_record is not None and
                    old_host_record["server_id"] == record["server_id"]):
                doc_id = tbl_host.save(record)
                install_rec = tbl_installstate.find_one(
                    {"server_id": record["server_id"]})
                if (install_rec["hostname"] != "{0}.{1}".format(
                        record["hostname"], record["domainname"])):
                    install_rec["hostname"] = "{0}.{1}".format(
                        record["hostname"], record["domainname"])
                    tbl_installstate.save(install_rec)
            else:
                #
                # Check for double host server id
                #
                if tbl_host.find_one(
                        {"server_id": record["server_id"]}) is not None:
                    return xmlrpclib.Fault(
                        -32501, "The Server already has a host attached.")
                doc_id = tbl_host.save(record)
                install_rec = tbl_installstate.find_one(
                    {"host_id": record["_id"]})
                if install_rec is not None:
                    install_rec["server_id"] = record["server_id"]
                    tbl_installstate.save(install_rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be updated")
Beispiel #3
0
def dc2_inventory_networks_update(record=None):
    if record is not None and type(record) is types.DictType:
        if (check_record(record, NETWORK_RECORD) and
                tbl_server.find_one({"_id": record["_id"]}) is not None):
            doc_id = tbl_server.save(record)
            return doc_id
    return xmlrpclib.Fault(-32504, "Record couldn't be updated")
Beispiel #4
0
Datei: host.py Projekt: sadig/DC2
def dc2_deployment_hosts_add(record=None):
    if record is not None and type(record) is types.DictType:
        if (check_record(record, HOST_RECORD) and
                tbl_host.find_one({"server_id": record["server_id"]}) is None):
            doc_id = tbl_host.save(record)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #5
0
def dc2_authentication_groups_add(record=None):
    if record is not None and isinstance(record, dict):
        if (check_record(record, GROUP_RECORD) and
                tbl_groups.find_one(
                    {"groupname": record["groupname"]}) is None):
            doc_id = tbl_groups.save(record)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #6
0
def dc2_servers_update(rec_server=None):
    if rec_server is not None and type(rec_server) is types.DictType:
        if (check_record(rec_server, SERVER_RECORD) and
            tbl_server.find_one({"_id": rec_server["_id"],
                                 "uuid": rec_server["uuid"]}) is not None):
            doc_id = tbl_server.save(rec_server)
            return doc_id
    return xmlrpclib.Fault(-32504, "Record couldn't be updated")
Beispiel #7
0
def dc2_authentication_users_update(record=None):
    if record is not None and isinstance(record, dict):
        if (check_record(record, USER_RECORD) and
                tbl_users.find_one(
                    {"username": record["useranme"]}) is not None):
            doc_id = tbl_users.save(record)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be updated")
Beispiel #8
0
def dc2_servers_macaddr_add(rec_mac=None):
    if rec_mac is not None and type(rec_mac) is types.DictType:
        if (check_record(rec_mac, MACADDR_RECORD) and
                tbl_server.find_one(
                    {"mac_addr": rec_mac["mac_addr"]}) is None):
            doc_id = tbl_server.save(rec_mac)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #9
0
def dc2_deployment_environments_add(env_rec=None):
    if env_rec is not None and type(env_rec) is types.DictType:
        if (check_record(env_rec, ENVIRONMENT_RECORDS) and
            'name' in env_rec and
                tbl_environments.find_one({"name": env_rec["name"]}) is None):
            doc_id = tbl_environments.save(env_rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #10
0
def dc2_servers_add(rec_server=None):
    if rec_server is not None and type(rec_server) is types.DictType:
        if (check_record(rec_server, SERVER_RECORD) and
                tbl_server.find_one(
                {"uuid": rec_server["uuid"]}) is None):
            doc_id = tbl_server.save(rec_server)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record wasn't added!")
Beispiel #11
0
def dc2_configuration_defaultbootmethods_update(rec=None):
    if rec is not None and type(rec) is types.DictType:
        if (check_record(rec, DEFBOOT_RECORD) and
            'hardware_type' in rec and
                tbl_bootmethods.find_one(
                    {"hardware_type": rec["hardware_type"]}) is not None):
            doc_id = tbl_bootmethods.save(rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record could not be updates")
Beispiel #12
0
def dc2_deployment_installstate_add(record=None):
    if record is not None and type(record) is types.DictType:
        if (check_record(record, INSTALLSTATUS_RECORD) and
                tbl_installstatus.find_one(
                    {"server_id": record["server_id"],
                        "host_id": record["host_id"]}) is None):
            doc_id = tbl_installstatus.save(record)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #13
0
def dc2_configuration_xenanswerfile_update(rec=None):
    if rec is not None and type(rec) is types.DictType:
        if (check_record(rec, XEN_RECORD) and
            'filename' in rec and
            tbl_xenanswerfiles.find_fond(
                {"filename": rec["filename"]}) is not None):
            doc_id = tbl_xenanswerfiles.save(rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record could not be updates")
Beispiel #14
0
Datei: rib.py Projekt: sadig/DC2
def dc2_servers_rib_update(rec_rib=None):
    if rec_rib is not None and type(rec_rib) is types.DictType:
        if (
            check_record(rec_rib, RIB_RECORD)
            and tbl_server.find_one({"_id": rec_rib["_id"], "server_id": rec_rib["server_id"]}) is not None
        ):
            doc_id = tbl_server.save(rec_rib)
            return doc_id
    return xmlrpclib.Fault(-32504, "Record couldn't be updated")
Beispiel #15
0
def dc2_configuration_defaultclasses_add(defclass_rec=None):
    if defclass_rec is not None and type(defclass_rec) is types.DictType:
        if (check_record(defclass_rec, DEFCLASSES_RECORD) and
            'classname' in defclass_rec and
            tbl_server.find_one(
                {"classname": defclass_rec["classname"]}) is None):
            doc_id = tbl_server.save(defclass_rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #16
0
def dc2_servers_macaddr_update(rec_mac=None):
    if rec_mac is not None and type(rec_mac) is types.DictType:
        if (check_record(rec_mac, MACADDR_RECORD) and
                tbl_server.find_one({
                    "_id": rec_mac["_id"],
                    "server_id": rec_mac["server_id"]}) is not None):
            doc_id = tbl_server.save(rec_mac)
            return doc_id
    return xmlrpclib.Fault(-32504, "Record couldn't be updated")
Beispiel #17
0
def dc2_configuration_systemusers_update(rec=None):
    if rec is not None and type(rec) is types.DictType:
        if (
            check_record(rec, SYSUSERS_RECORD)
            and "username" in rec
            and tbl_systemusers.find_one({"username": rec["username"]}) is not None
        ):
            doc_id = tbl_systemusers.save(rec)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record could not be updated")
Beispiel #18
0
def dc2_configuration_systemgroups_update(rec=None):
    if rec is not None and type(rec) is types.DictType:
        if (
            check_record(rec, SYSGROUP_RECORD)
            and "_id" in rec
            and tbl_systemgroups.find_one({"_id": rec["_id"]}) is not None
        ):
            doc_id = tbl_systemgroups.save(rec)
            return doc_id
    return xmlrpclib.fault(-32501, "Record could not be updated")
Beispiel #19
0
def dc2_configuration_classtemplates_add(record=None):
    if record is not None and type(record) is types.DictType:
        if (check_record(record, TEMPLATE_RECORD) and
                "name" in record and
                tbl_templates.find_one({"name": record["name"]}) is None):
            try:
                doc_id = tbl_templates.save(record)
                return doc_id
            except Exception as e:
                return xmlrpclib.Fault(
                    -32501,
                    "Record couldn't be added {0}".format(e))
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #20
0
def dc2_dhcp_mgmt_add(record=None):
    if record is not None and isinstance(record, dict):
        if (check_record(record, DHCP_RECORD) and
                tbl_dhcp_mgmt.find_one({
                    'ipspace': record['ipspace']}) is None):
            try:
                ip = netaddr.IPNetwork(record['ipspace'])
                if ip.size == 256:
                    doc_id = tbl_dhcp_mgmt.save(record)
                    return doc_id
            except netaddr.core.AddrFormatError as e:
                return xmlrpclib.Fault(-32501, e)
    return xmlrpclib.Fault(-32501, 'Record was not added')
Beispiel #21
0
def dc2_inventory_networks_add(record=None):
    if record is not None and type(record) is types.DictType:
        if check_record(record, NETWORK_RECORD):
            doc_id = tbl_server.save(record)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")
Beispiel #22
0
Datei: rib.py Projekt: sadig/DC2
def dc2_servers_rib_add(rec_rib=None):
    if rec_rib is not None and type(rec_rib) is types.DictType:
        if check_record(rec_rib, RIB_RECORD):
            doc_id = tbl_server.save(rec_rib)
            return doc_id
    return xmlrpclib.Fault(-32501, "Record couldn't be added")