示例#1
0
def shutdown(TheInterface):
    TheInterfaceMainName = TheInterface.name
    ethernet_filename = "ifcfg-" + TheInterfaceMainName
    ethernet_file_object = File(ethernet_filename, NETWORK_CONF_PATH)
    if not ethernet_file_object.Existed():
        return False
    for line in ethernet_file_object.Read().split("\n"):
        match = re.search('^iface\s+(\S+)\s+inet', line)
        if match:
            TheInterfaceName = match.group(1)
            ethernet_object = NetworkInterface(TheInterfaceName)
            ethernet_object.ifDown()
            ethernet_object.Down()
    return True
示例#2
0
def ethernet_read(request):
    ethernets = Ethernet.objects.all().order_by("name")
    records = []
    for each_ethernet in ethernets:
        if each_ethernet.dhcp:
            ethernet_object = NetworkInterface(each_ethernet.name)
            IPv4Addresses = ethernet_object.List().ip
        else:
            IPv4Addresses = each_ethernet.ipv4address
        records.append({
            "Author": each_ethernet.author.username,
            "EthernetId": each_ethernet.id,
            "Name": each_ethernet.name,
            "Description": each_ethernet.desc,
            "Status": each_ethernet.status,
            "Link": each_ethernet.link,
            "Mac": each_ethernet.mac,
            "Dhcp": each_ethernet.dhcp,
            'IPv4Address': IPv4Addresses,
            'Gateway': each_ethernet.gateway,
            'ManualDns': each_ethernet.manual_dns,
            'DnsServer': each_ethernet.dnsserver,
            'Mtu': each_ethernet.mtu,
            'ManualMss': each_ethernet.manual_mss,
            'Mss': each_ethernet.mss,
            "AddedDate": each_ethernet.added_date,
            "EditedDate": each_ethernet.edited_date
        })

    parsed_json = records
    json_length = len(parsed_json)

    start = int(request.GET["StartIndex"])
    pageSize = int(request.GET["PageSize"])
    page_length = (start + pageSize) if (
        start + pageSize < json_length) else json_length
    parsed_json = parsed_json[start:page_length]
    parsed_json = {
        'Result': "OK",
        'TotalRecordCount': json_length,
        'Records': parsed_json
    }

    data = json.dumps(parsed_json)

    response = HttpResponse()
    response['Content-Type'] = "application/json"
    response.write(data)
    return response
示例#3
0
def getEthernetLinkStatus(request):
    EthernetObject = NetworkInterface()
    records = []
    for iface in EthernetObject.List():
        eachEthernetObjects = NetworkInterface(iface.name)
        records.append({
            "Name": iface.name,
            "Link": eachEthernetObjects.getLink()
        })
    data = json.dumps(records)

    response = HttpResponse()
    response['Content-Type'] = "application/json"
    response.write(data)
    return response
示例#4
0
def getEthernetLink(interface):
    ethernet_object = NetworkInterface(interface)
    return ethernet_object.getLink()
示例#5
0
def getEthernetHwAddress(interface):
    ethernet_object = NetworkInterface(interface)
    return ethernet_object.List().mac
示例#6
0
def getEthernetRealInterfaces():
    EthernetObject = NetworkInterface()
    result = []
    for iface in EthernetObject.List():
        result.append(iface.name)
    return result