コード例 #1
0
def remove_dns_server(ns, setting, address):
    '''
    Remove dns server from given setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    # Check the IP address
    address, version = util.address_check(address)

    protocolIFType = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.value(
        "IPv%d" % version)
    for settingData in setting.associators(
            AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.classname == "LMI_DNSSettingData"
                and settingData.ProtocolIFType == protocolIFType):
            for i in range(len(settingData.DNSServerAddresses)):
                if util.compare_address(settingData.DNSServerAddresses[i],
                                        address):
                    del settingData.DNSServerAddresses[i]
                    settingData.push()
                    return 0
            else:
                raise LmiInvalidOptions(
                    "No DNS with address %s found for setting %s" %
                    (address, setting.Caption))
    else:
        raise LmiInvalidOptions(
            "Can't remove DNS address to setting %s, invalid setting type" %
            setting.Caption)
    LOG().info("DNS server %s removed from setting %s", address,
               setting.Caption)
    return 0
コード例 #2
0
def remove_ip_address(ns, setting, address):
    '''
    Remove the IP address from given static setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    address, version = util.address_check(address)

    protocol = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.values_dict()["IPv%s" % version]
    found = False
    for settingData in setting.associators(AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.ProtocolIFType is not None and
                int(settingData.ProtocolIFType) == protocol and
                hasattr(settingData, "IPAddresses")):

            i = 0
            while i < len(settingData.IPAddresses):
                if util.compare_address(settingData.IPAddresses[i], address):
                    del settingData.IPAddresses[i]
                    if version == 4:
                        del settingData.SubnetMasks[i]
                    else:
                        del settingData.IPv6SubnetPrefixLengths[i]
                    del settingData.GatewayAddresses[i]
                    found = True
                i += 1
            settingData.push()
    if not found:
        raise LmiInvalidOptions("Can't remove IP address from setting: invalid setting type or address doesn't exist.")
    LOG().info("IP address %s removed from setting %s", address, setting.Caption)
    return 0
コード例 #3
0
ファイル: __init__.py プロジェクト: jsafrane/openlmi-scripts
def remove_dns_server(ns, setting, address):
    '''
    Remove dns server from given setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    # Check the IP address
    address, version = util.address_check(address)

    protocolIFType = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.value("IPv%d" % version)
    for settingData in setting.associators(AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.classname == "LMI_DNSSettingData" and settingData.ProtocolIFType == protocolIFType):
            dns = []
            for addr in settingData.DNSServerAddresses:
                if not util.compare_address(addr, address):
                    dns.append(addr)
            if len(dns) == len(settingData.DNSServerAddresses):
                raise LmiInvalidOptions("No DNS with address %s found for setting %s" % (address, setting.Caption))
            settingData.DNSServerAddresses = dns
            settingData.push()
            return 0
    else:
        raise LmiInvalidOptions("Can't remove DNS address to setting %s, invalid setting type" % setting.Caption)
    LOG().info("DNS server %s removed from setting %s", address, setting.Caption)
    return 0
コード例 #4
0
def remove_ip_address(ns, setting, address):
    '''
    Remove the IP address from given static setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    address, version = util.address_check(address)

    protocol = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.values_dict(
    )["IPv%s" % version]
    found = False
    for settingData in setting.associators(
            AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.ProtocolIFType is not None
                and int(settingData.ProtocolIFType) == protocol
                and hasattr(settingData, "IPAddresses")):

            i = 0
            while i < len(settingData.IPAddresses):
                if util.compare_address(settingData.IPAddresses[i], address):
                    del settingData.IPAddresses[i]
                    if version == 4:
                        del settingData.SubnetMasks[i]
                    else:
                        del settingData.IPv6SubnetPrefixLengths[i]
                    del settingData.GatewayAddresses[i]
                    found = True
                i += 1
            settingData.push()
    if not found:
        raise LmiInvalidOptions(
            "Can't remove IP address from setting: invalid setting type or address doesn't exist."
        )
    return 0
