当前位置: 首页>>代码示例>>Python>>正文


Python Logger.debug方法代码示例

本文整理汇总了Python中systematic.log.Logger.debug方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.debug方法的具体用法?Python Logger.debug怎么用?Python Logger.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在systematic.log.Logger的用法示例。


在下文中一共展示了Logger.debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: KnownHosts

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class KnownHosts(list):
    """
    Parser for OpenSSH known_hosts file contents
    """
    def __init__(self, path=DEFAULT_KNOWN_HOSTS, fingerprint_hash=None):
        self.log = Logger().default_stream
        self.path = path
        self.fingerprint_hash = fingerprint_hash
        self.load()

    def load(self):
        """
        Load known hosts file, discarding earlier data in the object.
        """
        del self[0:len(self)]

        if not os.path.isfile(self.path):
            self.log.debug('No such file: {}'.format(self.path))
            return

        for line in [l.rstrip() for l in open(self.path, 'r').readlines()]:
            if line.startswith('#') or line.strip() == '':
                continue

            # Strip list of hosts from line
            hosts, key = line.split(None, 1)
            hosts = hosts.split(',')

            try:
                key = KnownHostsEntry(key)
                if key not in self:
                    self.append(key)
                else:
                    key = self[self.index(key)]
                key.add_hosts(hosts)
            except SSHKeyError:
                pass

    def save(self, path=None):
        """Save known hosts

        Saves known hosts file, merging same keys to single line
        """
        if path is None:
            path = self.path
        try:
            with open(path, 'w') as fd:
                for entry in self:
                    fd.write('{}\n'.format(entry))
        except Exception as e:
            raise SSHKeyError('Error writing {}: {}'.format(path, e))

    def find_host_key(self, value):
        """Find key for hostname

        """
        for key in self:
            if value in key.hosts:
                return key
        return None
开发者ID:hile,项目名称:systematic,代码行数:62,代码来源:sshconfig.py

示例2: AuthorizedKeys

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class AuthorizedKeys(list):
    """
    Parser for OpenSSH authorized_keys file contents
    """
    def __init__(self, path=DEFAULT_AUTHORIZED_KEYS):
        self.log = Logger().default_stream
        self.path = path
        self.load()

    def load(self):
        """
        Load authorized keys file, discarding earlier data in the object.

        SSH v1 authorized_keys line: options, bits, exponent, modulus, comment)
        SSH v2 authorized_keys line: options, keytype, base64-encoded key, comment)'

        See man sshd for details.
        """
        self.__delslice__(0, len(self))

        if not os.path.isfile(self.path):
            self.log.debug('No such file: {0}'.format(self.path))
            return

        for line in [l.rstrip() for l in open(self.path, 'r').readlines()]:
            if line.startswith('#') or line.strip() == '':
                continue

            try:
                self.append(OpenSSHPublicKey(line))
            except SSHKeyError:
                pass
开发者ID:sgalaviz,项目名称:systematic,代码行数:34,代码来源:sshconfig.py

示例3: SSHConfig

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class SSHConfig(dict):
    def __init__(self, path=None):
        self.defaults = {}
        self.patterns = []
        self.log = Logger().default_stream
        self.path = path is not None and path or os.path.expanduser('~/.ssh/config')
        self.reload()

    def reload(self):
        self.clear()
        if not os.path.isfile(self.path):
            self.log.debug('No such file: {}'.format(self.path))
            return

        with open(self.path, 'r') as fd:
            host = None
            for line in [x.strip() for x in fd.readlines()]:
                if line == '' or line.startswith('#'):
                    continue

                if line[:5] == 'Host ':
                    host = SSHConfigHostPattern(self, line[5:])
                    for pattern in host.patterns:
                        self[pattern] = host
                    self.patterns.append(host)

                else:
                    host.parse(line)

        if '*' in self.keys():
            self.defaults.update(self.pop('*').items())

    def keys(self):
        return [k for k in sorted(super(SSHConfig, self).keys())]

    def items(self):
        return [(k, self[k]) for k in self.keys()]

    def values(self):
        return [self[k] for k in self.keys()]
