Beispiel #1
0
def datas_refresh(oc_widgets):
    """
    refresh a page's all data
    """
    # some of the item don't create by _create_iteme which `certainly`
    # have attributes called ('get_conf', 'set_conf', 'show_conf', 'conf_path')
    # so we have to use the double_check function here.
    for i in oc_widgets.values():
        if double_check(i, 'get_conf'):
            if double_check(i, 'conf_path'):
                v = i.get_conf(i.conf_path)
            elif double_check(i, 'get_conf_args'):
                v = i.get_conf(*i.get_conf_args)
            else:
                v = i.get_conf()
            if double_check(i, 'show_conf'):
                i.show_conf(v)
            elif hasattr(i, 'set_label'):
                i.set_label(v or "")
                i.get_oc_value = i.get_label
            elif hasattr(i, 'set_text'):
                i.set_text(v or "")
                i.get_oc_value = i.get_text
            else:
                logger.debug('Need a Setter for' + str(i))
Beispiel #2
0
def datas_refresh(oc_widgets):
    """
    refresh a page's all data
    """
    # some of the item don't create by _create_iteme which `certainly`
    # have attributes called ('get_conf', 'set_conf', 'show_conf', 'conf_path')
    # so we have to use the double_check function here.
    for i in oc_widgets.values():
        if double_check(i, 'get_conf'):
            if double_check(i, 'conf_path'):
                v = i.get_conf(i.conf_path)
            elif double_check(i, 'get_conf_args'):
                v = i.get_conf(*i.get_conf_args)
            else:
                v = i.get_conf()
            if double_check(i, 'show_conf'):
                i.show_conf(v)
            elif hasattr(i, 'set_label'):
                i.set_label(v or "")
                i.get_oc_value = i.get_label
            elif hasattr(i, 'set_text'):
                i.set_text(v or "")
                i.get_oc_value = i.get_text
            else:
                logger.debug('Need a Setter for' + str(i))
Beispiel #3
0
def conf_apply(apy_btn):
    oc_widgets = get_oc_widgets(apy_btn)
    for widget in oc_widgets.values():
        # this could be a ValidateEntry, which has
        # get_oc_value, or a normal gtk.Entry, which
        # will automatically get a get_oc_value during
        # the creation.
        if hasattr(widget, 'get_oc_value'):
            v = widget.get_oc_value()
        else:
            logger.debug('Nothing to apply for:' + str(widget))
        if double_check(widget, 'set_conf'):
            if double_check(widget, 'conf_path'):
                widget.set_conf(widget.conf_path, v)
            else:
                widget.set_conf(v)
Beispiel #4
0
def conf_apply(apy_btn):
    oc_widgets = get_oc_widgets(apy_btn)
    for widget in oc_widgets.values():
        # this could be a ValidateEntry, which has
        # get_oc_value, or a normal gtk.Entry, which
        # will automatically get a get_oc_value during
        # the creation.
        if hasattr(widget, 'get_oc_value'):
            v = widget.get_oc_value()
        else:
            logger.debug('Nothing to apply for:' + str(widget))
        if double_check(widget, 'set_conf'):
            if double_check(widget, 'conf_path'):
                widget.set_conf(widget.conf_path, v)
            else:
                widget.set_conf(v)
Beispiel #5
0
def read_status_datas():
    status_text = []
    if network_up():
        network_status = {}
        client = gudev.Client(['net'])
        # reload augeas tree
        aug.load()
        for nic in client.query_by_subsystem("net"):
            try:
                interface = nic.get_property("INTERFACE")
                logger.debug(interface)
                if not interface == "lo":
                    if(has_ip_address(interface) or
                            get_ipv6_address(interface)):
                        ipv4_address = get_ip_address(interface)
                        try:
                            ipv6_address, netmask = get_ipv6_address(interface)
                        except:
                            ipv6_address = ""
                        network_status[interface] = (
                            ipv4_address,
                            ipv6_address)
            except:
                pass
        # remove parent/bridge duplicates
        for key in sorted(network_status.iterkeys()):
            if key.startswith("br"):
                parent_dev = key[+2:]
                if network_status.has_key(parent_dev):
                    del network_status[parent_dev]
        for key in sorted(network_status.iterkeys()):
            ipv4_addr, ipv6_addr = network_status[key]
            cmd = "/files/etc/sysconfig/network-scripts/" +\
                "ifcfg-%s/BOOTPROTO" % str(key)
            dev_bootproto = augtool_get(cmd)
            if dev_bootproto is None:
                cmd = "/files/etc/sysconfig/network-scripts/" +\
                    "ifcfg-br%s/BOOTPROTO" % str(key)
                dev_bootproto = augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
            if not nic_link_detected(key):
                ipv4_addr = "(Link Inactive)"
            if ipv4_addr.strip() == "" and dev_bootproto.strip() == "dhcp":
                if "Inactive" in ipv4_addr:
                    ipv4_addr = "(Link Inactive)"
                else:
                    ipv4_addr = "(DHCP Failed)"
            if OVIRT_VARS.has_key("OVIRT_IPV6") and ipv6_addr != "":
                pass
            else:
                ipv6_addr = ""
            status_text.append([key.strip(), dev_bootproto.strip(),
                                ipv4_addr.strip(), ipv6_addr.strip()])
            logger.debug(status_text)
            logger.debug(network_status)
    else:
        status_text.append(["Not Connected", "", "", ""])
    return status_text
