Example #1
0
def build_eth_config(subnet, template_config):
    plLogger.LogInfo("build_eth_config: ")

    config_utils.init_config(template_config)

    mac_port_step = None
    if subnet["mac_config"]["_type"] != "Profile::UniqueMacConfig":
        mac_port_step = subnet["mac_config"]["mac_port_step"]

    mac_config = subnet["mac_config"]
    dev_count = subnet["device_count_per_port"]
    if mac_config["_type"] == "Profile::UniqueMacConfig":
        if dev_count > 1:
            # randomize mac is handled outside of this command
            return
        else:
            handle_physical_interface_mac(template_config, subnet)
            return
    plLogger.LogInfo(str(mac_config))
    mac = str(mac_config["mac"])
    mac_step = str(mac_config["mac_step"])

    tag_name = tag_name_util.get_ethIIIf_tag(subnet)

    property_value = {
        "className": "EthIIIf",
        "tagName": tag_name,
        "propertyValueList": {
            "SrcMacStep": mac_step
        }
    }
    property_value_list = config_utils.get_property_value_list(template_config)
    property_value_list.append(property_value)

    stm_property_modifier = {
        "className": "EthIIIf",
        "tagName": tag_name + ".SourceMac",
        "parentTagName": tag_name,
        "propertyName": "SourceMac",
        "propertyValueList": {
            "Start": mac,
            "Step": mac_port_step,
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    stm_property_modifier_list.append(stm_property_modifier)
Example #2
0
def create_config(subnet, template_name, tag_prefix):
    template_config = {}
    config_utils.init_config(template_config)
    template_config["baseTemplateFile"] = template_name
    template_config["tagPrefix"] = tag_prefix
    tag_name = tag_name_util.get_dev_tag(subnet)
    property_value = {
        "className": "EmulatedDevice",
        "tagName": tag_name,
        "propertyValueList": {
            "DeviceCount": str(subnet["device_count_per_port"])
        }
    }
    property_value_list = config_utils.get_property_value_list(template_config)
    property_value_list.append(property_value)
    return template_config
Example #3
0
def pack(gameID, channelID, packID, tempFilePath):

    log_utils.debug("now to pack. gameID:"+gameID+";channelID:"+channelID+";packID:"+packID+";temp file path:"+tempFilePath)
    print("begin to pack....")
    sys.stdout.flush()

    config_utils.init_config(tempFilePath, gameID)

    print("begin to pack 2....")
    sys.stdout.flush()

    game = db_utils.get_game_by_id(gameID)
    if game == None:
        log_utils.error("game not exists in db. gameID:"+gameID)
        return 1

    channel = db_utils.get_channel_by_id(channelID)
    if game == None:
        log_utils.error("channel not exists in db. channel id:"+channelID)
        return 1

    packlog = db_utils.get_packlog_by_id(packID)
    if packlog == None:
        log_utils.error("channel packlog not exists in db. packID:"+packID)
        return 1

    keystore = db_utils.get_keystore_by_id(channel["keystoreID"])
    if channel["signApk"] == 1 and keystore == None:
        log_utils.error("curr config need sign apk but keystore not exists in db. keystore id:"+channel["keystoreID"])
        return 1

    log_utils.info("now to package %s...", channel["channelName"])

    #load channel config.xml
    ret = config_utils.load_channel_config(game, channel, packlog)
    if ret:
        log_utils.error("load channel config failed. "+ channel['channelName'])
        return 1


    ret = builder.build(game, channel, packID+".apk", keystore)

    if ret:

        return 0

    return 1
Example #4
0
def pack(gameID, channelID, packID, tempFilePath):
    log_utils.debug("开始打包: gameID:" + gameID + ";channelID:" + channelID +
                    ";packID:" + packID + ";temp file path:" + tempFilePath)

    # 设置临时环境变量
    os.environ['JAVA_HOME'] = file_utils.getJavaDir()
    os.environ['CLASSPATH'] = ''

    config_utils.init_config(tempFilePath, gameID)

    game = db_utils.get_game_by_id(gameID)
    if game == None:
        log_utils.error("game not exists in db. gameID:" + gameID)
        return 1

    channel = db_utils.get_channel_by_id(channelID)
    if game == None:
        log_utils.error("channel not exists in db. channel id:" + channelID)
        return 1

    packlog = db_utils.get_packlog_by_id(packID)
    if packlog == None:
        log_utils.error("channel packlog not exists in db. packID:" + packID)
        return 1

    keystore = db_utils.get_keystore_by_id(channel["keystoreID"])
    if channel["signApk"] == 1 and keystore == None:
        log_utils.error(
            "curr config need sign apk but keystore not exists in db. keystore id:"
            + channel["keystoreID"])
        return 1

    log_utils.info("now to package %s...", channel["channelName"])

    # load channel config.xml
    ret = config_utils.load_channel_config(game, channel, packlog)
    if ret:
        log_utils.error("load channel config failed. " +
                        channel['channelName'])
        return 1

    ret = builder.build(game, channel, packID + ".apk", keystore)

    if ret:
        return 0

    return 1
Example #5
0
def build_dhcp_config(subnet, template_config):
    plLogger.LogInfo("build_dhcp_config: ")

    if not subnet["dhcp_enabled"]:
        plLogger.LogInfo("dhcp disabled")
        return

    config_utils.init_config(template_config)
    tag_name = None
    dev_tag_name = tag_name_util.get_dev_tag(subnet)
    if subnet["ip_config"]["_type"] == "Profile::Ipv4Config":
        tag_name = tag_name_util.get_dhcpv4_tag(subnet)
    else:
        raise Exception("DHCP for Ipv6 is not supported")

    merge_list = config_utils.get_merge_list(template_config)
    merge_list.append(
        {
            "mergeSourceTemplateFile": "Access_Protocols.xml",
            "mergeSourceTag": tag_name,
            "mergeTargetTag": dev_tag_name
        }
    )

    if subnet["gateway_config"]["_type"] == "Profile::GatewayDhcpConfig":
        option_list = ["1", "3", "6", "15", "33", "44"]
        property_value = {
            "className": "Dhcpv4BlockConfig",
            "tagName": tag_name,
            "propertyValueList": {
                "OptionList": option_list,
                "EnableRouterOption": "TRUE"
            }
        }
        property_value_list = config_utils.get_property_value_list(
            template_config
        )
        property_value_list.append(property_value)
Example #6
0
def build_ipv4_config(subnet, template_config):
    plLogger.LogInfo("build_ipv4_config: ")

    config_utils.init_config(template_config)

    gateway_type = subnet["gateway_config"]["_type"]
    ip_config = subnet["ip_config"]
    ipv4_port_step = ip_config["ipv4_port_step"]
    gateway_ipv4_port_step = None
    gateway_mac_port_step = None
    gateway_config = subnet["gateway_config"]
    if gateway_type == "Profile::GatewayArpConfig":
        gw_ip_config = gateway_config.get("ip_config")
        gateway_ipv4_port_step = gw_ip_config["ipv4_port_step"]
    elif gateway_type == "Profile::GatewayMacConfig":
        gateway_mac_port_step = gateway_config["mac_port_step"]
    gateway_config = subnet["gateway_config"]
    ip_config = subnet["ip_config"]
    gateway_type = gateway_config["_type"]
    gw_ip_config = gateway_config.get("ip_config")

    ipv4 = str(ip_config["ipv4"])
    ipv4_step = str(ip_config["ipv4_step"])
    prefix = str(ip_config["prefix"])
    pri = 0
    if "control_plane_priority" in ip_config:
        pri_str = str(ip_config["control_plane_priority"])
        if pri_str == "routine":
            pri = 0
        elif pri_str == "high":
            pri = 32
        else:
            pri = 0
    # Modify the Ipv4If parameters
    # Attach StmPropertyModifier objects to the Address and Gateway
    # fields.
    # Address
    tag_name = tag_name_util.get_ipv4If_tag(subnet)
    stm_property_modifier_list = config_utils.get_stm_property_modifier_list(
        template_config
    )
    property_value_list = config_utils.get_property_value_list(template_config)

    ipv4_stm_property_modifier = {
        "className": "Ipv4If",
        "tagName": tag_name + ".Address",
        "parentTagName": tag_name,
        "propertyName": "Address",
        "propertyValueList": {
            "Start": ipv4,
            "Step": ipv4_port_step,
            "ResetOnNewTargetObject": False
        }
    }
    stm_property_modifier_list.append(ipv4_stm_property_modifier)

    # Gateway
    # Profile::GatewayDhcpConfig is handled in dhcp_builder
    if gateway_type == "Profile::GatewayArpConfig":
        process_gateway_arp_config(subnet,
                                   template_config,
                                   gateway_ipv4_port_step)
    elif gateway_type == "Profile::GatewayMacConfig":
        process_gateway_mac_config(subnet,
                                   template_config,
                                   gateway_mac_port_step)
    # Modify any other parameters not on the StmPropertyModifier
    ipv4_property_value = {
        "className": "Ipv4If",
        "tagName": tag_name,
        "propertyValueList": {
            "AddrStep": ipv4_step,
            "PrefixLength": prefix,
            "Tos": str(pri)
        }
    }
    if gateway_type == "Profile::GatewayArpConfig":
        gw_step = str(gw_ip_config["ipv4_step"])
        ipv4_property_value["propertyValueList"]["GatewayStep"] = gw_step
    elif gateway_type == "Profile::GatewayMacConfig":
        ipv4_property_value["propertyValueList"]["ResolveGatewayMac"] = "FALSE"
    property_value_list.append(ipv4_property_value)