コード例 #1
0
ファイル: ccs_rurallink.py プロジェクト: libzz/amiral
def addRurallinkAsset(session_id, eth0mac):
    """Creates a new RuralLink asset"""

    setmac = False
    setserial = False

    try:
        serial = getSoekrisSerial(eth0mac)
        type = TYPE_SOEKRIS
    except:
        type = TYPE_WRAP

    asset = {}
    asset["asset_type"] = getRurallinkAssetType(session_id, type)
    if type == TYPE_SOEKRIS:
        asset["serial_no"] = serial
    asset["description"] = "RuralLink Farm Device"
    asset["date_purchased"] = time.strftime("%Y-%m-%d")
    asset["enabled"] = "t"
    asset["subassets"] = {}

    # Now setup the subassets
    for subasset in getLinkedSubassets(session_id, asset["asset_type"]):
        sadata = {}
        # Skip optional subassets
        if not subasset["required"]:
            continue
        sadata["enabled"] = "t"
        sadata["properties"] = {}
        for prop in getLinkedProperties(session_id, subasset["subasset_type_id"]):
            # Look for eth0 mac to set
            if subasset["name"] == "eth0" and prop["description"] == "MAC Address":
                val = eth0mac
                setmac = True
            elif prop["description"] == RURALLINK_SERIAL_DESCRIPTION:
                val = allocateRurallinkSerial(session_id, type)
                setserial = True
            else:
                # Skip optional properties
                if not prop["required"]:
                    continue
                val = prop["default_value"]
            sadata["properties"][prop["subasset_property_id"]] = val
        asset["subassets"][subasset["asset_type_subasset_id"]] = sadata

    # Check the MAC addres and Serial properties were set
    if not setmac or not setserial:
        raise ccs_rurallink_error(
            "Unable to create device asset. Asset "
            "type %d lacks necessary properties! (%s, %s)" % (asset["asset_type"], setmac, setserial)
        )

    # Add the asset and return the newly created object
    asset_id = addAsset(session_id, asset)
    return getAsset(session_id, asset_id)
コード例 #2
0
ファイル: ccs_rurallink.py プロジェクト: libzz/amiral
def addRurallinkWirelessAsset(session_id, mac):
    """Creates a new RuralLink wireless card asset"""

    setmac = False

    asset = {}
    asset["asset_type"] = getRurallinkWirelessType(session_id, mac)
    asset["description"] = "miniPCI 802.11abg card"
    asset["date_purchased"] = time.strftime("%Y-%m-%d")
    asset["enabled"] = "t"
    asset["subassets"] = {}

    # Now setup the subassets
    for subasset in getLinkedSubassets(session_id, asset["asset_type"]):
        sadata = {}
        # Skip optional subassets
        if not subasset["required"]:
            continue
        sadata["enabled"] = "t"
        sadata["properties"] = {}
        for prop in getLinkedProperties(session_id, subasset["subasset_type_id"]):
            # Look for eth0 mac to set
            if subasset["name"] == "wireless" and prop["description"] == "MAC Address":
                val = mac
                setmac = True
            else:
                # Skip optional properties
                if not prop["required"]:
                    continue
                val = prop["default_value"]
            sadata["properties"][prop["subasset_property_id"]] = val
        asset["subassets"][subasset["asset_type_subasset_id"]] = sadata

    # Check the MAC addres and Serial properties were set
    if not setmac:
        raise ccs_rurallink_error(
            "Unable to create wireless asset. Asset " "type %d lacks necessary properties!" % (asset["asset_type"])
        )

    # Add the asset and return the newly created object
    asset_id = addAsset(session_id, asset)
    return getAsset(session_id, asset_id)