Пример #1
0
def _aug_get_or_set(augpath, new_servers=None):
    """Get or set some servers
    """
    aug = Augeas()
    aug.save()
    aug.force_reload()

    servers = []
    for path in aug.match(augpath):
        servers.append(aug.get(path))

    LOGGER.debug("Current servers: %s" % servers)

    if new_servers is not None:
        itempath = lambda idx: "%s[%d]" % (augpath, idx + 1)
        LOGGER.debug("Removing old servers: %s" % servers)
        for idx, server in enumerate(servers):
            LOGGER.debug("Removing server %s: %s" % (itempath(idx),
                                                     server))
            aug.remove(itempath(idx))
        LOGGER.debug("Setting new servers: %s" % new_servers)
        for idx, server in enumerate(new_servers):
            LOGGER.debug("Setting server %s: %s" % (itempath(idx), server))
            aug.set(itempath(idx), server)
    return servers
Пример #2
0
 def load_properties(self):
     Augeas.force_reload()
     for p in [
             "bridge", "type", "bootproto", "ipaddr", "netmask", "gateway",
             "vlan", "device", "onboot", "hwaddr"
     ]:
         self.__dict__[p] = self.ifcfg_property(p.upper())
Пример #3
0
def iface(iface):
    """Retuns the config of an iface

    Args:
        iface: Interface to retrieve the config for
    Returns:
        A dict of (nic-name, nic-infos-dict)
    """
    LOGGER.debug("Getting configuration for '%s'" % iface)
    Augeas.force_reload()

    info = {}

    aug = Augeas()
    filepath = "/etc/sysconfig/network-scripts/ifcfg-%s" % iface
    augdevicepath = "/files%s" % filepath

    if not os.path.exists(filepath):
        LOGGER.debug("No config file %s" % filepath)

    # Type
    info["type"] = aug.get(augdevicepath + "/TYPE", True)

    # Bootprotocol
    info["bootproto"] = aug.get(augdevicepath + "/BOOTPROTO", True)

    # IPV4
    for p in ["IPADDR", "NETMASK", "GATEWAY"]:
        info[p.lower()] = aug.get(augdevicepath + "/" + p, True)

    # FIXME IPv6

    # Parent bridge
    info["bridge"] = aug.get(augdevicepath + "/BRIDGE", True)

    # VLAN
    info["is_vlan"] = aug.get(augdevicepath + "/VLAN", True) is not None
    name_says_vlan = "." in iface
    if info["is_vlan"] != name_says_vlan:
        LOGGER.warning("NIC config says the device is a VLAN, but the name" +
                       "doesn't reflect that: %s (%s vs %s)" % (iface,
                       info["is_vlan"], name_says_vlan))

    if info["is_vlan"] is True:
        parts = iface.split(".")
        vlanid = parts[-1:][0]
        info["vlanid"] = vlanid
        info["vlan_parent"] = ".".join(parts[:-1])

        info["type"] = "vlan"
        LOGGER.debug("Found VLAN %s on %s" % (str(vlanid), iface))
    else:
        info["vlanid"] = None

    return info
Пример #4
0
def iface(iface):
    """Retuns the config of an iface

    Args:
        iface: Interface to retrieve the config for
    Returns:
        A dict of (nic-name, nic-infos-dict)
    """
    LOGGER.debug("Getting configuration for '%s'" % iface)
    Augeas.force_reload()

    info = {}

    aug = Augeas()
    filepath = "/etc/sysconfig/network-scripts/ifcfg-%s" % iface
    augdevicepath = "/files%s" % filepath

    if not os.path.exists(filepath):
        LOGGER.debug("No config file %s" % filepath)

    # Type
    info["type"] = aug.get(augdevicepath + "/TYPE", True)

    # Bootprotocol
    info["bootproto"] = aug.get(augdevicepath + "/BOOTPROTO", True)

    # IPV4
    for p in ["IPADDR", "NETMASK", "GATEWAY"]:
        info[p.lower()] = aug.get(augdevicepath + "/" + p, True)

    # FIXME IPv6

    # Parent bridge
    info["bridge"] = aug.get(augdevicepath + "/BRIDGE", True)

    # VLAN
    info["is_vlan"] = aug.get(augdevicepath + "/VLAN", True) is not None
    name_says_vlan = "." in iface
    if info["is_vlan"] != name_says_vlan:
        LOGGER.warning("NIC config says the device is a VLAN, but the name" +
                       "doesn't reflect that: %s (%s vs %s)" %
                       (iface, info["is_vlan"], name_says_vlan))

    if info["is_vlan"] is True:
        parts = iface.split(".")
        vlanid = parts[-1:][0]
        info["vlanid"] = vlanid
        info["vlan_parent"] = ".".join(parts[:-1])

        info["type"] = "vlan"
        LOGGER.debug("Found VLAN %s on %s" % (str(vlanid), iface))
    else:
        info["vlanid"] = None

    return info
Пример #5
0
def _aug_get_or_set(augpath, new_servers=None):
    """Get or set some servers
    """
    aug = Augeas()
    aug.save()
    aug.force_reload()

    servers = []
    for path in aug.match(augpath):
        servers.append(aug.get(path))

    LOGGER.debug("Current servers: %s" % servers)

    if new_servers is not None:
        itempath = lambda idx: "%s[%d]" % (augpath, idx + 1)
        LOGGER.debug("Removing old servers: %s" % servers)
        for idx, server in enumerate(servers):
            LOGGER.debug("Removing server %s: %s" % (itempath(idx), server))
            aug.remove(itempath(idx))
        LOGGER.debug("Setting new servers: %s" % new_servers)
        for idx, server in enumerate(new_servers):
            LOGGER.debug("Setting server %s: %s" % (itempath(idx), server))
            aug.set(itempath(idx), server)
    return servers
Пример #6
0
 def load_properties(self):
     Augeas.force_reload()
     for p in ["bridge", "type", "bootproto", "ipaddr", "netmask",
               "gateway", "vlan", "device", "onboot", "hwaddr"]:
         self.__dict__[p] = self.ifcfg_property(p.upper())