开发者ID:hile,项目名称:systematic,代码行数:42,代码来源:sshconfig.py

示例4: SSHConfig

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class SSHConfig(dict):
    def __init__(self, path=None):
        self.defaults = {}
        self.log = Logger().default_stream
        self.path = path is not None and path or os.path.expanduser('~/.ssh/config')
        self.reload()

    def reload(self):
        self.clear()
        if not os.path.isfile(self.path):
            self.log.debug('No such file: %s' % self.path)
            return

        with open(self.path, 'r') as fd:
            host = None
            for l in [x.strip() for x in fd.readlines()]:
                if l=='' or l.startswith('#'):
                    continue

                if l[:5]=='Host ':
                    host = SSHConfigHost(self, l[5:])
                    self[host.name] = host

                else:
                    host.parse(l)

        if '*' in self.keys():
            self.defaults.update(self.pop('*').items())

    def keys(self):
        return [k for k in sorted(dict.keys(self))]

    def items(self):
        return [(k, self[k]) for k in self.keys()]

    def values(self):
        return [self[k] for k in self.keys()]
开发者ID:pombreda,项目名称:systematic,代码行数:39,代码来源:sshconfig.py

示例5: UserSSHKeys

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class UserSSHKeys(dict):
    """
    List of user configured SSH keys to process
    """
    def __init__(self, authorized_keys=DEFAULT_AUTHORIZED_KEYS):
        self.log = Logger().default_stream
        self.__parse_user_keyfiles()
        self.authorized_keys = AuthorizedKeys(authorized_keys)

    def __parse_user_keyfiles(self):
        """
        Parses any normal user keyfiles in ~/.ssh directory automatically.

        These keys are marked by default not to be automatically loaded:
        to enable, add key path to ~/.ssh/sshkeys.conf
        """

        user_sshdir = os.path.expanduser('~/.ssh')
        if not os.path.isdir(user_sshdir):
            return

        paths = filter(lambda x:
            os.path.isfile(x),
            [os.path.join(user_sshdir, x) for x in filter(lambda x:
                x not in SSH_CONFIG_FILES and os.path.splitext(x)[1]!='.pub',
                os.listdir(user_sshdir)
            )]
        )
        for path in paths:
            try:
                sshkey = SSHKeyFile(self, path)
            except SSHKeyError, emsg:
                self.log.debug(emsg)
                continue

            self[sshkey.path] = sshkey
开发者ID:sgalaviz,项目名称:systematic,代码行数:38,代码来源:sshconfig.py