コード例 #5
0
def remove_ip_address(ns, setting, address):
    '''
    Remove the IP address from given static setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    address, version = util.address_check(address)

    protocol = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.values_dict(
    )["IPv%s" % version]
    found = False
    for settingData in setting.associators(
            AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.ProtocolIFType is not None
                and int(settingData.ProtocolIFType) == protocol
                and hasattr(settingData, "IPAddresses")):

            i = 0
            # lmishell doesn't handle in-place editing of array parameters properly,
            # we need to create new arrays and then copy them back
            addresses = []
            masks = []
            gateways = []
            while i < len(settingData.IPAddresses):
                if not util.compare_address(settingData.IPAddresses[i],
                                            address):
                    addresses.append(settingData.IPAddresses[i])
                    if version == 4:
                        masks.append(settingData.SubnetMasks[i])
                    else:
                        masks.append(settingData.IPv6SubnetPrefixLengths[i])
                    gateways.append(settingData.GatewayAddresses[i])
                else:
                    found = True
                i += 1
            settingData.IPAddresses = addresses
            if version == 4:
                settingData.SubnetMasks = masks
            else:
                settingData.IPv6SubnetPrefixLengths = masks
            settingData.GatewayAddresses = gateways
            settingData.push()
    if not found:
        raise LmiInvalidOptions(
            "Can't remove IP address from setting: invalid setting type or address doesn't exist."
        )
    LOG().info("IP address %s removed from setting %s", address,
               setting.Caption)
    return 0
コード例 #6
0
ファイル: __init__.py プロジェクト: jsafrane/openlmi-scripts
def remove_ip_address(ns, setting, address):
    '''
    Remove the IP address from given static setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    address, version = util.address_check(address)

    protocol = ns.LMI_IPAssignmentSettingData.ProtocolIFTypeValues.values_dict()["IPv%s" % version]
    found = False
    for settingData in setting.associators(AssocClass="LMI_OrderedIPAssignmentComponent"):
        if (settingData.ProtocolIFType is not None and
                int(settingData.ProtocolIFType) == protocol and
                hasattr(settingData, "IPAddresses")):

            i = 0
            # lmishell doesn't handle in-place editing of array parameters properly,
            # we need to create new arrays and then copy them back
            addresses = []
            masks = []
            gateways = []
            while i < len(settingData.IPAddresses):
                if not util.compare_address(settingData.IPAddresses[i], address):
                    addresses.append(settingData.IPAddresses[i])
                    if version == 4:
                        masks.append(settingData.SubnetMasks[i])
                    else:
                        masks.append(settingData.IPv6SubnetPrefixLengths[i])
                    gateways.append(settingData.GatewayAddresses[i])
                else:
                    found = True
                i += 1
            settingData.IPAddresses = addresses
            if version == 4:
                settingData.SubnetMasks = masks
            else:
                settingData.IPv6SubnetPrefixLengths = masks
            settingData.GatewayAddresses = gateways
            settingData.push()
    if not found:
        raise LmiInvalidOptions("Can't remove IP address from setting: invalid setting type or address doesn't exist.")
    LOG().info("IP address %s removed from setting %s", address, setting.Caption)
    return 0
コード例 #7
0
def remove_static_route(ns, setting, address):
    '''
    Remove static route to the given setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    # Check the IP address
    address, version = util.address_check(address)

    found = False
    for settingData in setting.associators(AssocClass="LMI_OrderedIPAssignmentComponent", ResultClass="LMI_IPRouteSettingData"):
        if util.compare_address(settingData.DestinationAddress, address):
            found = True
            settingData.delete()
    if not found:
        raise LmiInvalidOptions("No such route: %s" % address)
    LOG().info("Static route to %s removed from setting %s", address, setting.Caption)
    return 0
コード例 #8
0
def remove_static_route(ns, setting, address):
    '''
    Remove static route to the given setting.

    :param LMI_IPAssignmentSettingData setting: network setting.
    :param str address: IPv4 or IPv6 address.
    '''
    # Check the IP address
    address, version = util.address_check(address)

    found = False
    for settingData in setting.associators(
            AssocClass="LMI_OrderedIPAssignmentComponent",
            ResultClass="LMI_IPRouteSettingData"):
        if util.compare_address(settingData.DestinationAddress, address):
            found = True
            settingData.delete()
    if not found:
        raise LmiInvalidOptions("No such route: %s" % address)

    return 0