예제 #1
0
def list_all_nodes():
    # type: () -> None
    '''display a list of all nodes'''

    nodes = config.get_all_nodes()
    nodes.sort()

    for node in nodes:
        ignored = set(config.get_groups(node))
        ignored &= param.IGNORE_GROUPS

        if OPT_FILTER_IGNORED and ignored:
            continue

        if OPT_IPADDRESS:
            node += ' ' + config.get_node_ipaddress(node)

        if OPT_RSYNC:
            if node in param.NO_RSYNC:
                node += ' no'
            else:
                node += ' yes'

        if ignored:
            node += ' (ignored)'

        print node
예제 #2
0
def list_all_nodes():
    '''display a list of all nodes'''

    nodes = config.get_all_nodes()
    nodes.sort()

    for node in nodes:
        ignored = set(config.get_groups(node))
        ignored &= param.IGNORE_GROUPS

        if OPT_FILTER_IGNORED and len(ignored) > 0:
            continue

        if OPT_IPADDRESS:
            node += ' ' + config.get_node_ipaddress(node)

        if OPT_RSYNC:
            if node in param.NO_RSYNC:
                node += ' no'
            else:
                node += ' yes'

        if len(ignored) > 0:
            node += ' (ignored)'

        print node
예제 #3
0
def list_nodes(nodelist):
    # type: (str) -> None
    '''display node definition'''

    nodeset = synctool.nodeset.NodeSet()
    try:
        nodeset.add_node(nodelist)
    except synctool.range.RangeSyntaxError as err:
        error(str(err))
        sys.exit(1)

    if nodeset.addresses() is None:
        # error message already printed
        sys.exit(1)

    groups = []  # type: List[str]
    for node in nodeset.nodelist:
        if OPT_IPADDRESS or OPT_RSYNC:
            out = ''
            if OPT_IPADDRESS:
                out += ' ' + config.get_node_ipaddress(node)

            if OPT_RSYNC:
                if node in param.NO_RSYNC:
                    out += ' no'
                else:
                    out += ' yes'

            print out[1:]
        else:
            for group in config.get_groups(node):
                # extend groups, but do not have duplicates
                if group not in groups:
                    groups.append(group)

    # group order is important, so don't sort
    # however, when you list multiple nodes at once, the groups will have
    # been added to the end
    # So the order is important, but may be incorrect when listing
    # multiple nodes at once


#    groups.sort()

    for group in groups:
        if OPT_FILTER_IGNORED and group in param.IGNORE_GROUPS:
            continue

        if group in param.IGNORE_GROUPS:
            group += ' (ignored)'

        print group
예제 #4
0
def list_nodes(nodelist):
    # type: (str) -> None
    '''display node definition'''

    nodeset = synctool.nodeset.NodeSet()
    try:
        nodeset.add_node(nodelist)
    except synctool.range.RangeSyntaxError as err:
        error(str(err))
        sys.exit(1)

    if nodeset.addresses() is None:
        # error message already printed
        sys.exit(1)

    groups = []     # type: List[str]
    for node in nodeset.nodelist:
        if OPT_IPADDRESS or OPT_RSYNC:
            out = ''
            if OPT_IPADDRESS:
                out += ' ' + config.get_node_ipaddress(node)

            if OPT_RSYNC:
                if node in param.NO_RSYNC:
                    out += ' no'
                else:
                    out += ' yes'

            print out[1:]
        else:
            for group in config.get_groups(node):
                # extend groups, but do not have duplicates
                if group not in groups:
                    groups.append(group)

    # group order is important, so don't sort
    # however, when you list multiple nodes at once, the groups will have
    # been added to the end
    # So the order is important, but may be incorrect when listing
    # multiple nodes at once
#    groups.sort()

    for group in groups:
        if OPT_FILTER_IGNORED and group in param.IGNORE_GROUPS:
            continue

        if group in param.IGNORE_GROUPS:
            group += ' (ignored)'

        print group
예제 #5
0
def list_nodegroups(grouplist):
    # type: (str) -> None
    '''display list of nodes that are member of group'''

    nodeset = synctool.nodeset.NodeSet()
    try:
        nodeset.add_group(grouplist)
    except synctool.range.RangeSyntaxError as err:
        error(str(err))
        sys.exit(1)

    if nodeset.addresses() is None:
        # error message already printed
        sys.exit(1)

    arr = list(nodeset.nodelist)
    arr.sort()

    for node in arr:
        ignored = set(config.get_groups(node))
        ignored &= param.IGNORE_GROUPS

        if OPT_FILTER_IGNORED and ignored:
            continue

        if OPT_IPADDRESS:
            node += ' ' + config.get_node_ipaddress(node)

        if OPT_RSYNC:
            if node in param.NO_RSYNC:
                node += ' no'
            else:
                node += ' yes'

        if ignored:
            node += ' (ignored)'

        print node
예제 #6
0
def list_nodegroups(grouplist):
    # type: (str) -> None
    '''display list of nodes that are member of group'''

    nodeset = synctool.nodeset.NodeSet()
    try:
        nodeset.add_group(grouplist)
    except synctool.range.RangeSyntaxError as err:
        error(str(err))
        sys.exit(1)

    if nodeset.addresses() is None:
        # error message already printed
        sys.exit(1)

    arr = list(nodeset.nodelist)
    arr.sort()

    for node in arr:
        ignored = set(config.get_groups(node))
        ignored &= param.IGNORE_GROUPS

        if OPT_FILTER_IGNORED and ignored:
            continue

        if OPT_IPADDRESS:
            node += ' ' + config.get_node_ipaddress(node)

        if OPT_RSYNC:
            if node in param.NO_RSYNC:
                node += ' no'
            else:
                node += ' yes'

        if ignored:
            node += ' (ignored)'

        print node