示例6: RsyncCommand

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class RsyncCommand(object):
    """
    Wrapper to execute rsync to target nicely from python
    """
    def __init__(self, src, dst,
                 flags=DEFAULT_RSYNC_FLAGS,
                 output_format=DEFAULT_OUTPUT_FORMAT):

        self.log = Logger('rsync').default_stream
        self.src = src
        self.dst = dst
        self.flags = flags
        self.output_format = output_format

        cmd = CommandPathCache().which('rsync')
        if cmd is None:
            raise RsyncError('No such command: rsync')
        self.command = [cmd] + flags + [self.output_format, '{0}'.format(src), '{0}'.format(dst)]

    def __str__(self):
        return ' '.join(self.command)

    def run(self, verbose=False):
        """
        Run the rsync command specific in __init__()
        """
        if not verbose and self.log.level == logging.DEBUG:
            verbose = True
        try:
            p = Popen(self.command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
            self.log.debug('Running: {0}'.format(self))

            rval = None
            while rval is None:
                if verbose:
                    while True:
                        line = p.stdout.readline()
                        if line == '':
                            break
                        sys.stdout.write('{0}\n'.format(line.rstrip()))
                time.sleep(0.2)
                rval = p.poll()

            self.log.debug('Return code: {0}'.format(rval))
            if rval != 0:
                raise RsyncError('Error running command {0}: {1}'.format(self, p.stderr.read()))

        except KeyboardInterrupt:
            self.log.debug('Rsync interrupted')
            raise KeyboardInterrupt
开发者ID:hile,项目名称:systematic,代码行数:52,代码来源:rsync.py

示例7: SNMPAgent

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class SNMPAgent(Script):
    """SNMP Agent implementation

    SNMP agent daemon for net-snmpd pass_persist mode

    Example usage:

        agent = SNMPAgent('.1.2.3.4')
        tree = agent.register_tree('1.2.3.4.1')
        tree.register('1.2.3.4.1.1', 'integer', 1)
        tree.register('1.2.3.4.1.2', 'integer', 2)

        agent.register_tree('1.2.3.4.2')
        agent.register('1.2.3.4.2.1', 'integer', 1)
        agent.register('1.2.3.4.2.4', 'integer', 4)
        agent.register('1.2.3.4.2.3', 'integer', 3)
        agent.register('1.2.3.4.2.2', 'integer', 2)

        tree = agent.register_tree('1.2.3.4.3')
        tree.register('1.2.3.4.3.1.1', 'integer', 1)
        tree.add_values('string', [x for x in string.digits[2:]])

        tree = agent.register_tree('1.2.3.4.4')
        tree.add_prefix_map([
            { 'oid': '1.2.3.4.4.1', 'key': 'string', 'values': [x for x in string.letters[:10]]},
            { 'oid': '1.2.3.4.4.2', 'key': 'integer', 'values': [x for x in string.digits[:10]]},
        ])

        agent.run()
    """
    def __init__(self, oid, reload_interval=60):
        Script.__init__(self)
        self.log = Logger('snmp').default_stream

        self.reload_interval = reload_interval
        self.last_reload = None

        self.add_argument('-g', '--get', help='SNMP GET request')
        self.add_argument('-n', '--next', help='SNMP GET request')
        self.add_argument('-t', '--tree', action='store_true', help='Show OID tree')

        self.tree = Tree(oid)

    def __SIGHUP__(self, signum, frame):
        """
        Signal handler to reload configuration. Note this requires also the
        IOError processing in main input loop below
        """
        self.log.debug('Reloading from signal')
        self.reload()

    def register_tree(self, oid):
        return self.tree.add(Tree(oid))

    def register(self, oid, key, value):
        return self.tree.add(Item(oid, key, value))

    def GET(self, oid):
        """GET from agent

        Return given OID from agent tree or None

        """
        try:
            return self.tree.GET(oid)
        except SNMPError, emsg:
            self.log.debug(emsg)
            return None
开发者ID:bambou42,项目名称:seine,代码行数:70,代码来源:agent.py

示例8: OIDPrefix

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class OIDPrefix(object):
    """Sortable OID base class

    Base class for OID prefixes, sortable in OID order

    """
    def __init__(self, oid):
        self.log = Logger('snmp').default_stream
        self.oid = self.__format_oid__(oid)
        self.oid_string = self.__format_oid_string__(oid)

        self._parent = None
        self._next = None

    def __format_oid_string__(self, oid):
        return '.%s' % '.'.join(str(x) for x in self.__format_oid__(oid))

    def __format_oid__(self, oid):
        """Format OID

        Format OID string to validated OID list

        Return list of integeres
        """

        if isinstance(oid, basestring):
            try:
                oid = oid.strip('.').split('.')
            except ValueError:
                raise ValueError('Invalid OID: %s' % oid)

        return self.__validate_oid__(oid)

    def __validate_oid__(self, oid):
        """Validate OID and return

        Validate list of integers to be a valid OID

        Returns value if OK
        """
        try:
            oid = [int(x) for x in oid]
            for x in oid:
                if x<=0:
                    raise ValueError

        except ValueError:
            raise ValueError('Invalid OID: %s' % oid)

        return oid

    def __invalid__(self, message):
        """Invalid request

        Log error and return None

        """
        self.log.debug('%s' % message)
        return None

    def __cmp__(self, other):
        """Compare oid prefix items

        Compares OID prefixes

        """
        if isinstance(other, basestring):
            oid = self.__format_oid__(other)

        elif isinstance(other, OIDPrefix):
            oid = other.oid

        else:
            raise ValueError('Error comparing OIDPrefix to %d' % type(other))

        if len(oid) != len(self.oid):
            return cmp(len(self.oid), len(oid))

        for i in range(0, len(oid)):
            if oid[i] != self.oid[i]:
                return cmp(self.oid[i], oid[i])

        return cmp(self.oid, oid)

    def __eq__(self, oid):
        return self.__cmp__(oid) == 0

    def __ne__(self, oid):
        return self.__cmp__(oid) != 0

    def __lt__(self, oid):
        return self.__cmp__(oid) < 0

    def __le__(self, oid):
        return self.__cmp__(oid) <= 0

    def __gt__(self, oid):
        return self.__cmp__(oid) > 0

    def __ge__(self, oid):
#.........这里部分代码省略.........
开发者ID:bambou42,项目名称:seine,代码行数:103,代码来源:agent.py

示例9: ServerConfigFile

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class ServerConfigFile(object):
    """
    Parser for configuration file describing servers and their
    operating systems.
    """

    def __init__(self, path):
        self.operating_systems = []
        self.servers = []
        self.path = path
        self.log = Logger().default_stream

        if os.path.isfile(self.path):
            self.load()

    @property
    def osnames(self):
        return [x.name for x in self.operating_systems]

    def load(self):
        self.operating_systems = []
        self.servers = []

        try:
            config = ConfigObj(self.path)
        except ValueError as e:
            raise ValueError("Error parsing {0}: {1}".format(self.path, e))

        osgroup = None
        for key, section in config.items():
            if "commands" in section:
                if key in self.servers:
                    raise ValueError("Duplicate OS group name: {0}".format(key))
                osgroup = OperatingSystemGroup(self, key, **section)
                self.operating_systems.append(osgroup)
                self.servers.extend(osgroup.servers)
            else:
                if osgroup is None:
                    raise ValueError("Server in configuration file but no OS group defined yet")
                self.servers.append(Server(osgroup, section))

        return

    def save(self):
        config = ConfigObj()

        for osgroup in self.operating_systems:
            section = {"commands": osgroup.update_commands}

            if osgroup.description is not None and osgroup.description != "":
                section["description"] = osgroup.description

            if osgroup.servers:
                section["servers"] = osgroup.servers

            if osgroup.connect_command != DEFAULT_CONNECT_COMMAND:
                section["connect"] = osgroup.connect_command

            if osgroup.command_separator != DEFAULT_COMMAND_SEPARATOR:
                section["command_separator"] = osgroup.command_separator

            config[osgroup.name] = section
            for server in osgroup.servers:
                if server.description:
                    config[server.name] = {"description": server.description}

        self.log.debug("Saving configuration to {0}".format(self.path))
        config.write(outfile=open(self.path, "w"))

    def match_os(self, name):
        for os in self.operating_systems:
            if os.name == name:
                return os

        raise ValueError("Unknown OS: {0}".format(name))
开发者ID:hile,项目名称:systematic,代码行数:77,代码来源:serverlist.py

示例10: PlaybookCallbacks

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class PlaybookCallbacks(callbacks.PlaybookCallbacks):
    """Playbook callbacks

    Override version of ansible.callbacks.PlaybookCallbacks that only logs
    to default logger with debug messages, not actually doing anything else.

    Please note that callback on_vars_prompt is NOT overridden, so if your
    code asks for variables we will use the standard chatty query version!
    """

    def __init__(self, verbose=False):
        callbacks.PlaybookCallbacks.__init__(self, verbose)
        self.log = Logger().default_stream

    def on_start(self):
        self.log.debug('starting playbook')

    def on_notify(self, host, handler):
        self.log.debug('playbook notification')

    def on_no_hosts_remaining(self):
        self.log.debug('playbook no hosts remaining')

    def on_task_start(self, name, is_conditional):
        self.log.debug('playbook starting task "%s"' % name)

    def on_setup(self):
        self.log.debug('playbook setup')

    def on_import_for_host(self, host, imported_file):
        self.log.debug('playbook importing for host %s' % host)

    def on_not_import_for_host(self, host, missing_file):
        self.log.debug('playbook not importing for host %s' % host)

    def on_play_start(self, name):
        self.log.debug('playbook start play %s' % name)

    def on_no_hosts_matched(self):
        raise RunnerError('No hosts matched')

    def on_stats(self, stats):
        self.log.debug('playbook statistics %s' % stats)
开发者ID:bcicen,项目名称:ansiblereporter,代码行数:45,代码来源:reporter_callbacks.py

示例11: AuthorizedKeys

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class AuthorizedKeys(dict):
    """
    Parser for OpenSSH authorized_keys file contents
    """
    def __init__(self, path=DEFAULT_AUTHORIZED_KEYS):
        self.log = Logger().default_stream
        self.path = path
        self.load()

    def load(self):
        """
        Load authorized keys file, discarding earlier data in the object.

        SSH v1 authorized_keys line: options, bits, exponent, modulus, comment)
        SSH v2 authorized_keys line: options, keytype, base64-encoded key, comment)'

        See man sshd for details.
        """
        self.clear()
        if not os.path.isfile(self.path):
            self.log.debug('No such file: {0}'.format(self.path))
            return

        for l in [l.rstrip() for l in open(self.path, 'r').readlines()]:
            if l.startswith('#') or l.strip() == '':
                continue

            entry = {}
            parts = l.split()

            if parts[0][0] in string.digits and len(parts) == 4:
                entry['keyformat'] = 1
                entry['bits'] = int(parts[0])
                entry['exponent'] = parts[1]
                entry['modulus'] = parts[2]
                entry['comment'] = parts[3]
                entry['options'] = None

            elif parts[0] in ( 'ssh-dsa', 'ssh-rsa', ):
                entry['keyformat'] = 2
                entry['keytype'] = parts[0]
                entry['key_base64'] = parts[1]
                entry['comment'] = len(parts) > 2 and parts[2] or ''
                entry['options'] = None

            else:
                entry['options'] = parts[0]
                parts = parts[1:]

                if not parts:
                    continue

                if parts[0] in ( 'ssh-dsa', 'ssh-rsa', ) and len(parts) ==  3:
                    entry['keyformat'] = 2
                    entry['keytype'] = parts[0]
                    entry['key_base64'] = parts[1]
                    entry['comment'] = parts[2]

                elif parts[0] in string.digits:
                    entry['keyformat'] = 1
                    entry['keyformat'] = 1
                    entry['bits'] = int(parts[0])
                    entry['exponent'] = parts[1]
                    entry['modulus'] = parts[2]
                    entry['comment'] = parts[3]
开发者ID:gregorynicholas,项目名称:systematic,代码行数:67,代码来源:sshconfig.py

示例12: SNMPAgent

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class SNMPAgent(Script):
    """SNMP Agent implementation

    SNMP agent daemon for net-snmpd pass_persist mode

    Example usage:

        agent = SNMPAgent('.1.2.3.4')
        tree = agent.register_tree('1.2.3.4.1')
        tree.register('1.2.3.4.1.1', 'integer', 1)
        tree.register('1.2.3.4.1.2', 'integer', 2)

        agent.register_tree('1.2.3.4.2')
        agent.register('1.2.3.4.2.1', 'integer', 1)
        agent.register('1.2.3.4.2.4', 'integer', 4)
        agent.register('1.2.3.4.2.3', 'integer', 3)
        agent.register('1.2.3.4.2.2', 'integer', 2)

        tree = agent.register_tree('1.2.3.4.3')
        tree.register('1.2.3.4.3.1.1', 'integer', 1)
        tree.add_values('string', [x for x in string.digits[2:]])

        tree = agent.register_tree('1.2.3.4.4')
        tree.add_prefix_map([
            { 'oid': '1.2.3.4.4.1', 'key': 'string', 'values': [x for x in string.letters[:10]]},
            { 'oid': '1.2.3.4.4.2', 'key': 'integer', 'values': [x for x in string.digits[:10]]},
        ])

        agent.run()
    """
    def __init__(self, oid, reload_interval=60):
        super(SNMPAgent, self).__init__()
        self.log = Logger('snmp').default_stream

        self.reload_interval = reload_interval
        self.last_reload = None
        self.args = None

        self.add_argument('-g', '--get', help='SNMP GET request')
        self.add_argument('-n', '--next', help='SNMP GET request')
        self.add_argument('-t', '--tree', action='store_true', help='Show OID tree')

        self.tree = Tree(oid)

    def __SIGHUP__(self, signum, frame):
        """
        Signal handler to reload configuration. Note this requires also the
        IOError processing in main input loop below
        """
        self.log.debug('Reloading from signal')
        self.reload()

    def parse_args(self):
        if self.args is None:
            self.args = super(SNMPAgent, self).parse_args()
        return self.args

    def register_tree(self, oid):
        return self.tree.add(Tree(oid))

    def register(self, oid, key, value):
        return self.tree.add(Item(oid, key, value))

    def GET(self, oid):
        """GET from agent

        Return given OID from agent tree or None

        """
        try:
            return self.tree.GET(oid)
        except SNMPError as e:
            self.log.debug(e)
            return None

    def NEXT(self, oid):
        """NEXT from agent

        Return given NEXT from agent tree or None

        """
        try:
            return self.tree.NEXT(oid)
        except SNMPError as e:
            self.log.debug(e)
            return None

    def SET(self, oid, value):
        """SET registered OID

        Set value for registered OID in agent tree.

        Note: By default items registered are readonly.


        """
        return self.tree.SET(oid, value)

    def clear(self):
        return self.tree.clear()
#.........这里部分代码省略.........
开发者ID:hile,项目名称:seine,代码行数:103,代码来源:agent.py

示例13: ARINReverseIP

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
    """
    entry = ARINReverseIP(address)

    url = URL_TEMPLATE % {'address': entry.address}
    headers = {'Accept': 'application/arin.whoisrws-v1+json' }
    res = requests.get(url, headers=headers)
    if res.status_code != 200:
        raise WhoisError('Error fetching URL %s' % url)

    try:
        data = json.loads(res.content)
    except ValueError, emsg:
        raise WhoisError('Error parsing response: %s' % res.content)

    if 'net' not in data:
        logger.debug('DATA: %s' % res.content)
        raise WhoisError('Did not receive expected data: missing net section')
    net = data['net']
    assert isinstance(net, dict)

    for key in ( 'handle', 'name', 'comment', 'ref', 'version', ):
        if key in net:
            setattr(entry, key, net[key])

    for key, field in DATE_FIELD_MAP.items():
        try:
            setattr(entry, key, net[field])
        except KeyError:
            continue

    blocks = net['netBlocks']['netBlock']
开发者ID:bambou42,项目名称:seine,代码行数:33,代码来源:arin.py

示例14: OperatingSystemGroup

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class OperatingSystemGroup(object):
    """
    Group of operating systems in configuration file
    """

    def __init__(self, config, name, **kwargs):
        self.log = Logger().default_stream
        self.name = name
        self.description = name
        self.connect_command = DEFAULT_CONNECT_COMMAND
        self.command_separator = DEFAULT_COMMAND_SEPARATOR
        self.update_commands = []
        self.servers = []

        for k in ( 'description', 'command_separator', ):
            if k in kwargs:
                setattr(self, k, kwargs[k])

        if 'connect' in kwargs:
            self.connect_command = kwargs['connect']

        if 'commands' in kwargs:
            self.update_commands = kwargs['commands']

        if 'servers' in kwargs:
            names = kwargs['servers']
            if not isinstance(names, list):
                names = [names]

            for name in names:
                self.servers.append(Server(self, name))

        self.modified = False

    def __repr__(self):
        return '%s: %s (%d servers)' % (self.name,self.description,len(self.servers))

    @property
    def command_separator(self):
        return self._command_separator
    @command_separator.setter
    def command_separator(self, value):
        self._command_separator = value
        self.modified = True

    @property
    def connect_command(self):
        return self._connect_command
    @connect_command.setter
    def connect_command(self, value):
        if isinstance(value, basestring):
            value = value.split()
        self._connect_command = value
        self.modified = True

    @property
    def update_command(self):
        return self._update_commands
    @update_command.setter
    def update_commands(self, value):
        if isinstance(value, basestring):
            value = [value]
        self._update_commands = value
        self.modified = True

    @property
    def descripion(self):
        return self._descripion
    @descripion.setter
    def descripion(self, value):
        self._descripion = value
        self.modified = True

    def add_server(self, name):
        if name in [s.name for s in self.servers]:
            self.log.debug('Error adding: server already in group: %s' % name)
            return

        self.servers.append(Server(self, name))
        self.modified = True

    def remove_server(self,name):
        try:
            server = [s for s in self.servers if s.name==name][0]
            self.servers.remove(server)
            self.modified = True
        except IndexError:
            self.log.debug('Error removing: server not in group: %s' % name)
            return
开发者ID:pombreda,项目名称:systematic,代码行数:91,代码来源:serverlist.py

示例15: Server

# 需要导入模块: from systematic.log import Logger [as 别名]
# 或者: from systematic.log.Logger import debug [as 别名]
class Server(object):
    """
    Configuration for one server
    """
    def __init__(self, osgroup, name, description=None):
        self.log = Logger().default_stream
        self.osgroup = osgroup
        self.name = name
        self.description = description

    def __repr__(self):
        if self.description is not None:
            return '%s (%s)' % (self.name, self.description)
        else:
            return '%s' % self.name

    def __cmp__(self, other):
        if isinstance(other, basestring):
            return cmp(self.name, other)

        return cmp(self, other)

    def __eq__(self, other):
        return self.__cmp__(other) == 0

    def __ne__(self, other):
        return self.__cmp__(other) != 0

    def __gt__(self, other):
        return self.__cmp__(other) > 0

    def __gte__(self, other):
        return self.__cmp__(other) >= 0

    def __lt__(self, other):
        return self.__cmp__(other) < 0

    def __lte__(self, other):
        return self.__cmp__(other) <= 0

    @property
    def connect_command(self):
        return [x=='SERVER' and self.name or x for x in self.osgroup.connect_command]

    def check_output(self, command):
        """
        Wrapper to execute and check output of a command without
        interactive console actions

        Splits string automatically to words so pass a list if you
        need to escape stuff properly.
        """
        if not isinstance(command, list):
            command = [command]

        cmd = self.connect_command + command
        p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        (stdout,stderr) = p.communicate()
        return p.returncode, stdout.rstrip('\n'), stderr.rstrip('\n')

    def shell(self, command):
        """
        Wrapper to run interactive shell command on the host, using
        current terminal for stdin, stdout and stderr

        Splits string automatically to words so pass a list if you
        need to escape stuff properly.

        Returns command return code
        """
        if not isinstance(command, list):
            command = [command]

        cmd = self.connect_command + command
        p = Popen(cmd, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
        p.wait()
        return p.returncode

    def update(self):
        """
        Wrapper to call correct update commands for this host
        """
        if not self.osgroup.update_commands:
            self.log.debug('No update commands for OS %s' % self.osgroup.name)
            return

        self.log.debug("Running: %s '%s'" % (
            ' '.join(self.connect_command),
            self.osgroup.command_separator.join(self.osgroup.update_commands)
        ))

        cmd = self.connect_command + [
            self.osgroup.command_separator.join(self.osgroup.update_commands)
        ]
        p = Popen(cmd, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
        p.wait()
        return p.returncode

    def remove(self):
        """Remove from configuration
#.........这里部分代码省略.........
开发者ID:pombreda,项目名称:systematic,代码行数:103,代码来源:serverlist.py


注:本文中的systematic.log.Logger.debug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。