Beispiel #6
0
def validator_disp(widget, _, validator):
    v = widget.get_parent().get_oc_value()
    if validator(v) is True:
        widget.get_parent().validate_status.set_label('VALID')
        widget.get_parent().bool_validate_state = 0
    else:
        widget.get_parent().validate_status.set_label('INVALID')
        widget.get_parent().bool_validate_state = 1
    oc_widgets = get_oc_widgets(widget.get_parent())
    apply_rest_btn = None
    invalid_cnt = 0
    for w in oc_widgets.values():
        if isinstance(w, ValidateEntry):
            invalid_cnt += w.bool_validate_state
        if isinstance(w, ApplyResetBtn):
            apply_rest_btn = w
    if apply_rest_btn:
        if invalid_cnt > 0 and apply_rest_btn:
            apply_rest_btn.btns[0].set_sensitive(False)
        elif invalid_cnt == 0:
            apply_rest_btn.btns[0].set_sensitive(True)
        else:
            logger.debug('Error invalid_cnt value :%d' % invalid_cnt)
Beispiel #7
0
def validator_disp(widget, _, validator):
    v = widget.get_parent().get_oc_value()
    if validator(v) is True:
        widget.get_parent().validate_status.set_label('VALID')
        widget.get_parent().bool_validate_state = 0
    else:
        widget.get_parent().validate_status.set_label('INVALID')
        widget.get_parent().bool_validate_state = 1
    oc_widgets = get_oc_widgets(widget.get_parent())
    apply_rest_btn = None
    invalid_cnt = 0
    for w in oc_widgets.values():
        if isinstance(w, ValidateEntry):
            invalid_cnt += w.bool_validate_state
        if isinstance(w, ApplyResetBtn):
            apply_rest_btn = w
    if apply_rest_btn:
        if invalid_cnt > 0 and apply_rest_btn:
            apply_rest_btn.btns[0].set_sensitive(False)
        elif invalid_cnt == 0:
            apply_rest_btn.btns[0].set_sensitive(True)
        else:
            logger.debug('Error invalid_cnt value :%d' % invalid_cnt)
Beispiel #8
0
def read_status_datas():
    status_text = []
    if network_up():
        network_status = {}
        client = gudev.Client(['net'])
        # reload augeas tree
        aug.load()
        for nic in client.query_by_subsystem("net"):
            try:
                interface = nic.get_property("INTERFACE")
                logger.debug(interface)
                if not interface == "lo":
                    if (has_ip_address(interface)
                            or get_ipv6_address(interface)):
                        ipv4_address = get_ip_address(interface)
                        try:
                            ipv6_address, netmask = get_ipv6_address(interface)
                        except:
                            ipv6_address = ""
                        network_status[interface] = (ipv4_address,
                                                     ipv6_address)
            except:
                pass
        # remove parent/bridge duplicates
        for key in sorted(network_status.iterkeys()):
            if key.startswith("br"):
                parent_dev = key[+2:]
                if network_status.has_key(parent_dev):
                    del network_status[parent_dev]
        for key in sorted(network_status.iterkeys()):
            ipv4_addr, ipv6_addr = network_status[key]
            cmd = "/files/etc/sysconfig/network-scripts/" +\
                "ifcfg-%s/BOOTPROTO" % str(key)
            dev_bootproto = augtool_get(cmd)
            if dev_bootproto is None:
                cmd = "/files/etc/sysconfig/network-scripts/" +\
                    "ifcfg-br%s/BOOTPROTO" % str(key)
                dev_bootproto = augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
            if not nic_link_detected(key):
                ipv4_addr = "(Link Inactive)"
            if ipv4_addr.strip() == "" and dev_bootproto.strip() == "dhcp":
                if "Inactive" in ipv4_addr:
                    ipv4_addr = "(Link Inactive)"
                else:
                    ipv4_addr = "(DHCP Failed)"
            if OVIRT_VARS.has_key("OVIRT_IPV6") and ipv6_addr != "":
                pass
            else:
                ipv6_addr = ""
            status_text.append([
                key.strip(),
                dev_bootproto.strip(),
                ipv4_addr.strip(),
                ipv6_addr.strip()
            ])
            logger.debug(status_text)
            logger.debug(network_status)
    else:
        status_text.append(["Not Connected", "", "", ""])
    return status_text