예제 #7
0
    def addresses(self, silent=False):
        '''return list of addresses of relevant nodes'''

        # by default, work on default_nodeset
        if not self.nodelist and not self.grouplist:
            if not param.DEFAULT_NODESET:
                return []

            self.nodelist = param.DEFAULT_NODESET

        # check if the nodes exist at all
        # the user may have given bogus names
        all_nodes = set(config.get_all_nodes())
        unknown = (self.nodelist | self.exclude_nodes) - all_nodes
        if len(unknown) > 0:
            # it's nice to display "the first" unknown node
            # (at least, for numbered nodes)
            arr = list(unknown)
            arr.sort()
            stderr("no such node '%s'" % arr[0])
            return None

        # check if the groups exist at all
        unknown = ((self.grouplist | self.exclude_groups) -
                   param.ALL_GROUPS)
        for group in unknown:
            stderr("no such group '%s'" % group)
            return None

        self.nodelist |= config.get_nodes_in_groups(self.grouplist)
        self.exclude_nodes |= config.get_nodes_in_groups(self.exclude_groups)
        # remove excluded nodes from nodelist
        self.nodelist -= self.exclude_nodes

        if not self.nodelist:
            return []

        addrs = []

        ignored_nodes = self.nodelist & param.IGNORE_GROUPS
        self.nodelist -= ignored_nodes

        for node in self.nodelist:
            # ignoring a group results in also ignoring the node
            my_groups = set(config.get_groups(node))
            my_groups &= param.IGNORE_GROUPS
            if len(my_groups) > 0:
                verbose('node %s is ignored due to an ignored group' % node)
                ignored_nodes.add(node)
                continue

            addr = config.get_node_ipaddress(node)
            self.namemap[addr] = node

            # make sure we do not have duplicates
            if addr not in addrs:
                addrs.append(addr)

        # print message about ignored nodes
        if not silent and len(ignored_nodes) > 0 and not synctool.lib.QUIET:
            if param.TERSE:
                synctool.lib.terse(synctool.lib.TERSE_WARNING,
                                   'ignored nodes')
            else:
                arr = list(ignored_nodes)
                arr.sort()
                ignored_str = ('ignored: ' + synctool.range.compress(arr))
                if len(ignored_str) < 70:
                    warning(ignored_str)
                else:
                    warning('some nodes are ignored')
                    if synctool.lib.VERBOSE:
                        for node in ignored_nodes:
                            verbose('ignored: %s' % node)

        return addrs
예제 #8
0
    def addresses(self, silent=False):
        '''return list of addresses of relevant nodes'''

        # by default, work on default_nodeset
        if not self.nodelist and not self.grouplist:
            if not param.DEFAULT_NODESET:
                return []

            self.nodelist = param.DEFAULT_NODESET

        # check if the nodes exist at all
        # the user may have given bogus names
        all_nodes = set(config.get_all_nodes())
        unknown = (self.nodelist | self.exclude_nodes) - all_nodes
        if len(unknown) > 0:
            # it's nice to display "the first" unknown node
            # (at least, for numbered nodes)
            arr = list(unknown)
            arr.sort()
            stderr("no such node '%s'" % arr[0])
            return None

        # check if the groups exist at all
        unknown = ((self.grouplist | self.exclude_groups) - param.ALL_GROUPS)
        for group in unknown:
            stderr("no such group '%s'" % group)
            return None

        self.nodelist |= config.get_nodes_in_groups(self.grouplist)
        self.exclude_nodes |= config.get_nodes_in_groups(self.exclude_groups)
        # remove excluded nodes from nodelist
        self.nodelist -= self.exclude_nodes

        if not self.nodelist:
            return []

        addrs = []

        ignored_nodes = self.nodelist & param.IGNORE_GROUPS
        self.nodelist -= ignored_nodes

        for node in self.nodelist:
            # ignoring a group results in also ignoring the node
            my_groups = set(config.get_groups(node))
            my_groups &= param.IGNORE_GROUPS
            if len(my_groups) > 0:
                verbose('node %s is ignored due to an ignored group' % node)
                ignored_nodes.add(node)
                continue

            addr = config.get_node_ipaddress(node)
            self.namemap[addr] = node

            # make sure we do not have duplicates
            if addr not in addrs:
                addrs.append(addr)

        # print message about ignored nodes
        if not silent and len(ignored_nodes) > 0 and not synctool.lib.QUIET:
            if param.TERSE:
                synctool.lib.terse(synctool.lib.TERSE_WARNING, 'ignored nodes')
            else:
                arr = list(ignored_nodes)
                arr.sort()
                ignored_str = ('ignored: ' + synctool.range.compress(arr))
                if len(ignored_str) < 70:
                    warning(ignored_str)
                else:
                    warning('some nodes are ignored')
                    if synctool.lib.VERBOSE:
                        for node in ignored_nodes:
                            verbose('ignored: %s' % node)

        return addrs